Search in sources :

Example 31 with PersonIdent

use of org.eclipse.jgit.lib.PersonIdent in project gitiles by GerritCodeReview.

the class DateFormatterTest method defaultWithUtc.

@Test
public void defaultWithUtc() throws Exception {
    PersonIdent ident = newIdent("Mon Jan 2 15:04:05 2006", "-0700");
    DateFormatter df = new DateFormatter(Optional.of(getTimeZone("UTC")), DEFAULT);
    assertThat(df.format(ident)).isEqualTo("Mon Jan 02 22:04:05 2006");
}
Also used : PersonIdent(org.eclipse.jgit.lib.PersonIdent) Test(org.junit.Test)

Example 32 with PersonIdent

use of org.eclipse.jgit.lib.PersonIdent in project egit by eclipse.

the class CommitOperation method setAuthorAndCommitter.

private void setAuthorAndCommitter(CommitCommand commitCommand) throws TeamException {
    final Date commitDate = new Date();
    final TimeZone timeZone = TimeZone.getDefault();
    final PersonIdent enteredAuthor = RawParseUtils.parsePersonIdent(author);
    final PersonIdent enteredCommitter = RawParseUtils.parsePersonIdent(committer);
    if (enteredAuthor == null)
        throw new TeamException(NLS.bind(CoreText.CommitOperation_errorParsingPersonIdent, author));
    if (enteredCommitter == null)
        throw new TeamException(NLS.bind(CoreText.CommitOperation_errorParsingPersonIdent, committer));
    PersonIdent authorIdent;
    if (repo.getRepositoryState().equals(RepositoryState.CHERRY_PICKING_RESOLVED)) {
        try (RevWalk rw = new RevWalk(repo)) {
            ObjectId cherryPickHead = repo.readCherryPickHead();
            authorIdent = rw.parseCommit(cherryPickHead).getAuthorIdent();
        } catch (IOException e) {
            Activator.logError(CoreText.CommitOperation_ParseCherryPickCommitFailed, e);
            throw new IllegalStateException(e);
        }
    } else {
        authorIdent = new PersonIdent(enteredAuthor, commitDate, timeZone);
    }
    final PersonIdent committerIdent = new PersonIdent(enteredCommitter, commitDate, timeZone);
    if (amending) {
        RepositoryUtil repoUtil = Activator.getDefault().getRepositoryUtil();
        RevCommit headCommit = repoUtil.parseHeadCommit(repo);
        if (headCommit != null) {
            final PersonIdent headAuthor = headCommit.getAuthorIdent();
            authorIdent = new PersonIdent(enteredAuthor, headAuthor.getWhen(), headAuthor.getTimeZone());
        }
    }
    commitCommand.setAuthor(authorIdent);
    commitCommand.setCommitter(committerIdent);
}
Also used : TeamException(org.eclipse.team.core.TeamException) TimeZone(java.util.TimeZone) PersonIdent(org.eclipse.jgit.lib.PersonIdent) ObjectId(org.eclipse.jgit.lib.ObjectId) IOException(java.io.IOException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) Date(java.util.Date) RepositoryUtil(org.eclipse.egit.core.RepositoryUtil) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 33 with PersonIdent

use of org.eclipse.jgit.lib.PersonIdent in project egit by eclipse.

the class RebaseInteractivePlan method createElement.

private PlanElement createElement(RebaseTodoLine todoLine, RevWalk walk) {
    PersonIdent author = null;
    PersonIdent committer = null;
    RevCommit commit = loadCommit(todoLine.getCommit(), walk);
    if (commit != null) {
        author = commit.getAuthorIdent();
        committer = commit.getCommitterIdent();
    }
    PlanElement element = new PlanElement(todoLine, author, committer);
    return element;
}
Also used : PersonIdent(org.eclipse.jgit.lib.PersonIdent) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 34 with PersonIdent

use of org.eclipse.jgit.lib.PersonIdent in project egit by eclipse.

the class ReplaceActionsTest method testReplaceWithPreviousWithMerge.

@Test
public void testReplaceWithPreviousWithMerge() throws Exception {
    Repository repo = lookupRepository(repositoryFile);
    try (Git git = new Git(repo)) {
        Calendar cal = Calendar.getInstance();
        long time = cal.getTime().getTime();
        PersonIdent sideCommitter = new PersonIdent("Side Committer", "side@example.org", time, 0);
        // Make sure commit time stamps are different, otherwise the order
        // in the dialog is not stable
        time += 5000;
        PersonIdent masterCommitter = new PersonIdent("Master Committer", "master@example.org", time, 0);
        git.checkout().setCreateBranch(true).setName("side").call();
        touch(PROJ1, "folder/test.txt", "side");
        RevCommit sideCommit = git.commit().setAll(true).setMessage("Side commit").setCommitter(sideCommitter).call();
        git.checkout().setName("master").call();
        touch(PROJ1, "folder/test2.txt", "master");
        git.commit().setAll(true).setMessage("Master commit").setCommitter(masterCommitter).call();
        git.merge().include(sideCommit).call();
    }
    TestUtil.waitForJobs(100, 5000);
    String contentAfterMerge = getTestFileContent();
    assertEquals("side", contentAfterMerge);
    String menuLabel = util.getPluginLocalizedValue("ReplaceWithPreviousVersionAction.label");
    clickReplaceWith(menuLabel);
    bot.shell(UIText.DiscardChangesAction_confirmActionTitle).bot().button(UIText.DiscardChangesAction_discardChangesButtonText).click();
    SWTBotShell selectDialog = bot.shell(UIText.CommitSelectDialog_WindowTitle);
    assertEquals(2, selectDialog.bot().table().rowCount());
    selectDialog.close();
    TestUtil.processUIEvents();
    // we have closed, so nothing should have changed
    String contentAfterClose = getTestFileContent();
    assertEquals(contentAfterMerge, contentAfterClose);
    clickReplaceWith(menuLabel);
    bot.shell(UIText.DiscardChangesAction_confirmActionTitle).bot().button(UIText.DiscardChangesAction_discardChangesButtonText).click();
    TestUtil.waitForJobs(100, 5000);
    selectDialog = bot.shell(UIText.CommitSelectDialog_WindowTitle);
    // Select first parent, which should be the master commit
    SWTBotTable table = selectDialog.bot().table();
    assertEquals("Master commit", table.cell(0, 1));
    table.select(0);
    executeReplace(selectDialog, IDialogConstants.OK_LABEL);
    TestUtil.waitForJobs(100, 5000);
    String replacedContent = getTestFileContent();
    assertThat(replacedContent, not(contentAfterMerge));
}
Also used : Repository(org.eclipse.jgit.lib.Repository) Git(org.eclipse.jgit.api.Git) PersonIdent(org.eclipse.jgit.lib.PersonIdent) Calendar(java.util.Calendar) SWTBotTable(org.eclipse.swtbot.swt.finder.widgets.SWTBotTable) SWTBotShell(org.eclipse.swtbot.swt.finder.widgets.SWTBotShell) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Test(org.junit.Test)

Example 35 with PersonIdent

use of org.eclipse.jgit.lib.PersonIdent in project egit by eclipse.

the class CommitInfoBuilder method format.

/**
 * Retrieves and formats the commit info.
 *
 * @param monitor
 *            for progress reporting and cancellation
 * @return formatted commit info
 * @throws IOException
 */
public FormatResult format(IProgressMonitor monitor) throws IOException {
    boolean trace = GitTraceLocation.HISTORYVIEW.isActive();
    if (trace)
        GitTraceLocation.getTrace().traceEntry(GitTraceLocation.HISTORYVIEW.getLocation());
    monitor.setTaskName(UIText.CommitMessageViewer_FormattingMessageTaskName);
    final StringBuilder d = new StringBuilder();
    final PersonIdent author = commit.getAuthorIdent();
    final PersonIdent committer = commit.getCommitterIdent();
    List<GitCommitReference> hyperlinks = new ArrayList<>();
    d.append(UIText.CommitMessageViewer_commit);
    d.append(' ');
    d.append(commit.getId().name());
    d.append(LF);
    addPersonIdent(d, author, UIText.CommitMessageViewer_author);
    addPersonIdent(d, committer, UIText.CommitMessageViewer_committer);
    for (int i = 0; i < commit.getParentCount(); i++) {
        addCommit(d, (SWTCommit) commit.getParent(i), UIText.CommitMessageViewer_parent, hyperlinks);
    }
    for (int i = 0; i < commit.getChildCount(); i++) {
        addCommit(d, (SWTCommit) commit.getChild(i), UIText.CommitMessageViewer_child, hyperlinks);
    }
    if (Activator.getDefault().getPreferenceStore().getBoolean(UIPreferences.HISTORY_SHOW_BRANCH_SEQUENCE)) {
        try (RevWalk rw = new RevWalk(db)) {
            List<Ref> branches = getBranches(commit, allRefs, db);
            if (!branches.isEmpty()) {
                d.append(UIText.CommitMessageViewer_branches);
                // $NON-NLS-1$
                d.append(": ");
                int count = 0;
                for (Iterator<Ref> i = branches.iterator(); i.hasNext(); ) {
                    Ref head = i.next();
                    RevCommit p;
                    p = rw.parseCommit(head.getObjectId());
                    addLink(d, formatHeadRef(head), hyperlinks, p);
                    if (i.hasNext()) {
                        if (count++ <= MAXBRANCHES) {
                            // $NON-NLS-1$
                            d.append(", ");
                        } else {
                            d.append(NLS.bind(UIText.CommitMessageViewer_MoreBranches, Integer.valueOf(branches.size() - MAXBRANCHES)));
                            break;
                        }
                    }
                }
                d.append(LF);
            }
        } catch (IOException e) {
            Activator.logError(e.getMessage(), e);
        }
    }
    String tagsString = getTagsString();
    if (tagsString.length() > 0) {
        d.append(UIText.CommitMessageViewer_tags);
        // $NON-NLS-1$
        d.append(": ");
        d.append(tagsString);
        d.append(LF);
    }
    if (Activator.getDefault().getPreferenceStore().getBoolean(UIPreferences.HISTORY_SHOW_TAG_SEQUENCE)) {
        try (RevWalk rw = new RevWalk(db)) {
            monitor.setTaskName(UIText.CommitMessageViewer_GettingPreviousTagTaskName);
            addTag(d, UIText.CommitMessageViewer_follows, rw, getNextTag(false, monitor), hyperlinks);
        } catch (IOException e) {
            Activator.logError(e.getMessage(), e);
        }
        try (RevWalk rw = new RevWalk(db)) {
            monitor.setTaskName(UIText.CommitMessageViewer_GettingNextTagTaskName);
            addTag(d, UIText.CommitMessageViewer_precedes, rw, getNextTag(true, monitor), hyperlinks);
        } catch (IOException e) {
            Activator.logError(e.getMessage(), e);
        }
    }
    d.append(LF);
    int headerEnd = d.length();
    String msg = commit.getFullMessage().trim();
    // Find start of footer:
    int footerStart = CommonUtils.getFooterOffset(msg);
    if (footerStart >= 0) {
        if (fill) {
            String footer = msg.substring(footerStart);
            msg = msg.substring(0, footerStart);
            msg = // $NON-NLS-1$ //$NON-NLS-2$
            msg.replaceAll("([\\w.,; \t])\n(\\w)", "$1 $2") + footer;
            footerStart = headerEnd + msg.length() - footer.length();
        } else {
            footerStart = headerEnd + footerStart;
        }
    } else if (fill) {
        // $NON-NLS-1$ //$NON-NLS-2$
        msg = msg.replaceAll("([\\w.,; \t])\n(\\w)", "$1 $2");
    }
    d.append(msg);
    if (!msg.endsWith(LF))
        d.append(LF);
    if (trace)
        GitTraceLocation.getTrace().traceExit(GitTraceLocation.HISTORYVIEW.getLocation());
    return new FormatResult(d.toString(), hyperlinks, headerEnd, footerStart >= 0 ? footerStart : d.length());
}
Also used : ArrayList(java.util.ArrayList) IOException(java.io.IOException) RevWalk(org.eclipse.jgit.revwalk.RevWalk) Ref(org.eclipse.jgit.lib.Ref) PersonIdent(org.eclipse.jgit.lib.PersonIdent) RevCommit(org.eclipse.jgit.revwalk.RevCommit) FormatResult(org.eclipse.egit.ui.internal.history.FormatJob.FormatResult)

Aggregations

PersonIdent (org.eclipse.jgit.lib.PersonIdent)221 RevCommit (org.eclipse.jgit.revwalk.RevCommit)78 ObjectId (org.eclipse.jgit.lib.ObjectId)55 Test (org.junit.Test)55 Repository (org.eclipse.jgit.lib.Repository)48 IOException (java.io.IOException)41 CommitBuilder (org.eclipse.jgit.lib.CommitBuilder)41 RevWalk (org.eclipse.jgit.revwalk.RevWalk)38 ObjectInserter (org.eclipse.jgit.lib.ObjectInserter)31 Change (com.google.gerrit.entities.Change)28 GerritPersonIdent (com.google.gerrit.server.GerritPersonIdent)26 Ref (org.eclipse.jgit.lib.Ref)26 Git (org.eclipse.jgit.api.Git)25 Account (com.google.gerrit.entities.Account)22 Instant (java.time.Instant)21 TestRepository (org.eclipse.jgit.junit.TestRepository)20 ArrayList (java.util.ArrayList)18 File (java.io.File)17 Date (java.util.Date)17 RefUpdate (org.eclipse.jgit.lib.RefUpdate)17