本文整理汇总了Java中org.eclipse.jgit.revwalk.RevCommit.getTree方法的典型用法代码示例。如果您正苦于以下问题:Java RevCommit.getTree方法的具体用法?Java RevCommit.getTree怎么用?Java RevCommit.getTree使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.eclipse.jgit.revwalk.RevCommit
的用法示例。
在下文中一共展示了RevCommit.getTree方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkJGitFix
import org.eclipse.jgit.revwalk.RevCommit; //导入方法依赖的package包/类
private void checkJGitFix (String branch, File file) throws Exception {
ObjectId headTree = null;
try {
headTree = Utils.findCommit(repository, Constants.HEAD).getTree();
} catch (GitException.MissingObjectException ex) { }
DirCache cache = repository.lockDirCache();
RevCommit commit;
commit = Utils.findCommit(repository, branch);
DirCacheCheckout dco = new DirCacheCheckout(repository, headTree, cache, commit.getTree());
dco.setFailOnConflict(false);
dco.checkout();
if (file.exists()) {
// and do not forget to remove WA in checkout command when JGit is fixed.
fail("Hey, JGit is fixed, why don't you fix me as well?");
}
cache.unlock();
}
示例2: getLoaderFrom
import org.eclipse.jgit.revwalk.RevCommit; //导入方法依赖的package包/类
/**
* Gets the loader for a file from a specified commit and its path
*
* @param commit
* - the commit from which to get the loader
* @param path
* - the path to the file
* @return the loader
* @throws MissingObjectException
* @throws IncorrectObjectTypeException
* @throws CorruptObjectException
* @throws IOException
*/
public ObjectLoader getLoaderFrom(ObjectId commit, String path)
throws IOException {
Repository repository = git.getRepository();
RevWalk revWalk = new RevWalk(repository);
RevCommit revCommit = revWalk.parseCommit(commit);
// and using commit's tree find the path
RevTree tree = revCommit.getTree();
TreeWalk treeWalk = new TreeWalk(repository);
treeWalk.addTree(tree);
treeWalk.setRecursive(true);
treeWalk.setFilter(PathFilter.create(path));
ObjectLoader loader = null;
if (treeWalk.next()) {
ObjectId objectId = treeWalk.getObjectId(0);
loader = repository.open(objectId);
}
treeWalk.close();
revWalk.close();
return loader;
}
示例3: getTree
import org.eclipse.jgit.revwalk.RevCommit; //导入方法依赖的package包/类
private static RevTree getTree(Repository repository) throws IOException {
ObjectId lastCommitId = repository.resolve(Constants.HEAD);
// a RevWalk allows to walk over commits based on some filtering
try (RevWalk revWalk = new RevWalk(repository)) {
RevCommit commit = revWalk.parseCommit(lastCommitId);
System.out.println("Time of commit (seconds since epoch): " + commit.getCommitTime());
// and using commit's tree find the path
RevTree tree = commit.getTree();
System.out.println("Having tree: " + tree);
return tree;
}
}
示例4: getRevTree
import org.eclipse.jgit.revwalk.RevCommit; //导入方法依赖的package包/类
private RevTree getRevTree() throws IOException {
Ref ref = repository.exactRef(branch.getFullRef());
RevCommit commit = new RevWalk(repository).parseCommit(ref.getObjectId());
return commit.getTree();
}
示例5: getCommit
import org.eclipse.jgit.revwalk.RevCommit; //导入方法依赖的package包/类
/**
* Returns the SHA-1 commit id for a file by specifying what commit to get for
* that file and it's path
*
* @param commit
* - specifies the commit to return(MINE, THEIRS, BASE, LOCAL)
* @param path
* - the file path for the specified commit
* @return the SHA-1 commit id
*/
public ObjectId getCommit(Commit commit, String path) {
List<DiffEntry> entries;
boolean baseIsNull = false;
int index = 0;
try {
entries = git.diff().setPathFilter(PathFilter.create(path)).call();
if (entries.size() == 2) {
baseIsNull = true;
}
if (commit == Commit.MINE) {
if (baseIsNull) {
index = 0;
} else {
index = 1;
}
return entries.get(index).getOldId().toObjectId();
} else if (commit == Commit.THEIRS) {
if (baseIsNull) {
index = 1;
} else {
index = 2;
}
return entries.get(index).getOldId().toObjectId();
} else if (commit == Commit.BASE) {
return entries.get(index).getOldId().toObjectId();
} else if (commit == Commit.LOCAL) {
ObjectId lastLocalCommit = getLastLocalCommit();
RevWalk revWalk = new RevWalk(git.getRepository());
RevCommit revCommit = revWalk.parseCommit(lastLocalCommit);
RevTree tree = revCommit.getTree();
TreeWalk treeWalk = new TreeWalk(git.getRepository());
treeWalk.addTree(tree);
treeWalk.setRecursive(true);
treeWalk.setFilter(PathFilter.create(path));
ObjectId objectId = null;
if (treeWalk.next()) {
objectId = treeWalk.getObjectId(0);
}
treeWalk.close();
revWalk.close();
return objectId;
}
} catch (GitAPIException |IOException e) {
if (logger.isDebugEnabled()) {
logger.debug(e, e);
}
}
return null;
}