[vcs-log] check that selected commits are not already being processed

This commit is contained in:
Julia Beliaeva
2016-01-14 19:25:57 +03:00
parent da6ec1194b
commit 684cd8334d
2 changed files with 24 additions and 6 deletions
@@ -64,6 +64,7 @@ public class VcsCherryPickAction extends DumbAwareAction {
final VcsLog log = e.getData(VcsLogDataKeys.VCS_LOG);
Project project = e.getProject();
assert project != null;
VcsCherryPickManager cherryPickManager = VcsCherryPickManager.getInstance(project);
List<VcsCherryPicker> cherryPickers = getActiveCherryPickersForProject(project);
if (log == null || cherryPickers.isEmpty()) {
@@ -72,7 +73,7 @@ public class VcsCherryPickAction extends DumbAwareAction {
}
List<CommitId> commits = VcsLogUtil.collectFirstPack(log.getSelectedCommits(), VcsLogUtil.MAX_SELECTED_COMMITS);
if (commits.isEmpty()) {
if (commits.isEmpty() || cherryPickManager.isCherryPickAlreadyStartedFor(commits)) {
e.getPresentation().setEnabled(false);
return;
}
@@ -60,6 +60,15 @@ public class VcsCherryPickManager {
}, null);
}
public boolean isCherryPickAlreadyStartedFor(@NotNull List<CommitId> commits) {
for (CommitId commit : commits) {
if (myIdsInProgress.contains(commit)) {
return true;
}
}
return false;
}
@Nullable
private VcsCherryPicker getCherryPickerForCommit(@NotNull VcsFullCommitDetails commitDetails) {
AbstractVcs vcs = myProjectLevelVcsManager.getVcsFor(commitDetails.getRoot());
@@ -91,14 +100,17 @@ public class VcsCherryPickManager {
}
public boolean processDetails(@NotNull VcsFullCommitDetails details) {
myIdsInProgress.add(new CommitId(details.getId(), details.getRoot()));
CommitId commitId = new CommitId(details.getId(), details.getRoot());
if (myIdsInProgress.contains(commitId)) {
showError("Cherry pick process is already started for commit " + commitId.getHash().toShortString() + " from root " + commitId.getRoot().getName());
return false;
}
myIdsInProgress.add(commitId);
VcsCherryPicker cherryPicker = getCherryPickerForCommit(details);
if (cherryPicker == null) {
String message =
"Cherry pick is not supported for commit " + details.getId().toShortString() + " from root " + details.getRoot().getName();
VcsNotifier.getInstance(myProject).notifyWeakError(message);
LOG.warn(message);
showError(
"Cherry pick is not supported for commit " + details.getId().toShortString() + " from root " + details.getRoot().getName());
return false;
}
List<VcsFullCommitDetails> list = myGroupedCommits.get(cherryPicker);
@@ -109,6 +121,11 @@ public class VcsCherryPickManager {
return true;
}
public void showError(@NotNull String message) {
VcsNotifier.getInstance(myProject).notifyWeakError(message);
LOG.warn(message);
}
@Override
public void run(@NotNull ProgressIndicator indicator) {
try {