use of com.google.gitiles.CommitData.Field in project gitiles by GerritCodeReview.
the class LogServlet method doGetJson.
@Override
protected void doGetJson(HttpServletRequest req, HttpServletResponse res) throws IOException {
Repository repo = ServletUtils.getRepository(req);
GitilesView view = getView(req, repo);
Set<Field> fs = Sets.newEnumSet(CommitJsonData.DEFAULT_FIELDS, Field.class);
String nameStatus = Iterables.getFirst(view.getParameters().get(NAME_STATUS_PARAM), null);
if ("1".equals(nameStatus) || "".equals(nameStatus)) {
fs.add(Field.DIFF_TREE);
}
Paginator paginator = null;
try {
GitilesAccess access = getAccess(req);
paginator = newPaginator(repo, view, access);
if (paginator == null) {
res.setStatus(SC_NOT_FOUND);
return;
}
DateFormatter df = new DateFormatter(access, Format.DEFAULT);
CommitJsonData.Log result = new CommitJsonData.Log();
List<CommitJsonData.Commit> entries = Lists.newArrayListWithCapacity(paginator.getLimit());
for (RevCommit c : paginator) {
paginator.getWalk().parseBody(c);
entries.add(new CommitJsonData().setRevWalk(paginator.getWalk()).toJsonData(req, c, fs, df));
}
result.log = entries;
if (paginator.getPreviousStart() != null) {
result.previous = paginator.getPreviousStart().name();
}
if (paginator.getNextStart() != null) {
result.next = paginator.getNextStart().name();
}
renderJson(req, res, result, new TypeToken<CommitJsonData.Log>() {
}.getType());
} finally {
if (paginator != null) {
paginator.getWalk().close();
}
}
}
use of com.google.gitiles.CommitData.Field 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