Search in sources :

Example 6 with PlotCommit

use of org.eclipse.jgit.revplot.PlotCommit in project egit by eclipse.

the class CommitGraphTable method doCopy.

private void doCopy() {
    final ISelection s = table.getSelection();
    if (s.isEmpty() || !(s instanceof IStructuredSelection))
        return;
    final IStructuredSelection iss = (IStructuredSelection) s;
    final Iterator<PlotCommit> itr = iss.iterator();
    final StringBuilder r = new StringBuilder();
    while (itr.hasNext()) {
        final PlotCommit d = itr.next();
        if (r.length() > 0)
            r.append(LINESEP);
        r.append(d.getId().name());
    }
    if (clipboard == null || clipboard.isDisposed())
        return;
    clipboard.setContents(new Object[] { r.toString() }, new Transfer[] { TextTransfer.getInstance() }, DND.CLIPBOARD);
}
Also used : PlotCommit(org.eclipse.jgit.revplot.PlotCommit) ISelection(org.eclipse.jface.viewers.ISelection) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection)

Example 7 with PlotCommit

use of org.eclipse.jgit.revplot.PlotCommit in project egit by eclipse.

the class GitPropertyTester method hasRef.

private boolean hasRef(IRepositoryCommit commit, Collection<String> names) {
    Repository repository = commit.getRepository();
    if (repository == null) {
        return false;
    }
    RevCommit revCommit = commit.getRevCommit();
    if (revCommit instanceof PlotCommit) {
        int n = ((PlotCommit) revCommit).getRefCount();
        for (int i = 0; i < n; i++) {
            Ref ref = ((PlotCommit) revCommit).getRef(i);
            for (String name : names) {
                if (ref.getName().startsWith(name)) {
                    return true;
                }
            }
        }
    } else {
        try {
            ObjectId selectedId = commit.getRevCommit().getId();
            for (String name : names) {
                for (Ref branch : repository.getRefDatabase().getRefs(name).values()) {
                    ObjectId objectId = branch.getLeaf().getObjectId();
                    if (objectId != null && objectId.equals(selectedId)) {
                        return true;
                    }
                }
            }
        } catch (IOException e) {
        // ignore here
        }
    }
    return false;
}
Also used : Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) PlotCommit(org.eclipse.jgit.revplot.PlotCommit) ObjectId(org.eclipse.jgit.lib.ObjectId) IOException(java.io.IOException) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 8 with PlotCommit

use of org.eclipse.jgit.revplot.PlotCommit in project egit by eclipse.

the class GitHistoryPage method attachCommitSelectionChanged.

private void attachCommitSelectionChanged() {
    graph.addSelectionChangedListener(new ISelectionChangedListener() {

        @Override
        public void selectionChanged(final SelectionChangedEvent event) {
            final ISelection s = event.getSelection();
            if (s.isEmpty() || !(s instanceof IStructuredSelection)) {
                commentViewer.setInput(null);
                fileViewer.setInput(null);
                return;
            }
            final IStructuredSelection sel = ((IStructuredSelection) s);
            if (sel.size() > 1) {
                commentViewer.setInput(null);
                fileViewer.setInput(null);
                return;
            }
            if (input == null) {
                return;
            }
            final PlotCommit<?> c = (PlotCommit<?>) sel.getFirstElement();
            commentViewer.setInput(c);
            final PlotWalk walk = new PlotWalk(input.getRepository());
            try {
                final RevCommit unfilteredCommit = walk.parseCommit(c);
                for (RevCommit parent : unfilteredCommit.getParents()) walk.parseBody(parent);
                fileViewer.setInput(unfilteredCommit);
            } catch (IOException e) {
                fileViewer.setInput(c);
            } finally {
                walk.dispose();
            }
            if (input.getSingleFile() != null)
                fileViewer.selectFirstInterestingElement();
        }
    });
    commentViewer.addCommitNavigationListener(new CommitNavigationListener() {

        @Override
        public void showCommit(final RevCommit c) {
            graph.selectCommit(c);
        }
    });
}
Also used : PlotCommit(org.eclipse.jgit.revplot.PlotCommit) ISelectionChangedListener(org.eclipse.jface.viewers.ISelectionChangedListener) ISelection(org.eclipse.jface.viewers.ISelection) SelectionChangedEvent(org.eclipse.jface.viewers.SelectionChangedEvent) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) IOException(java.io.IOException) PlotWalk(org.eclipse.jgit.revplot.PlotWalk) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 9 with PlotCommit

use of org.eclipse.jgit.revplot.PlotCommit in project egit by eclipse.

the class DeleteTagOnCommitHandler method getTagsOfCommit.

private List<Ref> getTagsOfCommit(IStructuredSelection selection) {
    final List<Ref> tagsOfCommit = new ArrayList<>();
    if (selection.isEmpty())
        return tagsOfCommit;
    PlotCommit commit = (PlotCommit) selection.getFirstElement();
    for (int i = 0; i < commit.getRefCount(); i++) {
        Ref ref = commit.getRef(i);
        if (ref.getName().startsWith(Constants.R_TAGS))
            tagsOfCommit.add(ref);
    }
    return tagsOfCommit;
}
Also used : Ref(org.eclipse.jgit.lib.Ref) PlotCommit(org.eclipse.jgit.revplot.PlotCommit) ArrayList(java.util.ArrayList)

Example 10 with PlotCommit

use of org.eclipse.jgit.revplot.PlotCommit in project egit by eclipse.

the class PushCommitHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    PlotCommit commit = (PlotCommit) getSelection(event).getFirstElement();
    final Repository repo = getRepository(event);
    try {
        PushBranchWizard wizard = null;
        Ref localBranch = null;
        for (int i = 0; i < commit.getRefCount(); i++) {
            Ref currentRef = commit.getRef(i);
            if (localBranch == null && currentRef.getName().startsWith(Constants.R_HEADS))
                localBranch = currentRef;
        }
        if (localBranch == null)
            wizard = new PushBranchWizard(repo, commit.getId());
        else
            wizard = new PushBranchWizard(repo, localBranch);
        PushWizardDialog dlg = new PushWizardDialog(HandlerUtil.getActiveShellChecked(event), wizard);
        dlg.setHelpAvailable(true);
        dlg.open();
    } catch (Exception e) {
        Activator.handleError(e.getMessage(), e, true);
    }
    return null;
}
Also used : Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) PlotCommit(org.eclipse.jgit.revplot.PlotCommit) PushWizardDialog(org.eclipse.egit.ui.internal.push.PushWizardDialog) PushBranchWizard(org.eclipse.egit.ui.internal.push.PushBranchWizard) ExecutionException(org.eclipse.core.commands.ExecutionException)

Aggregations

PlotCommit (org.eclipse.jgit.revplot.PlotCommit)10 Ref (org.eclipse.jgit.lib.Ref)7 RevCommit (org.eclipse.jgit.revwalk.RevCommit)6 Repository (org.eclipse.jgit.lib.Repository)5 IStructuredSelection (org.eclipse.jface.viewers.IStructuredSelection)4 IOException (java.io.IOException)3 ISelection (org.eclipse.jface.viewers.ISelection)3 ArrayList (java.util.ArrayList)2 ExecutionException (org.eclipse.core.commands.ExecutionException)2 ObjectId (org.eclipse.jgit.lib.ObjectId)2 GitFlowRepository (org.eclipse.egit.gitflow.GitFlowRepository)1 WrongGitFlowStateException (org.eclipse.egit.gitflow.WrongGitFlowStateException)1 AbstractRebaseCommandHandler (org.eclipse.egit.ui.internal.commands.shared.AbstractRebaseCommandHandler)1 PushBranchWizard (org.eclipse.egit.ui.internal.push.PushBranchWizard)1 PushWizardDialog (org.eclipse.egit.ui.internal.push.PushWizardDialog)1 CreateBranchWizard (org.eclipse.egit.ui.internal.repository.CreateBranchWizard)1 ISelectionChangedListener (org.eclipse.jface.viewers.ISelectionChangedListener)1 SelectionChangedEvent (org.eclipse.jface.viewers.SelectionChangedEvent)1 IWizard (org.eclipse.jface.wizard.IWizard)1 WizardDialog (org.eclipse.jface.wizard.WizardDialog)1