Example usage for org.eclipse.jgit.lib Constants TYPE_COMMIT

List of usage examples for org.eclipse.jgit.lib Constants TYPE_COMMIT

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib Constants TYPE_COMMIT.

Prototype

String TYPE_COMMIT

To view the source code for org.eclipse.jgit.lib Constants TYPE_COMMIT.

Click Source Link

Document

Text string that identifies an object as a commit.

Usage

From source file:com.google.gitiles.RevisionServlet.java

License:Open Source License

@Override
protected void doGet(HttpServletRequest req, HttpServletResponse res) throws IOException {
    GitilesView view = ViewFilter.getView(req);
    Repository repo = ServletUtils.getRepository(req);

    RevWalk walk = new RevWalk(repo);
    try {/*w  w  w .  j  ava 2  s  . c  o m*/
        List<RevObject> objects = listObjects(walk, view.getRevision().getId());
        List<Map<String, ?>> soyObjects = Lists.newArrayListWithCapacity(objects.size());
        boolean hasBlob = 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(linkifier, req, repo, walk, view).toSoyData((RevCommit) obj,
                                    KeySet.DETAIL_DIFF_TREE)));
                    break;
                case OBJ_TREE:
                    soyObjects.add(ImmutableMap.of("type", Constants.TYPE_TREE, "data",
                            new TreeSoyData(walk, view).toSoyData(obj)));
                    break;
                case OBJ_BLOB:
                    soyObjects.add(ImmutableMap.of("type", Constants.TYPE_BLOB, "data",
                            new BlobSoyData(walk, 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)));
                    break;
                default:
                    log.warn("Bad object type for %s: %s", 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;
            }
        }

        render(req, res, "gitiles.revisionDetail", ImmutableMap.of("title", view.getRevision().getName(),
                "objects", soyObjects, "hasBlob", hasBlob));
    } finally {
        walk.release();
    }
}