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;
}
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;
}
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;
}
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;
}
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();
}
}
Aggregations