use of com.google.gitiles.GitilesView in project gitiles by GerritCodeReview.
the class LinkTest method treeReadme.
private MarkdownToHtml treeReadme(String path) {
GitilesView v = GitilesView.path().copyFrom(view).setPathPart(path).build();
String file = CharMatcher.is('/').trimTrailingFrom(path) + "/README.md";
return readme(v, file);
}
use of com.google.gitiles.GitilesView in project gitiles by GerritCodeReview.
the class DocServlet method doGetHtml.
@Override
protected void doGetHtml(HttpServletRequest req, HttpServletResponse res) throws IOException {
MarkdownConfig cfg = MarkdownConfig.get(getAccess(req).getConfig());
if (!cfg.render) {
res.setStatus(SC_NOT_FOUND);
return;
}
GitilesView view = ViewFilter.getView(req);
Repository repo = ServletUtils.getRepository(req);
try (RevWalk rw = new RevWalk(repo)) {
ObjectReader reader = rw.getObjectReader();
String path = view.getPathPart();
RevTree root;
try {
root = rw.parseTree(view.getRevision().getId());
} catch (IncorrectObjectTypeException e) {
res.setStatus(SC_NOT_FOUND);
return;
}
MarkdownFile srcmd = findFile(rw, root, path);
if (srcmd == null) {
res.setStatus(SC_NOT_FOUND);
return;
}
MarkdownFile navmd = findFile(rw, root, NAVBAR_MD);
String curEtag = etag(srcmd, navmd);
if (etagMatch(req, curEtag)) {
res.setStatus(SC_NOT_MODIFIED);
return;
}
view = view.toBuilder().setPathPart(srcmd.path).build();
try {
srcmd.read(reader, cfg);
if (navmd != null) {
navmd.read(reader, cfg);
}
} catch (LargeObjectException.ExceedsLimit errBig) {
fileTooBig(res, view, errBig);
return;
} catch (IOException err) {
readError(res, view, err);
return;
}
MarkdownToHtml.Builder fmt = MarkdownToHtml.builder().setConfig(cfg).setGitilesView(view).setRequestUri(req.getRequestURI()).setReader(reader).setRootTree(root);
res.setHeader(HttpHeaders.ETAG, curEtag);
showDoc(req, res, view, cfg, fmt, navmd, srcmd);
}
}
use of com.google.gitiles.GitilesView in project gitiles by GerritCodeReview.
the class BlameServlet method doGetHtml.
@Override
protected void doGetHtml(HttpServletRequest req, HttpServletResponse res) throws IOException {
GitilesView view = ViewFilter.getView(req);
Repository repo = ServletUtils.getRepository(req);
try (RevWalk rw = new RevWalk(repo)) {
GitilesAccess access = getAccess(req);
RegionResult result = getRegions(view, access, repo, rw, res);
if (result == null) {
return;
}
String title = "Blame - " + view.getPathPart();
Map<String, ?> blobData = new BlobSoyData(rw.getObjectReader(), view).toSoyData(view.getPathPart(), result.blobId);
if (blobData.get("lines") != null) {
DateFormatter df = new DateFormatter(access, Format.ISO);
renderHtml(req, res, "gitiles.blameDetail", ImmutableMap.of("title", title, "breadcrumbs", view.getBreadcrumbs(), "data", blobData, "regions", toSoyData(view, rw.getObjectReader(), result.regions, df)));
} else {
renderHtml(req, res, "gitiles.blameDetail", ImmutableMap.of("title", title, "breadcrumbs", view.getBreadcrumbs(), "data", blobData));
}
}
}
use of com.google.gitiles.GitilesView in project gitiles by GerritCodeReview.
the class BlameServlet method doGetJson.
@Override
protected void doGetJson(HttpServletRequest req, HttpServletResponse res) throws IOException {
GitilesView view = ViewFilter.getView(req);
Repository repo = ServletUtils.getRepository(req);
try (RevWalk rw = new RevWalk(repo)) {
RegionResult result = getRegions(view, getAccess(req), repo, rw, res);
if (result == null) {
return;
}
// Output from BlameCache is 0-based for lines. We convert to 1-based for
// JSON output later (in RegionAdapter); here we're just filling in the
// transient fields.
int start = 0;
for (Region r : result.regions) {
r.setStart(start);
start += r.getCount();
}
renderJson(req, res, ImmutableMap.of("regions", result.regions), new TypeToken<Map<String, List<Region>>>() {
}.getType());
}
}
Aggregations