Example usage for org.eclipse.jgit.lib PersonIdent equals

List of usage examples for org.eclipse.jgit.lib PersonIdent equals

Introduction

In this page you can find the example usage for org.eclipse.jgit.lib PersonIdent equals.

Prototype

@Override
public boolean equals(Object o) 

Source Link

Usage

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   w w w  . j a v a 2 s . 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.madgag.agit.CommitDetailsFragment.java

License:Open Source License

@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {

    try {//  w  ww  .jav a 2  s.  c  om
        Repository repository = new FileRepository(gitDirFrom(getArguments()));
        ObjectId commitId = revisionIdFrom(repository, getArguments(), REVISION);
        Log.d(TAG, "onCreateView with " + commitId);

        View v = inflater.inflate(R.layout.commit_detail_view, container, false);

        CommitNavigationView commitNavigationView = (CommitNavigationView) v
                .findViewById(R.id.commit_navigation);

        commitNavigationView.setCommitSelectedListener(commitSelectedListener);
        PlotCommit<PlotLane> commit = commitSelectedListener.plotCommitFor(commitId);

        commitNavigationView.setCommit(commit);

        ((ObjectIdView) v.findViewById(R.id.commit_id)).setObjectId(commit);

        ViewGroup vg = (ViewGroup) v.findViewById(R.id.commit_people_group);

        PersonIdent author = commit.getAuthorIdent(), committer = commit.getCommitterIdent();
        if (author.equals(committer)) {
            addPerson("Author & Committer", author, vg);
        } else {
            addPerson("Author", author, vg);
            addPerson("Committer", committer, vg);
        }
        TextView textView = (TextView) v.findViewById(R.id.commit_message_text);
        textView.setText(commit.getFullMessage());
        return v;
    } catch (IOException e) {
        throw new RuntimeException(e);
    }
}

From source file:com.madgag.agit.CommitView.java

License:Open Source License

private void showCommitDetailsFor(final PlotCommit<PlotLane> commit) {
    commitNavigationView = (CommitNavigationView) findViewById(R.id.commit_navigation);
    Log.d("CV", "Got commitNavigationView=" + commitNavigationView + " commitSelectedListener="
            + commitSelectedListener);/*from w  ww.  j a v a  2  s. c om*/
    commitNavigationView.setCommitSelectedListener(commitSelectedListener);

    ((ObjectIdView) findViewById(R.id.commit_id)).setObjectId(commit);

    ViewGroup vg = (ViewGroup) findViewById(R.id.commit_people_group);

    PersonIdent author = commit.getAuthorIdent(), committer = commit.getCommitterIdent();
    if (author.equals(committer)) {
        addPerson("Author & Committer", author, vg);
    } else {
        addPerson("Author", author, vg);
        addPerson("Committer", committer, vg);
    }
    //      ViewGroup vg = (ViewGroup) findViewById(R.id.commit_refs_group);
    //      for (int i=0; i<commit.getRefCount(); ++i) {
    //         TextView tv = new TextView(getContext());
    //         tv.setText(commit.getRef(i).getName());
    //         vg.addView(tv);
    //      }
    TextView textView = (TextView) findViewById(R.id.commit_message_text);
    textView.setText(commit.getFullMessage());
    //      
    //      int width=textView.getBackground().getIntrinsicWidth(); // textView.getBackground is null at somepoint?
    //      Log.d("CV", "M Width = "+width);
    //      textView.setTextSize(TypedValue.COMPLEX_UNIT_PX, width/80);
}

From source file:org.eclipse.egit.ui.internal.blame.BlameInformationControl.java

License:Open Source License

public void setInput(Object input) {
    this.revision = (BlameRevision) input;

    RevCommit commit = this.revision.getCommit();

    String linkText = MessageFormat.format(UIText.BlameInformationControl_Commit, commit.name());
    commitLink.setText(linkText);/*from  w w w .  ja v  a  2  s .c o m*/
    StyleRange styleRange = new StyleRange(0, linkText.length(), null, null);
    styleRange.underline = true;
    commitLink.setStyleRange(styleRange);

    PersonIdent author = commit.getAuthorIdent();
    if (author != null) {
        setControlVisible(authorLabel, true);
        authorLabel.setText(MessageFormat.format(UIText.BlameInformationControl_Author, author.getName(),
                author.getEmailAddress(), author.getWhen()));
    } else
        setControlVisible(authorLabel, false);

    PersonIdent committer = commit.getCommitterIdent();
    setControlVisible(authorLabel, author != null);
    if (committer != null && !committer.equals(author)) {
        setControlVisible(committerLabel, true);
        committerLabel.setText(MessageFormat.format(UIText.BlameInformationControl_Committer,
                committer.getName(), committer.getEmailAddress(), committer.getWhen()));
    } else
        setControlVisible(committerLabel, false);

    messageText.setText(commit.getFullMessage());

    scrolls.setMinSize(displayArea.computeSize(SWT.DEFAULT, SWT.DEFAULT));
}

From source file:org.eclipse.egit.ui.internal.commit.CommitEditorPage.java

License:Open Source License

private void createHeaderArea(Composite parent, FormToolkit toolkit, int span) {
    RevCommit commit = getCommit().getRevCommit();
    Composite top = toolkit.createComposite(parent);
    GridDataFactory.fillDefaults().grab(true, false).span(span, 1).applyTo(top);
    GridLayoutFactory.fillDefaults().numColumns(2).applyTo(top);

    Composite userArea = toolkit.createComposite(top);
    GridLayoutFactory.fillDefaults().spacing(2, 2).numColumns(1).applyTo(userArea);
    GridDataFactory.fillDefaults().grab(true, false).applyTo(userArea);

    PersonIdent author = commit.getAuthorIdent();
    if (author != null)
        createUserArea(userArea, toolkit, author, true);

    PersonIdent committer = commit.getCommitterIdent();
    if (committer != null && !committer.equals(author))
        createUserArea(userArea, toolkit, committer, false);

    int count = commit.getParentCount();
    if (count > 0) {
        Composite parents = toolkit.createComposite(top);
        GridLayoutFactory.fillDefaults().spacing(2, 2).numColumns(2).applyTo(parents);
        GridDataFactory.fillDefaults().grab(false, false).applyTo(parents);

        for (int i = 0; i < count; i++) {
            final RevCommit parentCommit = commit.getParent(i);
            toolkit.createLabel(parents, UIText.CommitEditorPage_LabelParent)
                    .setForeground(toolkit.getColors().getColor(IFormColors.TB_TOGGLE));
            final Hyperlink link = toolkit.createHyperlink(parents,
                    parentCommit.abbreviate(PARENT_LENGTH).name(), SWT.NONE);
            link.addHyperlinkListener(new HyperlinkAdapter() {

                public void linkActivated(HyperlinkEvent e) {
                    try {
                        CommitEditor.open(new RepositoryCommit(getCommit().getRepository(), parentCommit));
                        if ((e.getStateMask() & SWT.MOD1) != 0)
                            getEditor().close(false);
                    } catch (PartInitException e1) {
                        Activator.logError("Error opening commit editor", e1);//$NON-NLS-1$
                    }/*from w ww  . j ava 2s.c om*/
                }
            });
        }
    }

    createTagsArea(userArea, toolkit, 2);
}