private List<Ref> getBranchesOfCommit(GitHistoryPage page, String head, boolean hideCurrentBranch) { 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 (hideCurrentBranch && head != null && refName.equals(head)) continue; if (refName.startsWith(Constants.R_HEADS) || refName.startsWith(Constants.R_REMOTES)) branchesOfCommit.add(ref); } return branchesOfCommit; }
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 { 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); } }