use of org.eclipse.jgit.treewalk.AbstractTreeIterator in project gitiles by GerritCodeReview.
the class DiffServlet method doGetText.
@Override
protected void doGetText(HttpServletRequest req, HttpServletResponse res) throws IOException {
GitilesView view = ViewFilter.getView(req);
Repository repo = ServletUtils.getRepository(req);
try (RevWalk walk = new RevWalk(repo)) {
AbstractTreeIterator oldTree;
AbstractTreeIterator newTree;
try {
oldTree = getTreeIterator(walk, view.getOldRevision().getId());
newTree = getTreeIterator(walk, view.getRevision().getId());
} catch (MissingObjectException | IncorrectObjectTypeException e) {
res.setStatus(SC_NOT_FOUND);
return;
}
try (Writer writer = startRenderText(req, res);
OutputStream out = BaseEncoding.base64().encodingStream(writer);
DiffFormatter diff = new DiffFormatter(out)) {
formatDiff(repo, oldTree, newTree, view.getPathPart(), diff);
}
}
}
use of org.eclipse.jgit.treewalk.AbstractTreeIterator in project compiler by boalang.
the class GitCommit method getChangeFiles.
private void getChangeFiles(final RevCommit parent, final RevCommit rc, final HashMap<String, String> rChangedPaths, final HashMap<String, String> rRemovedPaths, final HashMap<String, String> rAddedPaths) {
final DiffFormatter df = new DiffFormatter(NullOutputStream.INSTANCE);
df.setRepository(repository);
df.setDiffComparator(RawTextComparator.DEFAULT);
df.setDetectRenames(true);
try {
final AbstractTreeIterator parentIter;
if (parent == null)
parentIter = new EmptyTreeIterator();
else
parentIter = new CanonicalTreeParser(null, repository.newObjectReader(), parent.getTree());
for (final DiffEntry diff : df.scan(parentIter, new CanonicalTreeParser(null, repository.newObjectReader(), rc.getTree()))) {
if (diff.getChangeType() == ChangeType.MODIFY || diff.getChangeType() == ChangeType.COPY || diff.getChangeType() == ChangeType.RENAME) {
if (diff.getOldMode().getObjectType() == Constants.OBJ_BLOB && diff.getNewMode().getObjectType() == Constants.OBJ_BLOB) {
String path = diff.getNewPath();
rChangedPaths.put(path, diff.getOldPath());
filePathGitObjectIds.put(path, diff.getNewId().toObjectId());
}
} else if (diff.getChangeType() == ChangeType.ADD) {
if (diff.getNewMode().getObjectType() == Constants.OBJ_BLOB) {
String path = diff.getNewPath();
rAddedPaths.put(path, null);
filePathGitObjectIds.put(path, diff.getNewId().toObjectId());
}
} else if (diff.getChangeType() == ChangeType.DELETE) {
if (diff.getOldMode().getObjectType() == Constants.OBJ_BLOB) {
rRemovedPaths.put(diff.getOldPath(), diff.getOldPath());
}
}
}
} catch (final IOException e) {
if (debug)
System.err.println("Git Error getting commit diffs: " + e.getMessage());
}
df.close();
}
use of org.eclipse.jgit.treewalk.AbstractTreeIterator in project gitiles by GerritCodeReview.
the class DiffServlet method doGetHtml.
@Override
protected void doGetHtml(HttpServletRequest req, HttpServletResponse res) throws IOException {
GitilesView view = ViewFilter.getView(req);
Repository repo = ServletUtils.getRepository(req);
try (RevWalk walk = new RevWalk(repo);
TreeWalk tw = newTreeWalk(walk, view)) {
boolean showCommit;
boolean isFile;
AbstractTreeIterator oldTree;
AbstractTreeIterator newTree;
try {
if (tw == null && !view.getPathPart().isEmpty()) {
res.setStatus(SC_NOT_FOUND);
return;
}
isFile = tw != null && isFile(tw);
// If we are viewing the diff between a commit and one of its parents,
// include the commit detail in the rendered page.
showCommit = isParentOf(walk, view.getOldRevision(), view.getRevision());
oldTree = getTreeIterator(walk, view.getOldRevision().getId());
newTree = getTreeIterator(walk, view.getRevision().getId());
} catch (MissingObjectException | IncorrectObjectTypeException e) {
res.setStatus(SC_NOT_FOUND);
return;
}
Map<String, Object> data = getData(req);
data.put("title", "Diff - " + view.getRevisionRange());
if (showCommit) {
Set<Field> fs = CommitSoyData.DEFAULT_FIELDS;
if (isFile) {
fs = Field.setOf(fs, Field.PARENT_BLAME_URL);
}
GitilesAccess access = getAccess(req);
DateFormatter df = new DateFormatter(access, Format.DEFAULT);
data.put("commit", new CommitSoyData().setLinkifier(linkifier).setArchiveFormat(getArchiveFormat(access)).toSoyData(req, walk.parseCommit(view.getRevision().getId()), fs, df));
}
if (!data.containsKey("repositoryName") && (view.getRepositoryName() != null)) {
data.put("repositoryName", view.getRepositoryName());
}
if (!data.containsKey("breadcrumbs")) {
data.put("breadcrumbs", view.getBreadcrumbs());
}
setCacheHeaders(req, res);
try (OutputStream out = startRenderStreamingHtml(req, res, "gitiles.diffDetail", data);
DiffFormatter diff = new HtmlDiffFormatter(renderer, view, out)) {
formatDiff(repo, oldTree, newTree, view.getPathPart(), diff);
}
}
}
Aggregations