use of org.eclipse.jgit.diff.RawText in project gitiles by GerritCodeReview.
the class DiffServletTest method diffFileOneParentText.
@Test
public void diffFileOneParentText() throws Exception {
String contents1 = "foo\n";
String contents2 = "foo\ncontents\n";
RevCommit c1 = repo.update("master", repo.commit().add("foo", contents1));
RevCommit c2 = repo.update("master", repo.commit().parent(c1).add("foo", contents2));
FakeHttpServletResponse res = buildText("/repo/+diff/" + c2.name() + "^!/foo");
Patch p = parsePatch(res.getActualBody());
FileHeader f = getOnlyElement(p.getFiles());
assertThat(f.getChangeType()).isEqualTo(ChangeType.MODIFY);
assertThat(f.getPath(Side.OLD)).isEqualTo("foo");
assertThat(f.getPath(Side.NEW)).isEqualTo("foo");
RawText rt2 = new RawText(contents2.getBytes(UTF_8));
Edit e = getOnlyElement(getOnlyElement(f.getHunks()).toEditList());
assertThat(e.getType()).isEqualTo(Type.INSERT);
assertThat(rt2.getString(e.getBeginB(), e.getEndB(), false)).isEqualTo("contents\n");
}
use of org.eclipse.jgit.diff.RawText in project gitiles by GerritCodeReview.
the class DiffServletTest method diffFileNoParentsText.
@Test
public void diffFileNoParentsText() throws Exception {
String contents = "foo\ncontents\n";
RevCommit c = repo.update("master", repo.commit().add("foo", contents));
FakeHttpServletResponse res = buildText("/repo/+diff/" + c.name() + "^!/foo");
Patch p = parsePatch(res.getActualBody());
FileHeader f = getOnlyElement(p.getFiles());
assertThat(f.getChangeType()).isEqualTo(ChangeType.ADD);
assertThat(f.getPath(Side.OLD)).isEqualTo(DiffEntry.DEV_NULL);
assertThat(f.getPath(Side.NEW)).isEqualTo("foo");
RawText rt = new RawText(contents.getBytes(UTF_8));
Edit e = getOnlyElement(getOnlyElement(f.getHunks()).toEditList());
assertThat(e.getType()).isEqualTo(Type.INSERT);
assertThat(rt.getString(e.getBeginB(), e.getEndB(), false)).isEqualTo(contents);
}
use of org.eclipse.jgit.diff.RawText in project gitblit by gitblit.
the class DiffUtils method blame.
/**
* Returns the list of lines in the specified source file annotated with the
* source commit metadata.
*
* @param repository
* @param blobPath
* @param objectId
* @return list of annotated lines
*/
public static List<AnnotatedLine> blame(Repository repository, String blobPath, String objectId) {
List<AnnotatedLine> lines = new ArrayList<AnnotatedLine>();
try {
ObjectId object;
if (StringUtils.isEmpty(objectId)) {
object = JGitUtils.getDefaultBranch(repository);
} else {
object = repository.resolve(objectId);
}
BlameCommand blameCommand = new BlameCommand(repository);
blameCommand.setFilePath(blobPath);
blameCommand.setStartCommit(object);
BlameResult blameResult = blameCommand.call();
RawText rawText = blameResult.getResultContents();
int length = rawText.size();
for (int i = 0; i < length; i++) {
RevCommit commit = blameResult.getSourceCommit(i);
AnnotatedLine line = new AnnotatedLine(commit, i + 1, rawText.getString(i));
lines.add(line);
}
} catch (Throwable t) {
LOGGER.error(MessageFormat.format("failed to generate blame for {0} {1}!", blobPath, objectId), t);
}
return lines;
}
use of org.eclipse.jgit.diff.RawText in project gerrit by GerritCodeReview.
the class PatchListLoader method createPatchListEntry.
private static PatchListEntry createPatchListEntry(RawTextComparator cmp, RevCommit aCommit, Text aText, Text bText, String fileName) {
byte[] rawHdr = getRawHeader(aCommit != null, fileName);
byte[] aContent = aText.getContent();
byte[] bContent = bText.getContent();
long size = bContent.length;
long sizeDelta = bContent.length - aContent.length;
RawText aRawText = new RawText(aContent);
RawText bRawText = new RawText(bContent);
EditList edits = new HistogramDiff().diff(cmp, aRawText, bRawText);
FileHeader fh = new FileHeader(rawHdr, edits, PatchType.UNIFIED);
return new PatchListEntry(fh, edits, size, sizeDelta);
}
Aggregations