Search in sources :

Example 96 with PersonIdent

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

the class CommitEditorPage method createUserArea.

private Composite createUserArea(Composite parent, FormToolkit toolkit, PersonIdent person, boolean author) {
    Composite userArea = toolkit.createComposite(parent);
    GridLayoutFactory.fillDefaults().spacing(2, 2).numColumns(3).applyTo(userArea);
    Label userLabel = toolkit.createLabel(userArea, null);
    userLabel.setImage(getImage(author ? UIIcons.ELCL16_AUTHOR : UIIcons.ELCL16_COMMITTER));
    if (author)
        userLabel.setToolTipText(UIText.CommitEditorPage_TooltipAuthor);
    else
        userLabel.setToolTipText(UIText.CommitEditorPage_TooltipCommitter);
    boolean signedOff = isSignedOffBy(person);
    final Text userText = new Text(userArea, SWT.FLAT | SWT.READ_ONLY);
    addToFocusTracking(userText);
    setPerson(userText, person, author);
    toolkit.adapt(userText, false, false);
    userText.setData(FormToolkit.KEY_DRAW_BORDER, Boolean.FALSE);
    IPropertyChangeListener uiPrefsListener = (event) -> {
        String property = event.getProperty();
        if (UIPreferences.DATE_FORMAT.equals(property) || UIPreferences.DATE_FORMAT_CHOICE.equals(property)) {
            setPerson(userText, person, author);
            userArea.layout();
        }
    };
    Activator.getDefault().getPreferenceStore().addPropertyChangeListener(uiPrefsListener);
    userText.addDisposeListener((e) -> {
        Activator.getDefault().getPreferenceStore().removePropertyChangeListener(uiPrefsListener);
    });
    GridDataFactory.fillDefaults().span(signedOff ? 1 : 2, 1).applyTo(userText);
    if (signedOff) {
        Label signedOffLabel = toolkit.createLabel(userArea, null);
        signedOffLabel.setImage(getImage(UIIcons.SIGNED_OFF));
        if (author)
            signedOffLabel.setToolTipText(UIText.CommitEditorPage_TooltipSignedOffByAuthor);
        else
            signedOffLabel.setToolTipText(UIText.CommitEditorPage_TooltipSignedOffByCommitter);
    }
    return userArea;
}
Also used : IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) AdapterUtils(org.eclipse.egit.core.AdapterUtils) CLabel(org.eclipse.swt.custom.CLabel) DisposeEvent(org.eclipse.swt.events.DisposeEvent) TableViewer(org.eclipse.jface.viewers.TableViewer) UIPreferences(org.eclipse.egit.ui.UIPreferences) StyledText(org.eclipse.swt.custom.StyledText) FileDiff(org.eclipse.egit.ui.internal.history.FileDiff) DisposeListener(org.eclipse.swt.events.DisposeListener) Hyperlink(org.eclipse.ui.forms.widgets.Hyperlink) HyperlinkEvent(org.eclipse.ui.forms.events.HyperlinkEvent) Point(org.eclipse.swt.graphics.Point) RevWalk(org.eclipse.jgit.revwalk.RevWalk) IStatus(org.eclipse.core.runtime.IStatus) Composite(org.eclipse.swt.widgets.Composite) PartInitException(org.eclipse.ui.PartInitException) Map(java.util.Map) PreferenceBasedDateFormatter(org.eclipse.egit.ui.internal.PreferenceBasedDateFormatter) ViewerComparator(org.eclipse.jface.viewers.ViewerComparator) IAdaptable(org.eclipse.core.runtime.IAdaptable) ISchedulingRule(org.eclipse.core.runtime.jobs.ISchedulingRule) Text(org.eclipse.swt.widgets.Text) PlatformUI(org.eclipse.ui.PlatformUI) GitLabelProvider(org.eclipse.egit.ui.internal.GitLabelProvider) FormEditor(org.eclipse.ui.forms.editor.FormEditor) Status(org.eclipse.core.runtime.Status) Constants(org.eclipse.jgit.lib.Constants) GitDateFormatter(org.eclipse.jgit.util.GitDateFormatter) ArrayContentProvider(org.eclipse.jface.viewers.ArrayContentProvider) RevWalkUtils(org.eclipse.jgit.revwalk.RevWalkUtils) IManagedForm(org.eclipse.ui.forms.IManagedForm) GridLayoutFactory(org.eclipse.jface.layout.GridLayoutFactory) IProgressMonitor(org.eclipse.core.runtime.IProgressMonitor) PersonIdent(org.eclipse.jgit.lib.PersonIdent) CommitFileDiffViewer(org.eclipse.egit.ui.internal.history.CommitFileDiffViewer) List(java.util.List) ExpansionAdapter(org.eclipse.ui.forms.events.ExpansionAdapter) UIText(org.eclipse.egit.ui.internal.UIText) IFormColors(org.eclipse.ui.forms.IFormColors) Ref(org.eclipse.jgit.lib.Ref) SWT(org.eclipse.swt.SWT) UIIcons(org.eclipse.egit.ui.internal.UIIcons) Label(org.eclipse.swt.widgets.Label) FormPage(org.eclipse.ui.forms.editor.FormPage) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) RevCommit(org.eclipse.jgit.revwalk.RevCommit) Activator(org.eclipse.egit.ui.Activator) Image(org.eclipse.swt.graphics.Image) HashMap(java.util.HashMap) JFaceResources(org.eclipse.jface.resource.JFaceResources) PlatformObject(org.eclipse.core.runtime.PlatformObject) MessageFormat(java.text.MessageFormat) ArrayList(java.util.ArrayList) ExpansionEvent(org.eclipse.ui.forms.events.ExpansionEvent) IShowInSource(org.eclipse.ui.part.IShowInSource) ShowInContext(org.eclipse.ui.part.ShowInContext) IPropertyChangeListener(org.eclipse.jface.util.IPropertyChangeListener) GridData(org.eclipse.swt.layout.GridData) FillLayout(org.eclipse.swt.layout.FillLayout) Section(org.eclipse.ui.forms.widgets.Section) SpellcheckableMessageArea(org.eclipse.egit.ui.internal.dialogs.SpellcheckableMessageArea) Job(org.eclipse.core.runtime.jobs.Job) GridDataFactory(org.eclipse.jface.layout.GridDataFactory) FormToolkit(org.eclipse.ui.forms.widgets.FormToolkit) IOException(java.io.IOException) ImageDescriptor(org.eclipse.jface.resource.ImageDescriptor) ObjectId(org.eclipse.jgit.lib.ObjectId) AbstractHyperlink(org.eclipse.ui.forms.widgets.AbstractHyperlink) ScrolledForm(org.eclipse.ui.forms.widgets.ScrolledForm) UIUtils(org.eclipse.egit.ui.UIUtils) NonNull(org.eclipse.jgit.annotations.NonNull) Platform(org.eclipse.core.runtime.Platform) LocalResourceManager(org.eclipse.jface.resource.LocalResourceManager) Comparator(java.util.Comparator) HyperlinkAdapter(org.eclipse.ui.forms.events.HyperlinkAdapter) Collections(java.util.Collections) Repository(org.eclipse.jgit.lib.Repository) Control(org.eclipse.swt.widgets.Control) Composite(org.eclipse.swt.widgets.Composite) ExpandableComposite(org.eclipse.ui.forms.widgets.ExpandableComposite) CLabel(org.eclipse.swt.custom.CLabel) Label(org.eclipse.swt.widgets.Label) StyledText(org.eclipse.swt.custom.StyledText) Text(org.eclipse.swt.widgets.Text) UIText(org.eclipse.egit.ui.internal.UIText)

Example 97 with PersonIdent

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

the class CommitHelper method getHeadCommitInfo.

/**
 * @param repository
 * @return info related to the HEAD commit
 */
public static CommitInfo getHeadCommitInfo(Repository repository) {
    RevCommit headCommit = getHeadCommit(repository);
    if (headCommit == null)
        return null;
    String commitMessage = headCommit.getFullMessage().replaceAll("\n", // $NON-NLS-1$
    Text.DELIMITER);
    PersonIdent authorIdent = headCommit.getAuthorIdent();
    String author = authorIdent.getName() + " <" + authorIdent.getEmailAddress() + // $NON-NLS-1$ //$NON-NLS-2$
    ">";
    PersonIdent committerIdent = headCommit.getCommitterIdent();
    String committer = committerIdent.getName() + " <" + committerIdent.getEmailAddress() + // $NON-NLS-1$ //$NON-NLS-2$
    ">";
    return new CommitInfo(headCommit, author, committer, commitMessage);
}
Also used : PersonIdent(org.eclipse.jgit.lib.PersonIdent) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 98 with PersonIdent

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

the class BlameInformationControl method setInput.

@Override
public void setInput(Object input) {
    if (input == null) {
        // Make sure we don't hold a reference to this when nothing is
        // shown, it can be big
        this.revision = null;
        if (showAnnotationsLink != null) {
            // parent...)
            if (!showAnnotationsLink.isDisposed())
                showAnnotationsLink.removeSelectionListener(showAnnotationsLinkSelectionAdapter);
            showAnnotationsLink = null;
            showAnnotationsLinkSelectionAdapter = null;
        }
        return;
    }
    this.revision = (BlameRevision) input;
    // Used for showing the diff hunk of this line instead of the full diff.
    if (rulerInfo != null)
        revisionRulerLineNumber = rulerInfo.getLineOfLastMouseButtonActivity();
    RevCommit commit = this.revision.getCommit();
    String linkText = MessageFormat.format(UIText.BlameInformationControl_Commit, commit.abbreviate(7).name());
    commitLabel.setText(linkText);
    PreferenceBasedDateFormatter dateFormatter = PreferenceBasedDateFormatter.create();
    PersonIdent author = commit.getAuthorIdent();
    if (author != null) {
        setControlVisible(authorLabel, true);
        authorLabel.setText(MessageFormat.format(UIText.BlameInformationControl_Author, author.getName(), author.getEmailAddress(), dateFormatter.formatDate(author)));
    } 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(), dateFormatter.formatDate(committer)));
    } else
        setControlVisible(committerLabel, false);
    messageText.setText(commit.getFullMessage());
    createDiffs();
    displayArea.layout();
    scrolls.setMinSize(displayArea.computeSize(SWT.DEFAULT, SWT.DEFAULT));
}
Also used : PersonIdent(org.eclipse.jgit.lib.PersonIdent) PreferenceBasedDateFormatter(org.eclipse.egit.ui.internal.PreferenceBasedDateFormatter) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 99 with PersonIdent

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

the class RepositoryCommit method getStyledText.

/**
 * @param object
 * @return styled text
 */
@Override
public StyledString getStyledText(Object object) {
    StyledString styled = new StyledString();
    styled.append(abbreviate());
    // $NON-NLS-1$
    styled.append(": ");
    styled.append(commit.getShortMessage());
    PersonIdent author = commit.getAuthorIdent();
    PersonIdent committer = commit.getCommitterIdent();
    if (author != null && committer != null) {
        PreferenceBasedDateFormatter formatter = PreferenceBasedDateFormatter.create();
        if (author.getName().equals(committer.getName())) {
            styled.append(MessageFormat.format(UIText.RepositoryCommit_AuthorDate, author.getName(), formatter.formatDate(author)), StyledString.QUALIFIER_STYLER);
        } else {
            styled.append(MessageFormat.format(UIText.RepositoryCommit_AuthorDateCommitter, author.getName(), formatter.formatDate(author), committer.getName()), StyledString.QUALIFIER_STYLER);
        }
    }
    return styled;
}
Also used : PersonIdent(org.eclipse.jgit.lib.PersonIdent) StyledString(org.eclipse.jface.viewers.StyledString) PreferenceBasedDateFormatter(org.eclipse.egit.ui.internal.PreferenceBasedDateFormatter)

Example 100 with PersonIdent

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

the class CreateTagHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    List<RepositoryCommit> commits = getCommits(event);
    if (commits.size() == 1) {
        RepositoryCommit commit = commits.get(0);
        Repository repository = commit.getRepository();
        CreateTagDialog dialog = new CreateTagDialog(HandlerUtil.getActiveShellChecked(event), commit.getRevCommit().getId(), repository);
        if (dialog.open() != Window.OK)
            return null;
        final TagBuilder tag = new TagBuilder();
        PersonIdent personIdent = new PersonIdent(repository);
        String tagName = dialog.getTagName();
        tag.setTag(tagName);
        tag.setTagger(personIdent);
        tag.setMessage(dialog.getTagMessage());
        tag.setObjectId(commit.getRevCommit());
        try {
            new TagOperation(repository, tag, dialog.shouldOverWriteTag()).execute(new NullProgressMonitor());
        } catch (CoreException e) {
            throw new ExecutionException(e.getMessage(), e);
        }
        if (dialog.shouldStartPushWizard())
            PushTagsWizard.openWizardDialog(repository, tagName);
    }
    return null;
}
Also used : NullProgressMonitor(org.eclipse.core.runtime.NullProgressMonitor) Repository(org.eclipse.jgit.lib.Repository) CoreException(org.eclipse.core.runtime.CoreException) CreateTagDialog(org.eclipse.egit.ui.internal.dialogs.CreateTagDialog) PersonIdent(org.eclipse.jgit.lib.PersonIdent) TagOperation(org.eclipse.egit.core.op.TagOperation) ExecutionException(org.eclipse.core.commands.ExecutionException) RepositoryCommit(org.eclipse.egit.ui.internal.commit.RepositoryCommit) TagBuilder(org.eclipse.jgit.lib.TagBuilder)

Aggregations

PersonIdent (org.eclipse.jgit.lib.PersonIdent)253 RevCommit (org.eclipse.jgit.revwalk.RevCommit)96 Repository (org.eclipse.jgit.lib.Repository)63 Test (org.junit.Test)63 ObjectId (org.eclipse.jgit.lib.ObjectId)60 IOException (java.io.IOException)46 Git (org.eclipse.jgit.api.Git)41 CommitBuilder (org.eclipse.jgit.lib.CommitBuilder)41 RevWalk (org.eclipse.jgit.revwalk.RevWalk)40 ObjectInserter (org.eclipse.jgit.lib.ObjectInserter)31 Change (com.google.gerrit.entities.Change)28 Ref (org.eclipse.jgit.lib.Ref)27 GerritPersonIdent (com.google.gerrit.server.GerritPersonIdent)26 GitAPIException (org.eclipse.jgit.api.errors.GitAPIException)25 Account (com.google.gerrit.entities.Account)22 Instant (java.time.Instant)22 TestRepository (org.eclipse.jgit.junit.TestRepository)20 ArrayList (java.util.ArrayList)19 Date (java.util.Date)18 File (java.io.File)17