Search in sources :

Example 1 with Field

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();
        }
    }
}
Also used : Field(com.google.gitiles.CommitData.Field) Repository(org.eclipse.jgit.lib.Repository) RevCommit(org.eclipse.jgit.revwalk.RevCommit) TypeToken(com.google.gson.reflect.TypeToken) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 2 with Field

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);
        }
    }
}
Also used : OutputStream(java.io.OutputStream) IncorrectObjectTypeException(org.eclipse.jgit.errors.IncorrectObjectTypeException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) MissingObjectException(org.eclipse.jgit.errors.MissingObjectException) AbstractTreeIterator(org.eclipse.jgit.treewalk.AbstractTreeIterator) Field(com.google.gitiles.CommitData.Field) Repository(org.eclipse.jgit.lib.Repository) DiffFormatter(org.eclipse.jgit.diff.DiffFormatter) TreeWalk(org.eclipse.jgit.treewalk.TreeWalk)

Aggregations

Field (com.google.gitiles.CommitData.Field)2 Repository (org.eclipse.jgit.lib.Repository)2 TypeToken (com.google.gson.reflect.TypeToken)1 OutputStream (java.io.OutputStream)1 DiffFormatter (org.eclipse.jgit.diff.DiffFormatter)1 IncorrectObjectTypeException (org.eclipse.jgit.errors.IncorrectObjectTypeException)1 MissingObjectException (org.eclipse.jgit.errors.MissingObjectException)1 RevCommit (org.eclipse.jgit.revwalk.RevCommit)1 RevWalk (org.eclipse.jgit.revwalk.RevWalk)1 AbstractTreeIterator (org.eclipse.jgit.treewalk.AbstractTreeIterator)1 TreeWalk (org.eclipse.jgit.treewalk.TreeWalk)1