use of org.eclipse.jgit.revwalk.RevTree in project che by eclipse.
the class JGitDiffPage method commitToWorkingTree.
/**
* Show changes between specified revision and working tree.
*
* @param commitId
* id of commit
* @param formatter
* diff formatter
* @return list of diff entries
* @throws IOException
* if any i/o errors occurs
*/
private List<DiffEntry> commitToWorkingTree(String commitId, DiffFormatter formatter) throws IOException {
ObjectId commitA = repository.resolve(commitId);
if (commitA == null) {
File heads = new File(repository.getWorkTree().getPath() + "/.git/refs/heads");
if (heads.exists() && heads.list().length == 0) {
return Collections.emptyList();
}
throw new IllegalArgumentException("Invalid commit id " + commitId);
}
RevTree treeA;
try (RevWalk revWalkA = new RevWalk(repository)) {
treeA = revWalkA.parseTree(commitA);
}
List<DiffEntry> diff;
try (ObjectReader reader = repository.newObjectReader()) {
CanonicalTreeParser iterA = new CanonicalTreeParser();
iterA.reset(reader, treeA);
FileTreeIterator iterB = new FileTreeIterator(repository);
// Seems bug in DiffFormatter when work with working. Disable detect
// renames by formatter and do it later.
formatter.setDetectRenames(false);
diff = formatter.scan(iterA, iterB);
if (!params.isNoRenames()) {
// Detect renames.
RenameDetector renameDetector = createRenameDetector();
ContentSource.Pair sourcePairReader = new ContentSource.Pair(ContentSource.create(reader), ContentSource.create(iterB));
renameDetector.addAll(diff);
diff = renameDetector.compute(sourcePairReader, NullProgressMonitor.INSTANCE);
}
}
return diff;
}
use of org.eclipse.jgit.revwalk.RevTree in project che by eclipse.
the class JGitDiffPage method commitToCommit.
/**
* Show changes between specified two revisions and index. If
* <code>commitAId == null</code> then view changes between HEAD and revision commitBId.
*
* @param commitAId
* id of commit A, pass <code>null</code> is the same as pass HEAD
* @param commitBId
* id of commit B
* @param formatter
* diff formatter
* @return list of diff entries
* @throws IOException
* if any i/o errors occurs
*/
private List<DiffEntry> commitToCommit(String commitAId, String commitBId, DiffFormatter formatter) throws IOException {
if (commitAId == null) {
commitAId = Constants.HEAD;
}
ObjectId commitA = repository.resolve(commitAId);
if (commitA == null) {
throw new IllegalArgumentException("Invalid commit id " + commitAId);
}
ObjectId commitB = repository.resolve(commitBId);
if (commitB == null) {
throw new IllegalArgumentException("Invalid commit id " + commitBId);
}
RevTree treeA;
try (RevWalk revWalkA = new RevWalk(repository)) {
treeA = revWalkA.parseTree(commitA);
}
RevTree treeB;
try (RevWalk revWalkB = new RevWalk(repository)) {
treeB = revWalkB.parseTree(commitB);
}
if (!params.isNoRenames()) {
// Use embedded RenameDetector it works well with index and revision
// history.
formatter.setDetectRenames(true);
int renameLimit = params.getRenameLimit();
if (renameLimit > 0) {
formatter.getRenameDetector().setRenameLimit(renameLimit);
}
}
return formatter.scan(treeA, treeB);
}
use of org.eclipse.jgit.revwalk.RevTree in project che by eclipse.
the class JGitDiffPage method emptyToCommit.
/**
* Show changes between specified revision and empty tree.
*
* @param commitId
* id of commit
* @param formatter
* diff formatter
* @return list of diff entries
* @throws IOException
* if any i/o errors occurs
*/
private List<DiffEntry> emptyToCommit(String commitId, DiffFormatter formatter) throws IOException {
ObjectId commit = repository.resolve(commitId);
checkArgument(commit != null, "Invalid commit id " + commitId);
RevTree tree;
try (RevWalk revWalkA = new RevWalk(repository)) {
tree = revWalkA.parseTree(commit);
}
List<DiffEntry> diff;
try (ObjectReader reader = repository.newObjectReader()) {
CanonicalTreeParser iterator = new CanonicalTreeParser();
iterator.reset(reader, tree);
diff = formatter.scan(new EmptyTreeIterator(), iterator);
}
return diff;
}
use of org.eclipse.jgit.revwalk.RevTree in project gerrit by GerritCodeReview.
the class AbstractSubmoduleSubscription method expectToHaveSubmoduleState.
protected void expectToHaveSubmoduleState(TestRepository<?> repo, String branch, String submodule, ObjectId expectedId) throws Exception {
submodule = name(submodule);
ObjectId commitId = repo.git().fetch().setRemote("origin").call().getAdvertisedRef("refs/heads/" + branch).getObjectId();
RevWalk rw = repo.getRevWalk();
RevCommit c = rw.parseCommit(commitId);
rw.parseBody(c.getTree());
RevTree tree = c.getTree();
RevObject actualId = repo.get(tree, submodule);
assertThat(actualId).isEqualTo(expectedId);
}
use of org.eclipse.jgit.revwalk.RevTree in project gerrit by GerritCodeReview.
the class AbstractSubmoduleSubscription method expectToHaveSubmoduleState.
protected void expectToHaveSubmoduleState(TestRepository<?> repo, String branch, String submodule, TestRepository<?> subRepo, String subBranch) throws Exception {
submodule = name(submodule);
ObjectId commitId = repo.git().fetch().setRemote("origin").call().getAdvertisedRef("refs/heads/" + branch).getObjectId();
ObjectId subHead = subRepo.git().fetch().setRemote("origin").call().getAdvertisedRef("refs/heads/" + subBranch).getObjectId();
RevWalk rw = repo.getRevWalk();
RevCommit c = rw.parseCommit(commitId);
rw.parseBody(c.getTree());
RevTree tree = c.getTree();
RevObject actualId = repo.get(tree, submodule);
assertThat(actualId).isEqualTo(subHead);
}
Aggregations