本文整理匯總了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;
}