Search in sources :

Example 11 with RevTree

use of org.eclipse.jgit.revwalk.RevTree in project gerrit by GerritCodeReview.

the class AbstractSubmoduleSubscription method expectToHaveSubmoduleState.

protected void expectToHaveSubmoduleState(TestRepository<?> repo, String branch, String submodule, ObjectId expectedId) throws Exception {
    submodule = name(submodule);
    ObjectId commitId = repo.git().fetch().setRemote("origin").call().getAdvertisedRef("refs/heads/" + branch).getObjectId();
    RevWalk rw = repo.getRevWalk();
    RevCommit c = rw.parseCommit(commitId);
    rw.parseBody(c.getTree());
    RevTree tree = c.getTree();
    RevObject actualId = repo.get(tree, submodule);
    assertThat(actualId).isEqualTo(expectedId);
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) RevObject(org.eclipse.jgit.revwalk.RevObject) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RevTree(org.eclipse.jgit.revwalk.RevTree) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 12 with RevTree

use of org.eclipse.jgit.revwalk.RevTree in project gerrit by GerritCodeReview.

the class AbstractSubmoduleSubscription method expectToHaveSubmoduleState.

protected void expectToHaveSubmoduleState(TestRepository<?> repo, String branch, String submodule, TestRepository<?> subRepo, String subBranch) throws Exception {
    submodule = name(submodule);
    ObjectId commitId = repo.git().fetch().setRemote("origin").call().getAdvertisedRef("refs/heads/" + branch).getObjectId();
    ObjectId subHead = subRepo.git().fetch().setRemote("origin").call().getAdvertisedRef("refs/heads/" + subBranch).getObjectId();
    RevWalk rw = repo.getRevWalk();
    RevCommit c = rw.parseCommit(commitId);
    rw.parseBody(c.getTree());
    RevTree tree = c.getTree();
    RevObject actualId = repo.get(tree, submodule);
    assertThat(actualId).isEqualTo(subHead);
}
Also used : ObjectId(org.eclipse.jgit.lib.ObjectId) RevObject(org.eclipse.jgit.revwalk.RevObject) RevWalk(org.eclipse.jgit.revwalk.RevWalk) RevTree(org.eclipse.jgit.revwalk.RevTree) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 13 with RevTree

use of org.eclipse.jgit.revwalk.RevTree in project gitiles by GerritCodeReview.

the class RevisionServlet method doGetHtml.

@Override
protected void doGetHtml(HttpServletRequest req, HttpServletResponse res) throws IOException {
    GitilesView view = ViewFilter.getView(req);
    Repository repo = ServletUtils.getRepository(req);
    GitilesAccess access = getAccess(req);
    Config cfg = getAccess(req).getConfig();
    try (RevWalk walk = new RevWalk(repo)) {
        DateFormatter df = new DateFormatter(access, Format.DEFAULT);
        List<RevObject> objects = listObjects(walk, view.getRevision());
        List<Map<String, ?>> soyObjects = Lists.newArrayListWithCapacity(objects.size());
        boolean hasBlob = false;
        boolean hasReadme = false;
        // TODO(sop): Allow caching commits by SHA-1 when no S cookie is sent.
        for (RevObject obj : objects) {
            try {
                switch(obj.getType()) {
                    case OBJ_COMMIT:
                        soyObjects.add(ImmutableMap.of("type", Constants.TYPE_COMMIT, "data", new CommitSoyData().setLinkifier(linkifier).setRevWalk(walk).setArchiveFormat(getArchiveFormat(access)).toSoyData(req, (RevCommit) obj, COMMIT_SOY_FIELDS, df)));
                        break;
                    case OBJ_TREE:
                        Map<String, Object> tree = new TreeSoyData(walk.getObjectReader(), view, cfg, (RevTree) obj, req.getRequestURI()).toSoyData(obj);
                        soyObjects.add(ImmutableMap.of("type", Constants.TYPE_TREE, "data", tree));
                        hasReadme = tree.containsKey("readmeHtml");
                        break;
                    case OBJ_BLOB:
                        soyObjects.add(ImmutableMap.of("type", Constants.TYPE_BLOB, "data", new BlobSoyData(walk.getObjectReader(), view).toSoyData(obj)));
                        hasBlob = true;
                        break;
                    case OBJ_TAG:
                        soyObjects.add(ImmutableMap.of("type", Constants.TYPE_TAG, "data", new TagSoyData(linkifier, req).toSoyData((RevTag) obj, df)));
                        break;
                    default:
                        log.warn("Bad object type for {}: {}", ObjectId.toString(obj.getId()), obj.getType());
                        res.setStatus(SC_NOT_FOUND);
                        return;
                }
            } catch (MissingObjectException e) {
                log.warn("Missing object " + ObjectId.toString(obj.getId()), e);
                res.setStatus(SC_NOT_FOUND);
                return;
            } catch (IncorrectObjectTypeException e) {
                log.warn("Incorrect object type for " + ObjectId.toString(obj.getId()), e);
                res.setStatus(SC_NOT_FOUND);
                return;
            }
        }
        renderHtml(req, res, "gitiles.revisionDetail", ImmutableMap.of("title", view.getRevision().getName(), "objects", soyObjects, "hasBlob", hasBlob, "hasReadme", hasReadme));
    }
}
Also used : RevObject(org.eclipse.jgit.revwalk.RevObject) Config(org.eclipse.jgit.lib.Config) IncorrectObjectTypeException(org.eclipse.jgit.errors.IncorrectObjectTypeException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) MissingObjectException(org.eclipse.jgit.errors.MissingObjectException) Repository(org.eclipse.jgit.lib.Repository) RevObject(org.eclipse.jgit.revwalk.RevObject) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) RevTree(org.eclipse.jgit.revwalk.RevTree)

Example 14 with RevTree

use of org.eclipse.jgit.revwalk.RevTree in project gitiles by GerritCodeReview.

the class BlameServlet method resolveBlob.

private static ObjectId resolveBlob(GitilesView view, RevWalk rw, ObjectId commitId) throws IOException {
    try {
        if (commitId == null || Strings.isNullOrEmpty(view.getPathPart())) {
            return null;
        }
        RevTree tree = rw.parseTree(commitId);
        TreeWalk tw = TreeWalk.forPath(rw.getObjectReader(), view.getPathPart(), tree);
        if (tw == null || (tw.getRawMode(0) & FileMode.TYPE_MASK) != FileMode.TYPE_FILE) {
            return null;
        }
        return tw.getObjectId(0);
    } catch (IncorrectObjectTypeException e) {
        return null;
    }
}
Also used : IncorrectObjectTypeException(org.eclipse.jgit.errors.IncorrectObjectTypeException) TreeWalk(org.eclipse.jgit.treewalk.TreeWalk) RevTree(org.eclipse.jgit.revwalk.RevTree)

Example 15 with RevTree

use of org.eclipse.jgit.revwalk.RevTree 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)

Aggregations

RevTree (org.eclipse.jgit.revwalk.RevTree)35 RevWalk (org.eclipse.jgit.revwalk.RevWalk)24 ObjectId (org.eclipse.jgit.lib.ObjectId)17 RevCommit (org.eclipse.jgit.revwalk.RevCommit)17 ObjectReader (org.eclipse.jgit.lib.ObjectReader)11 IOException (java.io.IOException)8 DiffEntry (org.eclipse.jgit.diff.DiffEntry)8 Repository (org.eclipse.jgit.lib.Repository)7 RevObject (org.eclipse.jgit.revwalk.RevObject)6 TreeWalk (org.eclipse.jgit.treewalk.TreeWalk)6 File (java.io.File)4 IncorrectObjectTypeException (org.eclipse.jgit.errors.IncorrectObjectTypeException)4 CanonicalTreeParser (org.eclipse.jgit.treewalk.CanonicalTreeParser)4 ArrayList (java.util.ArrayList)3 DiffFormatter (org.eclipse.jgit.diff.DiffFormatter)3 RawTextComparator (org.eclipse.jgit.diff.RawTextComparator)3 ObjectLoader (org.eclipse.jgit.lib.ObjectLoader)3 Ref (org.eclipse.jgit.lib.Ref)3 RevBlob (org.eclipse.jgit.revwalk.RevBlob)3 ByteArrayOutputStream (java.io.ByteArrayOutputStream)2