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

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

Introduction

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

Prototype

int OBJ_COMMIT

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

Click Source Link

Document

In-pack object type: commit.

Usage

From source file:com.gitblit.wicket.pages.TagPage.java

License:Apache License

public TagPage(PageParameters params) {
    super(params);

    Repository r = getRepository();//from w ww  .j a  v a2s  .c  o  m

    // Find tag in repository
    List<RefModel> tags = JGitUtils.getTags(r, true, -1);
    RefModel tagRef = null;
    for (RefModel tag : tags) {
        if (tag.getName().equals(objectId) || tag.getObjectId().getName().equals(objectId)) {
            tagRef = tag;
            break;
        }
    }

    // Failed to find tag!
    if (tagRef == null) {
        error(MessageFormat.format(getString("gb.couldNotFindTag"), objectId), true);
    }

    // Display tag.
    Class<? extends WebPage> linkClass;
    PageParameters linkParameters = newCommitParameter(tagRef.getReferencedObjectId().getName());
    String typeKey;
    switch (tagRef.getReferencedObjectType()) {
    case Constants.OBJ_BLOB:
        typeKey = "gb.blob";
        linkClass = BlobPage.class;
        break;
    case Constants.OBJ_TREE:
        typeKey = "gb.tree";
        linkClass = TreePage.class;
        break;
    case Constants.OBJ_COMMIT:
    default:
        typeKey = "gb.commit";
        linkClass = CommitPage.class;
        break;
    }
    add(new AvatarImage("taggerAvatar", tagRef.getAuthorIdent()));

    add(new RefsPanel("tagName", repositoryName, Arrays.asList(tagRef)));
    add(new Label("tagId", tagRef.getObjectId().getName()));
    add(new LinkPanel("taggedObject", "list", tagRef.getReferencedObjectId().getName(), linkClass,
            linkParameters));
    add(new Label("taggedObjectType", getString(typeKey)));

    add(createPersonPanel("tagger", tagRef.getAuthorIdent(), com.gitblit.Constants.SearchType.AUTHOR));
    Date when = new Date(0);
    if (tagRef.getAuthorIdent() != null) {
        when = tagRef.getAuthorIdent().getWhen();
    }
    add(WicketUtils.createTimestampLabel("tagDate", when, getTimeZone(), getTimeUtils()));

    addFullText("fullMessage", tagRef.getFullMessage());
}

From source file:com.gitblit.wicket.panels.TagsPanel.java

License:Apache License

public TagsPanel(String wicketId, final String repositoryName, Repository r, final int maxCount) {
    super(wicketId);

    // header//from   www. j a  va 2  s. c  o m
    List<RefModel> tags = JGitUtils.getTags(r, false, maxCount);
    if (maxCount > 0) {
        // summary page
        // show tags page link
        add(new LinkPanel("header", "title", new StringResourceModel("gb.tags", this, null), TagsPage.class,
                WicketUtils.newRepositoryParameter(repositoryName)));
    } else {
        // tags page
        add(new Label("header", new StringResourceModel("gb.tags", this, null)));
    }

    ListDataProvider<RefModel> tagsDp = new ListDataProvider<RefModel>(tags);
    DataView<RefModel> tagView = new DataView<RefModel>("tag", tagsDp) {
        private static final long serialVersionUID = 1L;
        int counter;

        @Override
        public void populateItem(final Item<RefModel> item) {
            RefModel entry = item.getModelObject();

            item.add(WicketUtils.createDateLabel("tagDate", entry.getDate(), getTimeZone(), getTimeUtils()));

            Class<? extends WebPage> linkClass;
            switch (entry.getReferencedObjectType()) {
            case Constants.OBJ_BLOB:
                linkClass = BlobPage.class;
                break;
            case Constants.OBJ_TREE:
                linkClass = TreePage.class;
                break;
            case Constants.OBJ_COMMIT:
            default:
                linkClass = CommitPage.class;
                break;
            }
            item.add(new LinkPanel("tagName", "list name", entry.displayName, linkClass,
                    WicketUtils.newObjectParameter(repositoryName, entry.getReferencedObjectId().getName())));

            // workaround for RevTag returning a lengthy shortlog. :(
            String message = StringUtils.trimString(entry.getShortMessage(),
                    com.gitblit.Constants.LEN_SHORTLOG);

            if (linkClass.equals(BlobPage.class)) {
                // Blob Tag Object
                item.add(WicketUtils.newImage("tagIcon", "file_16x16.png"));
                LinkPanel messageLink = new LinkPanel("tagDescription", "list", message, TagPage.class,
                        WicketUtils.newObjectParameter(repositoryName, entry.getObjectId().getName()));
                if (!entry.getShortMessage().equals(message)) {
                    messageLink.setTooltip(entry.getShortMessage());
                }
                item.add(messageLink);

                Fragment fragment = new Fragment("tagLinks", "blobLinks", TagsPanel.this);
                fragment.add(new BookmarkablePageLink<Void>("tag", TagPage.class,
                        WicketUtils.newObjectParameter(repositoryName, entry.getObjectId().getName()))
                                .setEnabled(entry.isAnnotatedTag()));

                fragment.add(new BookmarkablePageLink<Void>("blob", linkClass, WicketUtils
                        .newObjectParameter(repositoryName, entry.getReferencedObjectId().getName())));

                String contextUrl = GitBlitRequestUtils.getRelativePathPrefixToContextRoot();
                String rawUrl = RawServlet.asLink(contextUrl, repositoryName, entry.displayName,
                        entry.getReferencedObjectId().getName());
                fragment.add(new ExternalLink("raw", rawUrl));
                item.add(fragment);
            } else {
                // TODO Tree Tag Object
                // Standard Tag Object
                if (entry.isAnnotatedTag()) {
                    item.add(WicketUtils.newImage("tagIcon", "tag_16x16.png"));
                    LinkPanel messageLink = new LinkPanel("tagDescription", "list", message, TagPage.class,
                            WicketUtils.newObjectParameter(repositoryName, entry.getObjectId().getName()));
                    if (!message.equals(entry.getShortMessage())) {
                        messageLink.setTooltip(entry.getShortMessage());
                    }
                    item.add(messageLink);

                    Fragment fragment = new Fragment("tagLinks", "annotatedLinks", TagsPanel.this);
                    fragment.add(new BookmarkablePageLink<Void>("tag", TagPage.class,
                            WicketUtils.newObjectParameter(repositoryName, entry.getObjectId().getName()))
                                    .setEnabled(entry.isAnnotatedTag()));

                    fragment.add(new BookmarkablePageLink<Void>("commit", linkClass, WicketUtils
                            .newObjectParameter(repositoryName, entry.getReferencedObjectId().getName())));

                    fragment.add(new BookmarkablePageLink<Void>("log", LogPage.class,
                            WicketUtils.newObjectParameter(repositoryName, entry.getName())));
                    item.add(fragment);
                } else {
                    item.add(WicketUtils.newBlankImage("tagIcon"));
                    item.add(new LinkPanel("tagDescription", "list", message, CommitPage.class,
                            WicketUtils.newObjectParameter(repositoryName, entry.getObjectId().getName())));
                    Fragment fragment = new Fragment("tagLinks", "lightweightLinks", TagsPanel.this);
                    fragment.add(new BookmarkablePageLink<Void>("commit", CommitPage.class, WicketUtils
                            .newObjectParameter(repositoryName, entry.getReferencedObjectId().getName())));
                    fragment.add(new BookmarkablePageLink<Void>("log", LogPage.class,
                            WicketUtils.newObjectParameter(repositoryName, entry.getName())));
                    item.add(fragment);
                }
            }

            WicketUtils.setAlternatingBackground(item, counter);
            counter++;
        }
    };
    add(tagView);
    if (tags.size() < maxCount || maxCount <= 0) {
        add(new Label("allTags", "").setVisible(false));
    } else {
        add(new LinkPanel("allTags", "link", new StringResourceModel("gb.allTags", this, null), TagsPage.class,
                WicketUtils.newRepositoryParameter(repositoryName)));
    }

    hasTags = tags.size() > 0;
}

From source file:com.google.gerrit.server.git.SubmoduleOp.java

License:Apache License

/**
 * Update the submodules in one branch of one repository.
 *
 * @param subscriber the branch of the repository which should be changed.
 * @param updates submodule updates which should be updated to.
 * @throws SubmoduleException/*from  ww  w.j  av a2s  . c  om*/
 */
private void updateGitlinks(ReviewDb db, Branch.NameKey subscriber, Collection<SubmoduleSubscription> updates)
        throws SubmoduleException {
    PersonIdent author = null;
    StringBuilder msgbuf = new StringBuilder("Updated git submodules\n\n");
    boolean sameAuthorForAll = true;

    try (Repository pdb = repoManager.openRepository(subscriber.getParentKey())) {
        if (pdb.getRef(subscriber.get()) == null) {
            throw new SubmoduleException("The branch was probably deleted from the subscriber repository");
        }

        DirCache dc = readTree(pdb, pdb.getRef(subscriber.get()));
        DirCacheEditor ed = dc.editor();

        for (SubmoduleSubscription s : updates) {
            try (Repository subrepo = repoManager.openRepository(s.getSubmodule().getParentKey());
                    RevWalk rw = CodeReviewCommit.newRevWalk(subrepo)) {
                Ref ref = subrepo.getRefDatabase().exactRef(s.getSubmodule().get());
                if (ref == null) {
                    ed.add(new DeletePath(s.getPath()));
                    continue;
                }

                final ObjectId updateTo = ref.getObjectId();
                RevCommit newCommit = rw.parseCommit(updateTo);

                if (author == null) {
                    author = newCommit.getAuthorIdent();
                } else if (!author.equals(newCommit.getAuthorIdent())) {
                    sameAuthorForAll = false;
                }

                DirCacheEntry dce = dc.getEntry(s.getPath());
                ObjectId oldId;
                if (dce != null) {
                    if (!dce.getFileMode().equals(FileMode.GITLINK)) {
                        log.error("Requested to update gitlink " + s.getPath() + " in "
                                + s.getSubmodule().getParentKey().get() + " but entry "
                                + "doesn't have gitlink file mode.");
                        continue;
                    }
                    oldId = dce.getObjectId();
                } else {
                    // This submodule did not exist before. We do not want to add
                    // the full submodule history to the commit message, so omit it.
                    oldId = updateTo;
                }

                ed.add(new PathEdit(s.getPath()) {
                    @Override
                    public void apply(DirCacheEntry ent) {
                        ent.setFileMode(FileMode.GITLINK);
                        ent.setObjectId(updateTo);
                    }
                });
                if (verboseSuperProject) {
                    msgbuf.append("Project: " + s.getSubmodule().getParentKey().get());
                    msgbuf.append(" " + s.getSubmodule().getShortName());
                    msgbuf.append(" " + updateTo.getName());
                    msgbuf.append("\n\n");

                    try {
                        rw.markStart(newCommit);
                        rw.markUninteresting(rw.parseCommit(oldId));
                        for (RevCommit c : rw) {
                            msgbuf.append(c.getFullMessage() + "\n\n");
                        }
                    } catch (IOException e) {
                        logAndThrowSubmoduleException(
                                "Could not perform a revwalk to " + "create superproject commit message", e);
                    }
                }
            }
        }
        ed.finish();

        if (!sameAuthorForAll || author == null) {
            author = myIdent;
        }

        ObjectInserter oi = pdb.newObjectInserter();
        ObjectId tree = dc.writeTree(oi);

        ObjectId currentCommitId = pdb.getRef(subscriber.get()).getObjectId();

        CommitBuilder commit = new CommitBuilder();
        commit.setTreeId(tree);
        commit.setParentIds(new ObjectId[] { currentCommitId });
        commit.setAuthor(author);
        commit.setCommitter(myIdent);
        commit.setMessage(msgbuf.toString());
        oi.insert(commit);
        oi.flush();

        ObjectId commitId = oi.idFor(Constants.OBJ_COMMIT, commit.build());

        final RefUpdate rfu = pdb.updateRef(subscriber.get());
        rfu.setForceUpdate(false);
        rfu.setNewObjectId(commitId);
        rfu.setExpectedOldObjectId(currentCommitId);
        rfu.setRefLogMessage("Submit to " + subscriber.getParentKey().get(), true);

        switch (rfu.update()) {
        case NEW:
        case FAST_FORWARD:
            gitRefUpdated.fire(subscriber.getParentKey(), rfu);
            changeHooks.doRefUpdatedHook(subscriber, rfu, account);
            // TODO since this is performed "in the background" no mail will be
            // sent to inform users about the updated branch
            break;

        default:
            throw new IOException(rfu.getResult().name());
        }
        // Recursive call: update subscribers of the subscriber
        updateSuperProjects(db, Sets.newHashSet(subscriber));
    } catch (IOException e) {
        throw new SubmoduleException("Cannot update gitlinks for " + subscriber.get(), e);
    }
}

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

License:Open Source License

Long getTime(final RevWalk walk, final ObjectId id) throws IOException {
    try {//from   w w w  . ja  v a  2s .  c  o  m
        return cache.get(id, new Callable<Long>() {
            @Override
            public Long call() throws IOException {
                RevObject o = walk.parseAny(id);
                while (o instanceof RevTag) {
                    RevTag tag = (RevTag) o;
                    PersonIdent ident = tag.getTaggerIdent();
                    if (ident != null) {
                        return ident.getWhen().getTime() / 1000;
                    }
                    o = tag.getObject();
                    walk.parseHeaders(o);
                }
                if (o.getType() == Constants.OBJ_COMMIT) {
                    return Long.valueOf(((RevCommit) o).getCommitTime());
                }
                return Long.MIN_VALUE;
            }
        });
    } catch (ExecutionException e) {
        Throwables.propagateIfInstanceOf(e.getCause(), IOException.class);
        throw new IOException(e);
    }
}

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

License:Open Source License

private String getCommand(String command, RevisionParser.Result result, String path) {
    // Note: if you change the mapping for +, make sure to change
    // GitilesView.toUrl() correspondingly.
    if (!CMD_AUTO.equals(command)) {
        return command;
    } else if (result.getOldRevision() != null) {
        return CMD_DIFF;
    }/*ww w.  j a v  a2s .co m*/
    Revision rev = result.getRevision();
    if (rev.getPeeledType() != Constants.OBJ_COMMIT || !path.isEmpty() || result.getRevision().nameIsId()) {
        return CMD_SHOW;
    } else {
        return CMD_LOG;
    }
}

From source file:com.tasktop.c2c.server.scm.service.GitBrowseUtil.java

License:Open Source License

private static Item.Type getType(int type) {
    switch (type) {
    case Constants.OBJ_BLOB:
        return Item.Type.BLOB;
    case Constants.OBJ_TREE:
        return Item.Type.TREE;
    case Constants.OBJ_COMMIT:
        return Item.Type.COMMIT;
    // XXX add more
    default://ww  w.  j  a v  a 2  s .  c om
        return null;
    }
}

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

License:Eclipse Distribution License

private void process(final ObjectId id) throws TransportException {
    final RevObject obj;
    try {/*ww  w.ja  va 2s .c om*/
        if (id instanceof RevObject) {
            obj = (RevObject) id;
            if (obj.has(COMPLETE))
                return;
            revWalk.parseHeaders(obj);
        } else {
            obj = revWalk.parseAny(id);
            if (obj.has(COMPLETE))
                return;
        }
    } catch (IOException e) {
        throw new TransportException(MessageFormat.format(JGitText.get().cannotRead, id.name()), e);
    }

    switch (obj.getType()) {
    case Constants.OBJ_BLOB:
        processBlob(obj);
        break;
    case Constants.OBJ_TREE:
        processTree(obj);
        break;
    case Constants.OBJ_COMMIT:
        processCommit(obj);
        break;
    case Constants.OBJ_TAG:
        processTag(obj);
        break;
    default:
        throw new TransportException(MessageFormat.format(JGitText.get().unknownObjectType, id.name()));
    }

    // If we had any prior errors fetching this object they are
    // now resolved, as the object was parsed successfully.
    //
    fetchErrors.remove(id);
}

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

License:Eclipse Distribution License

private void markLocalObjComplete(RevObject obj) throws IOException {
    while (obj.getType() == Constants.OBJ_TAG) {
        obj.add(COMPLETE);/*from w  ww  .ja  v  a2 s . co  m*/
        obj = ((RevTag) obj).getObject();
        revWalk.parseHeaders(obj);
    }

    switch (obj.getType()) {
    case Constants.OBJ_BLOB:
        obj.add(COMPLETE);
        break;
    case Constants.OBJ_COMMIT:
        pushLocalCommit((RevCommit) obj);
        break;
    case Constants.OBJ_TREE:
        markTreeComplete((RevTree) obj);
        break;
    }
}

From source file:jetbrains.buildServer.buildTriggers.vcs.git.GitCollectChangesPolicy.java

License:Apache License

private List<RevCommit> getCommits(@NotNull RepositoryStateData state, @NotNull Repository r,
        @NotNull RevWalk walk) throws IOException {
    List<RevCommit> revisions = new ArrayList<RevCommit>();
    for (String revision : state.getBranchRevisions().values()) {
        ObjectId id = ObjectId.fromString(GitUtils.versionRevision(revision));
        if (r.hasObject(id)) {
            RevObject obj = walk.parseAny(id);
            if (obj.getType() == Constants.OBJ_COMMIT)
                revisions.add((RevCommit) obj);
        }/*from  www  . ja v a  2 s  .  c om*/
    }
    return revisions;
}

From source file:jetbrains.buildServer.buildTriggers.vcs.git.GitMapFullPath.java

License:Apache License

private Set<String> getNewCommits(@NotNull Repository db, @NotNull Map<String, Ref> oldRefs,
        @NotNull Map<String, Ref> newRefs) throws IOException {
    Set<ObjectId> updatedHeads = new HashSet<ObjectId>();
    Set<ObjectId> uninteresting = new HashSet<ObjectId>();
    for (Map.Entry<String, Ref> e : newRefs.entrySet()) {
        String refName = e.getKey();
        if (!refName.startsWith("refs/"))
            continue;
        Ref newRef = e.getValue();
        Ref oldRef = oldRefs.get(refName);
        if (oldRef == null || !oldRef.getObjectId().equals(newRef.getObjectId()))
            updatedHeads.add(newRef.getObjectId());
        if (oldRef != null)
            uninteresting.add(oldRef.getObjectId());
    }/*w  w  w  .j ava2s. co m*/

    RevWalk revWalk = new RevWalk(db);
    try {
        revWalk.sort(RevSort.TOPO);
        for (ObjectId id : updatedHeads) {
            RevObject obj = revWalk.parseAny(id);
            if (obj.getType() == Constants.OBJ_COMMIT)
                revWalk.markStart((RevCommit) obj);
        }
        for (ObjectId id : uninteresting) {
            RevObject obj = revWalk.parseAny(id);
            if (obj.getType() == Constants.OBJ_COMMIT)
                revWalk.markUninteresting((RevCommit) obj);
        }
        Set<String> newCommits = new HashSet<String>();
        RevCommit newCommit = null;
        while ((newCommit = revWalk.next()) != null) {
            newCommits.add(newCommit.name());
        }
        return newCommits;
    } finally {
        revWalk.dispose();
    }
}