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);
}
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;
}
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));
}
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());
}
use of org.eclipse.jgit.lib.PersonIdent in project egit by eclipse.
the class CommitResultLabelProvider method getStyledText.
/**
* @see org.eclipse.jface.viewers.DelegatingStyledCellLabelProvider.IStyledLabelProvider#getStyledText(java.lang.Object)
*/
@Override
public StyledString getStyledText(Object element) {
StyledString styled = new StyledString();
if (element instanceof RepositoryCommit) {
RepositoryCommit commit = (RepositoryCommit) element;
RevCommit revCommit = commit.getRevCommit();
styled.append(MessageFormat.format(UIText.CommitResultLabelProvider_SectionMessage, commit.abbreviate(), revCommit.getShortMessage()));
PersonIdent author = revCommit.getAuthorIdent();
if (author != null)
styled.append(MessageFormat.format(UIText.CommitResultLabelProvider_SectionAuthor, author.getName(), dateFormatter.formatDate(author)), StyledString.QUALIFIER_STYLER);
if (layout == AbstractTextSearchViewPage.FLAG_LAYOUT_FLAT)
styled.append(MessageFormat.format(UIText.CommitResultLabelProvider_SectionRepository, commit.getRepositoryName()), StyledString.DECORATIONS_STYLER);
} else if (element instanceof RepositoryMatch) {
RepositoryMatch repository = (RepositoryMatch) element;
styled.append(repository.getLabel(repository));
// $NON-NLS-1$
styled.append(" - ", StyledString.QUALIFIER_STYLER);
styled.append(repository.getRepository().getDirectory().getAbsolutePath(), StyledString.QUALIFIER_STYLER);
styled.append(// $NON-NLS-1$
MessageFormat.format(// $NON-NLS-1$
" ({0})", Integer.valueOf(repository.getMatchCount())), StyledString.COUNTER_STYLER);
}
return styled;
}
Aggregations