use of org.eclipse.jgit.revwalk.RevTree in project gitblit by gitblit.
the class DiffUtils method getDiffStat.
/**
* Returns the diffstat between the two commits for the specified file or folder.
*
* @param repository
* @param baseCommit
* if base commit is unspecified, the diffstat is generated against
* the primary parent of the specified commit.
* @param commit
* @param path
* if path is specified, the diffstat is generated only for the
* specified file or folder. if unspecified, the diffstat is
* generated for the entire diff between the two commits.
* @return patch as a string
*/
public static DiffStat getDiffStat(Repository repository, RevCommit baseCommit, RevCommit commit, String path) {
DiffStat stat = null;
try {
RawTextComparator cmp = RawTextComparator.DEFAULT;
DiffStatFormatter df = new DiffStatFormatter(commit.getName(), repository);
df.setRepository(repository);
df.setDiffComparator(cmp);
df.setDetectRenames(true);
RevTree commitTree = commit.getTree();
RevTree baseTree;
if (baseCommit == null) {
if (commit.getParentCount() > 0) {
final RevWalk rw = new RevWalk(repository);
RevCommit parent = rw.parseCommit(commit.getParent(0).getId());
baseTree = parent.getTree();
} else {
// FIXME initial commit. no parent?!
baseTree = commitTree;
}
} else {
baseTree = baseCommit.getTree();
}
List<DiffEntry> diffEntries = df.scan(baseTree, commitTree);
if (path != null && path.length() > 0) {
for (DiffEntry diffEntry : diffEntries) {
if (diffEntry.getNewPath().equalsIgnoreCase(path)) {
df.format(diffEntry);
break;
}
}
} else {
df.format(diffEntries);
}
stat = df.getDiffStat();
df.flush();
} catch (Throwable t) {
LOGGER.error("failed to generate commit diff!", t);
}
return stat;
}
use of org.eclipse.jgit.revwalk.RevTree in project omegat by omegat-org.
the class GITRemoteRepository2 method prepareTreeParser.
private static AbstractTreeIterator prepareTreeParser(Repository repository, ObjectId objId) throws Exception {
// the TreeParser
try (RevWalk walk = new RevWalk(repository)) {
RevCommit commit = walk.parseCommit(objId);
RevTree tree = walk.parseTree(commit.getTree().getId());
CanonicalTreeParser treeParser = new CanonicalTreeParser();
ObjectReader reader = repository.newObjectReader();
treeParser.reset(reader, tree.getId());
return treeParser;
}
}
use of org.eclipse.jgit.revwalk.RevTree in project jwt by emweb.
the class Git method treeSize.
public int treeSize(ObjectId treeId) {
if (treeId.id == null)
return 0;
try {
RevWalk walk = new RevWalk(repository, 0);
RevTree tree = walk.parseTree(treeId.id);
TreeWalk treeWalk = new TreeWalk(repository);
treeWalk.addTree(tree);
treeWalk.setRecursive(false);
int count = 0;
while (treeWalk.next()) ++count;
return count;
} catch (MissingObjectException e) {
throw new RuntimeException(e);
} catch (IncorrectObjectTypeException e) {
throw new RuntimeException(e);
} catch (CorruptObjectException e) {
throw new RuntimeException(e);
} catch (IOException e) {
throw new RuntimeException(e);
}
}
use of org.eclipse.jgit.revwalk.RevTree in project curiostack by curioswitch.
the class CurioGenericCiPlugin method parserForBranch.
private static CanonicalTreeParser parserForBranch(Git git, Ref branch) throws IOException {
try (RevWalk walk = new RevWalk(git.getRepository())) {
RevCommit commit = walk.parseCommit(branch.getObjectId());
RevTree tree = walk.parseTree(commit.getTree().getId());
final CanonicalTreeParser parser;
try (ObjectReader reader = git.getRepository().newObjectReader()) {
parser = parser(reader, tree.getId());
}
walk.dispose();
return parser;
}
}
Aggregations