Search in sources :

Example 1 with GitilesView

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);
}
Also used : GitilesView(com.google.gitiles.GitilesView)

Example 2 with GitilesView

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);
    }
}
Also used : GitilesView(com.google.gitiles.GitilesView) IncorrectObjectTypeException(org.eclipse.jgit.errors.IncorrectObjectTypeException) IOException(java.io.IOException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) LargeObjectException(org.eclipse.jgit.errors.LargeObjectException) Repository(org.eclipse.jgit.lib.Repository) ObjectReader(org.eclipse.jgit.lib.ObjectReader) RevTree(org.eclipse.jgit.revwalk.RevTree)

Example 3 with GitilesView

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));
        }
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) BlobSoyData(com.google.gitiles.BlobSoyData) GitilesAccess(com.google.gitiles.GitilesAccess) DateFormatter(com.google.gitiles.DateFormatter) GitilesView(com.google.gitiles.GitilesView) RevWalk(org.eclipse.jgit.revwalk.RevWalk)

Example 4 with GitilesView

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());
    }
}
Also used : Repository(org.eclipse.jgit.lib.Repository) TypeToken(com.google.gson.reflect.TypeToken) GitilesView(com.google.gitiles.GitilesView) ImmutableList(com.google.common.collect.ImmutableList) List(java.util.List) RevWalk(org.eclipse.jgit.revwalk.RevWalk)

Aggregations

GitilesView (com.google.gitiles.GitilesView)4 Repository (org.eclipse.jgit.lib.Repository)3 RevWalk (org.eclipse.jgit.revwalk.RevWalk)3 ImmutableList (com.google.common.collect.ImmutableList)1 BlobSoyData (com.google.gitiles.BlobSoyData)1 DateFormatter (com.google.gitiles.DateFormatter)1 GitilesAccess (com.google.gitiles.GitilesAccess)1 TypeToken (com.google.gson.reflect.TypeToken)1 IOException (java.io.IOException)1 List (java.util.List)1 IncorrectObjectTypeException (org.eclipse.jgit.errors.IncorrectObjectTypeException)1 LargeObjectException (org.eclipse.jgit.errors.LargeObjectException)1 ObjectReader (org.eclipse.jgit.lib.ObjectReader)1 RevTree (org.eclipse.jgit.revwalk.RevTree)1