Example usage for org.eclipse.jgit.revplot PlotCommit getRefCount

List of usage examples for org.eclipse.jgit.revplot PlotCommit getRefCount

Introduction

In this page you can find the example usage for org.eclipse.jgit.revplot PlotCommit getRefCount.

Prototype

public final int getRefCount() 

Source Link

Document

Get the number of refs for this commit.

Usage

From source file:org.eclipse.egit.ui.internal.history.command.AbstractRebaseHistoryCommandHandler.java

License:Open Source License

/**
 * @param commit/*from ww w  .  ja va2 s.c o  m*/
 * @param repository
 * @param currentBranch
 * @return ref pointing to the given commit, prefers tracking branch if
 *         multiple refs are available
 */
protected Ref getRef(PlotCommit commit, Repository repository, String currentBranch) {
    int count = commit.getRefCount();
    if (count == 0)
        return new ObjectIdRef.Unpeeled(Storage.LOOSE, commit.getName(), commit);
    else if (count == 1)
        return commit.getRef(0);
    else {
        BranchConfig branchConfig = new BranchConfig(repository.getConfig(), currentBranch);
        String trackingBranch = branchConfig.getTrackingBranch();
        Ref remoteRef = null;

        for (int i = 0; i < count; i++) {
            Ref ref = commit.getRef(i);
            if (trackingBranch != null && trackingBranch.equals(ref.getName()))
                return ref;
            if (ref.getName().startsWith(Constants.R_REMOTES))
                remoteRef = ref;
        }

        if (remoteRef != null)
            return remoteRef;
        else
            // We tried to pick a nice ref, just pick the first then
            return commit.getRef(0);
    }
}

From source file:org.eclipse.egit.ui.internal.history.command.DeleteBranchOnCommitHandler.java

License:Open Source License

private List<Ref> getBranchesOfCommit(GitHistoryPage page, final Repository repo, boolean hideCurrentBranch)
        throws IOException {
    final List<Ref> branchesOfCommit = new ArrayList<Ref>();
    IStructuredSelection selection = getSelection(page);
    if (selection.isEmpty())
        return branchesOfCommit;
    PlotCommit commit = (PlotCommit) selection.getFirstElement();
    String head = repo.getFullBranch();

    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);//  w  w w.  j  av a 2s.c o  m
    }
    return branchesOfCommit;
}

From source file:org.eclipse.egit.ui.internal.history.command.DeleteTagOnCommitHandler.java

License:Open Source License

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);/*from   w  w  w.  ja v  a  2s.c  o m*/
    }
    return tagsOfCommit;
}

From source file:org.eclipse.egit.ui.internal.history.command.RebaseCurrentHandler.java

License:Open Source License

private Ref getRef(PlotCommit commit, Repository repository, String currentBranch) {
    int count = commit.getRefCount();
    if (count == 0)
        return new ObjectIdRef.Unpeeled(Storage.LOOSE, commit.getName(), commit);
    else if (count == 1)
        return commit.getRef(0);
    else {//from   ww  w.  ja  va2  s  .c  o m
        BranchConfig branchConfig = new BranchConfig(repository.getConfig(), currentBranch);
        String trackingBranch = branchConfig.getTrackingBranch();
        Ref remoteRef = null;

        for (int i = 0; i < count; i++) {
            Ref ref = commit.getRef(i);
            if (trackingBranch != null && trackingBranch.equals(ref.getName()))
                return ref;
            if (ref.getName().startsWith(Constants.R_REMOTES))
                remoteRef = ref;
        }

        if (remoteRef != null)
            return remoteRef;
        else
            // We tried to pick a nice ref, just pick the first then
            return commit.getRef(0);
    }
}

From source file:org.eclipse.egit.ui.internal.history.command.RenameBranchOnCommitHandler.java

License:Open Source License

private List<Ref> getBranchesOfCommit(GitHistoryPage page) {
    final List<Ref> branchesOfCommit = new ArrayList<Ref>();
    IStructuredSelection selection = getSelection(page);
    if (selection.isEmpty())
        return branchesOfCommit;
    PlotCommit commit = (PlotCommit) selection.getFirstElement();

    int refCount = commit.getRefCount();
    for (int i = 0; i < refCount; i++) {
        Ref ref = commit.getRef(i);
        String refName = ref.getName();
        if (refName.startsWith(Constants.R_HEADS) || refName.startsWith(Constants.R_REMOTES))
            branchesOfCommit.add(ref);/*from  ww  w  .j  a  va 2 s  . com*/
    }
    return branchesOfCommit;
}