Search in sources :

Example 1 with PlotCommit

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

the class AbstractHistoryCommandHandler method getBranchesOfCommit.

private List<Ref> getBranchesOfCommit(IStructuredSelection selection, String head, boolean hideCurrentBranch) {
    final List<Ref> branchesOfCommit = new ArrayList<>();
    if (selection.isEmpty()) {
        return branchesOfCommit;
    }
    RevCommit revCommit = AdapterUtils.adapt(selection.getFirstElement(), RevCommit.class);
    if (!(revCommit instanceof PlotCommit)) {
        return branchesOfCommit;
    }
    PlotCommit commit = (PlotCommit) revCommit;
    int refCount = commit.getRefCount();
    for (int i = 0; i < refCount; i++) {
        Ref ref = commit.getRef(i);
        String refName = ref.getName();
        if (hideCurrentBranch && head != null && refName.equals(head))
            continue;
        if (refName.startsWith(Constants.R_HEADS) || refName.startsWith(Constants.R_REMOTES))
            branchesOfCommit.add(ref);
    }
    return branchesOfCommit;
}
Also used : Ref(org.eclipse.jgit.lib.Ref) PlotCommit(org.eclipse.jgit.revplot.PlotCommit) ArrayList(java.util.ArrayList) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 2 with PlotCommit

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

the class AbstractRebaseHistoryCommandHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    RevCommit revCommit = AdapterUtils.adapt(getSelection(event).getFirstElement(), RevCommit.class);
    if (!(revCommit instanceof PlotCommit)) {
        return null;
    }
    PlotCommit commit = (PlotCommit) revCommit;
    final Repository repository = getRepository(event);
    if (repository == null)
        return null;
    String currentBranch = getCurrentBranch(repository);
    final Ref ref = getRef(commit, repository, currentBranch);
    String jobname = NLS.bind(UIText.RebaseCurrentRefCommand_RebasingCurrentJobName, currentBranch, ref.getName());
    AbstractRebaseCommandHandler rebaseCurrentRef = new AbstractRebaseCommandHandler(jobname, UIText.RebaseCurrentRefCommand_RebaseCanceledMessage) {

        @Override
        protected RebaseOperation createRebaseOperation(Repository repository2) throws ExecutionException {
            return AbstractRebaseHistoryCommandHandler.this.createRebaseOperation(repository2, ref);
        }
    };
    rebaseCurrentRef.execute(repository);
    return null;
}
Also used : Repository(org.eclipse.jgit.lib.Repository) ObjectIdRef(org.eclipse.jgit.lib.ObjectIdRef) Ref(org.eclipse.jgit.lib.Ref) PlotCommit(org.eclipse.jgit.revplot.PlotCommit) AbstractRebaseCommandHandler(org.eclipse.egit.ui.internal.commands.shared.AbstractRebaseCommandHandler) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

Example 3 with PlotCommit

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

the class CreateBranchOnCommitHandler method execute.

@Override
public Object execute(ExecutionEvent event) throws ExecutionException {
    Repository repo = getRepository(event);
    IStructuredSelection selection = getSelection(event);
    IWizard wiz = null;
    List<Ref> branches = getBranches(selection, repo);
    if (branches.isEmpty()) {
        PlotCommit commit = (PlotCommit) selection.getFirstElement();
        wiz = new CreateBranchWizard(repo, commit.name());
    } else {
        // prefer to create new branch based on a remote tracking branch
        Collections.sort(branches, new Comparator<Ref>() {

            @Override
            public int compare(Ref o1, Ref o2) {
                String refName1 = o1.getName();
                String refName2 = o2.getName();
                if (refName1.startsWith(Constants.R_REMOTES)) {
                    if (refName2.startsWith(Constants.R_HEADS))
                        return -1;
                    else
                        return refName1.compareTo(refName2);
                } else {
                    if (refName2.startsWith(Constants.R_REMOTES))
                        return 1;
                    else
                        return refName1.compareTo(refName2);
                }
            }
        });
        Ref branch = branches.get(0).getLeaf();
        wiz = new CreateBranchWizard(repo, branch.getName());
    }
    WizardDialog dlg = new WizardDialog(HandlerUtil.getActiveShellChecked(event), wiz);
    dlg.setHelpAvailable(false);
    dlg.open();
    return null;
}
Also used : Repository(org.eclipse.jgit.lib.Repository) Ref(org.eclipse.jgit.lib.Ref) PlotCommit(org.eclipse.jgit.revplot.PlotCommit) IWizard(org.eclipse.jface.wizard.IWizard) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) WizardDialog(org.eclipse.jface.wizard.WizardDialog) CreateBranchWizard(org.eclipse.egit.ui.internal.repository.CreateBranchWizard)

Example 4 with PlotCommit

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

the class GitPropertyTester method hasMultipleRefs.

private boolean hasMultipleRefs(IRepositoryCommit commit, Collection<String> names) {
    Repository repository = commit.getRepository();
    if (repository == null) {
        return false;
    }
    int count = 0;
    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)) {
                    if (++count > 1) {
                        break;
                    }
                }
            }
            if (count > 1) {
                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)) {
                        if (++count > 1) {
                            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 5 with PlotCommit

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

the class ReleaseStartHandler method getStartCommit.

private String getStartCommit(ExecutionEvent event) throws ExecutionException {
    ISelection currentSelection = HandlerUtil.getCurrentSelection(event);
    IStructuredSelection selection = SelectionUtils.getStructuredSelection(currentSelection);
    if (selection.getFirstElement() instanceof PlotCommit) {
        RevCommit plotCommit = (RevCommit) selection.getFirstElement();
        return plotCommit.getName();
    } else {
        GitFlowRepository gitFlowRepository = GitFlowHandlerUtil.getRepository(event);
        if (gitFlowRepository == null) {
            throw new ExecutionException(UIText.ReleaseStartHandler_startCommitCouldNotBeDetermined);
        }
        RevCommit head;
        try {
            head = gitFlowRepository.findHead();
        } catch (WrongGitFlowStateException e) {
            throw new ExecutionException(e.getMessage(), e);
        }
        return head.getName();
    }
}
Also used : PlotCommit(org.eclipse.jgit.revplot.PlotCommit) ISelection(org.eclipse.jface.viewers.ISelection) WrongGitFlowStateException(org.eclipse.egit.gitflow.WrongGitFlowStateException) IStructuredSelection(org.eclipse.jface.viewers.IStructuredSelection) ExecutionException(org.eclipse.core.commands.ExecutionException) GitFlowRepository(org.eclipse.egit.gitflow.GitFlowRepository) RevCommit(org.eclipse.jgit.revwalk.RevCommit)

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