Java 有JGit管道API吗?
我需要使用git管道命令(如中使用的命令),如Java 有JGit管道API吗?,java,git,jgit,Java,Git,Jgit,我需要使用git管道命令(如中使用的命令),如git hash object、git write tree、git commit tree以及所有其他命令。在JGit中是否有一个很好的API来完成这些工作(我似乎找不到),或者您如何做一些基本的事情,比如从输出流或文件写入blob/您使用什么来代替git命令?如果有,应该在中 例如,DirCache对象(即Git索引)具有: 欢迎来到这里。除了包org.eclipse.jgit.API中的高级Cellar API之外,低级API与本机git的管道
git hash object
、git write tree
、git commit tree
以及所有其他命令。在JGit中是否有一个很好的API来完成这些工作(我似乎找不到),或者您如何做一些基本的事情,比如从输出流或文件写入blob/您使用什么来代替git命令?如果有,应该在中
例如,DirCache
对象(即Git索引)具有:
欢迎来到这里。除了包org.eclipse.jgit.API
中的高级Cellar API之外,低级API与本机git的管道命令没有紧密关联。这是因为JGit是一个Java库,而不是命令行界面
如果需要示例,请首先查看>2000 JGit测试用例。接下来,我们来看看EGit是如何使用JGit的。如果这没有帮助,请回来问更具体的问题。git hash object
预期产量:323FAE03F460EA9991DF8BEFB2FCA795E648FA正如在中所讨论的,我正在寻找和你一样的东西。 我使用git作为k-v数据库来描述我们的数据结构。 所以我想将git风格的管道API或Jgit风格的管道API包装为CRUDAPI。 然后我找到了org.eclipse.jgit.lib.ObjectInserter 我认为大多数C语言对CRUD的要求可以通过包装ObjectInserter来实现
/**
* Write all index trees to the object store, returning the root tree.
*
* @param ow
* the writer to use when serializing to the store. The caller is
* responsible for flushing the inserter before trying to use the
* returned tree identity.
* @return identity for the root tree.
* @throws UnmergedPathException
* one or more paths contain higher-order stages (stage > 0),
* which cannot be stored in a tree object.
* @throws IllegalStateException
* one or more paths contain an invalid mode which should never
* appear in a tree object.
* @throws IOException
* an unexpected error occurred writing to the object store.
*/
public ObjectId writeTree(final ObjectInserter ow)
import java.io.*;
import org.eclipse.jgit.lib.ObjectId;
import org.eclipse.jgit.lib.ObjectInserter;
import org.eclipse.jgit.lib.ObjectInserter.Formatter;
import static org.eclipse.jgit.lib.Constants.OBJ_BLOB;
public class GitHashObject {
public static void main(String[] args) throws IOException {
File file = File.createTempFile("foobar", ".txt");
FileOutputStream out = new FileOutputStream(file);
out.write("foobar\n".getBytes());
out.close();
System.out.println(gitHashObject(file));
}
public static String gitHashObject(File file) throws IOException {
FileInputStream in = new FileInputStream(file);
Formatter formatter = new ObjectInserter.Formatter();
ObjectId objectId = formatter.idFor(OBJ_BLOB, file.length(), in);
in.close();
return objectId.getName(); // or objectId.name()
}
}