List of usage examples for org.eclipse.jgit.revplot PlotCommit getRef
public final Ref getRef(int nth)
From source file:org.eclipse.egit.ui.internal.history.command.AbstractRebaseHistoryCommandHandler.java
License:Open Source License
/** * @param commit/*from w ww . j ava2s. 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);/*from w w w. j a v a 2 s. 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 ww . j a v a2s . c om*/ } 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. j a v a2 s.co 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);/* w ww.j a v a2 s .c o m*/ } return branchesOfCommit; }