use of org.eclipse.jgit.lib.AbbreviatedObjectId in project egit by eclipse.
the class GitCommitsModelCache method getChangedObjects.
private static Map<String, Change> getChangedObjects(Repository repo, RevCommit commit, RevCommit parentCommit, TreeFilter pathFilter, final int direction) throws IOException {
final Map<String, Change> result = new HashMap<String, GitCommitsModelCache.Change>();
try (final TreeWalk tw = new TreeWalk(repo)) {
int commitIndex = addTree(tw, commit);
int parentCommitIndex = addTree(tw, parentCommit);
tw.setRecursive(true);
if (pathFilter == null)
tw.setFilter(ANY_DIFF);
else
tw.setFilter(AndTreeFilter.create(ANY_DIFF, pathFilter));
final AbbreviatedObjectId commitId = getAbbreviatedObjectId(commit);
final AbbreviatedObjectId parentCommitId = getAbbreviatedObjectId(parentCommit);
MutableObjectId idBuf = new MutableObjectId();
while (tw.next()) {
Change change = new Change();
change.commitId = commitId;
change.remoteCommitId = parentCommitId;
change.name = tw.getNameString();
tw.getObjectId(idBuf, commitIndex);
change.objectId = AbbreviatedObjectId.fromObjectId(idBuf);
tw.getObjectId(idBuf, parentCommitIndex);
change.remoteObjectId = AbbreviatedObjectId.fromObjectId(idBuf);
calculateAndSetChangeKind(direction, change);
result.put(tw.getPathString(), change);
}
}
return result.size() > 0 ? result : null;
}
use of org.eclipse.jgit.lib.AbbreviatedObjectId in project fuse-karaf by jboss-fuse.
the class DiffUtils method diff.
private static void diff(Git git, ObjectReader reader, DiffEntry diff, Writer result) throws IOException {
ByteArrayOutputStream baos = new ByteArrayOutputStream();
DiffFormatter df = new DiffFormatter(baos);
df.setDiffAlgorithm(DiffAlgorithm.getAlgorithm(DiffAlgorithm.SupportedAlgorithm.HISTOGRAM));
df.setDiffComparator(RawTextComparator.DEFAULT);
df.setRepository(git.getRepository());
df.format(diff);
// System.out.println(new String(baos.toByteArray()));
AbbreviatedObjectId id1 = diff.getOldId();
AbbreviatedObjectId id2 = diff.getNewId();
byte[] bytes1 = reader.open(id1.toObjectId()).getBytes();
byte[] bytes2 = reader.open(id2.toObjectId()).getBytes();
RawText rt1 = new RawText(bytes1);
RawText rt2 = new RawText(bytes2);
EditList edits = DiffAlgorithm.getAlgorithm(DiffAlgorithm.SupportedAlgorithm.HISTOGRAM).diff(RawTextComparator.DEFAULT, rt1, rt2);
int aCur = 0;
for (Edit curEdit : edits) {
boolean prolog = aCur < curEdit.getBeginA();
if (prolog) {
result.write("<div class=\"edit unchanged\">");
}
while (aCur < curEdit.getBeginA()) {
result.write(html(rt1.getString(aCur++)) + "\n");
}
if (prolog) {
result.write("</div>");
}
if (curEdit.getType() == Edit.Type.INSERT) {
result.write("<div class=\"edit added\">");
for (int i = curEdit.getBeginB(); i < curEdit.getEndB(); i++) {
result.write(html(rt2.getString(i)) + "\n");
}
result.write("</div>");
}
if (curEdit.getType() == Edit.Type.REPLACE) {
result.write("<div class=\"edit changed\"><div class=\"edit removed\">");
for (int i = curEdit.getBeginA(); i < curEdit.getEndA(); i++) {
result.write(html(rt1.getString(i)) + "\n");
}
result.write("</div><div class=\"edit added\">");
for (int i = curEdit.getBeginB(); i < curEdit.getEndB(); i++) {
result.write(html(rt2.getString(i)) + "\n");
}
aCur = curEdit.getEndA();
result.write("</div></div>");
}
if (curEdit.getType() == Edit.Type.DELETE) {
result.write("<div class=\"edit changed\"><div class=\"edit removed\">");
for (int i = curEdit.getBeginA(); i < curEdit.getEndA(); i++) {
result.write(html(rt1.getString(i)) + "\n");
}
aCur = curEdit.getEndA();
result.write("</div></div>");
}
}
boolean prolog = aCur < rt1.size();
if (prolog) {
result.write("<div class=\"edit unchanged\">");
}
while (aCur < rt1.size()) {
result.write(html(rt1.getString(aCur++)) + "\n");
}
if (prolog) {
result.write("</div>");
}
}
Aggregations