Example usage for org.eclipse.jgit.revwalk RevObject getId

List of usage examples for org.eclipse.jgit.revwalk RevObject getId

Introduction

In this page you can find the example usage for org.eclipse.jgit.revwalk RevObject getId.

Prototype

public final ObjectId getId() 

Source Link

Document

Get the name of this object.

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 ww. java  2  s.  c  om*/
        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();
    }
}

From source file:it.com.atlassian.labs.speakeasy.util.jgit.WalkFetchConnection.java

License:Eclipse Distribution License

private void processTree(final RevObject obj) throws TransportException {
    try {/*  w  ww.  ja  v a 2 s  .  c o m*/
        treeWalk.reset(obj);
        while (treeWalk.next()) {
            final FileMode mode = treeWalk.getFileMode(0);
            final int sType = mode.getObjectType();

            switch (sType) {
            case Constants.OBJ_BLOB:
            case Constants.OBJ_TREE:
                treeWalk.getObjectId(idBuffer, 0);
                needs(revWalk.lookupAny(idBuffer, sType));
                continue;

            default:
                if (FileMode.GITLINK.equals(mode))
                    continue;
                treeWalk.getObjectId(idBuffer, 0);
                throw new CorruptObjectException(MessageFormat.format(JGitText.get().invalidModeFor, mode,
                        idBuffer.name(), treeWalk.getPathString(), obj.getId().name()));
            }
        }
    } catch (IOException ioe) {
        throw new TransportException(MessageFormat.format(JGitText.get().cannotReadTree, obj.name()), ioe);
    }
    obj.add(COMPLETE);
}

From source file:org.eclipse.oomph.gitbash.revision.AbstractRevisionAction.java

License:Open Source License

@Override
protected void run(Shell shell, RevObject revision) throws Exception {
    Repository repository = getRepository();
    if (repository != null) {
        File workTree = repository.getWorkTree();
        String id = revision.getId().name();
        run(shell, workTree, id);//w  ww .  j av  a 2s.c  om
    }
}

From source file:org.kie.commons.java.nio.fs.jgit.util.JGitUtil.java

License:Apache License

public static InputStream resolveInputStream(final Git git, final String treeRef, final String path) {
    checkNotNull("git", git);
    checkNotEmpty("treeRef", treeRef);
    checkNotEmpty("path", path);

    final String gitPath = fixPath(path);

    RevWalk rw = null;/*  w  w w  .  j a v  a  2s.com*/
    TreeWalk tw = null;
    try {
        final ObjectId tree = git.getRepository().resolve(treeRef + "^{tree}");
        rw = new RevWalk(git.getRepository());
        tw = new TreeWalk(git.getRepository());
        tw.setFilter(createFromStrings(singleton(gitPath)));
        tw.reset(tree);
        while (tw.next()) {
            if (tw.isSubtree() && !gitPath.equals(tw.getPathString())) {
                tw.enterSubtree();
                continue;
            }
            final ObjectId entid = tw.getObjectId(0);
            final FileMode entmode = tw.getFileMode(0);
            final RevObject ro = rw.lookupAny(entid, entmode.getObjectType());
            rw.parseBody(ro);
            final ObjectLoader ldr = git.getRepository().open(ro.getId(), Constants.OBJ_BLOB);
            return ldr.openStream();
        }
    } catch (final Throwable t) {
        throw new NoSuchFileException("Can't find '" + gitPath + "' in tree '" + treeRef + "'");
    } finally {
        if (rw != null) {
            rw.dispose();
        }
        if (tw != null) {
            tw.release();
        }
    }
    throw new NoSuchFileException("");
}