[vcs] Disable "Revert" action in the RepositoryChangesBrowser for some cases. IDEA-55533, IDEA-55673, IDEA-56407

Let CommittedChangeList hold the flag "modifiable": if the flag is disabled, "revert" action is disabled (and theoretically, some other actions).
Set the flag to false for all Git changelists, except for the ones created from the file history and folder diff.
This commit is contained in:
Kirill Likhodedov
2012-08-02 18:15:26 +04:00
parent 1df16ac527
commit e14552f585
13 changed files with 66 additions and 23 deletions
@@ -40,4 +40,9 @@ public interface CommittedChangeList extends ChangeList {
AbstractVcs getVcs();
Collection<Change> getChangesWithMovedTrees();
/**
* @return true if this change list can be modified, for example, by reverting some of the changes.
*/
boolean isModifiable();
}
@@ -68,6 +68,11 @@ public class CommittedChangeListImpl implements CommittedChangeList {
return getChangesWithMovedTreesImpl(this);
}
@Override
public boolean isModifiable() {
return true;
}
public static Collection<Change> getChangesWithMovedTreesImpl(final CommittedChangeList list) {
return list.getChanges();
}
@@ -21,6 +21,8 @@ import com.intellij.openapi.actionSystem.Presentation;
import com.intellij.openapi.vcs.VcsBundle;
import com.intellij.openapi.vcs.VcsDataKeys;
import com.intellij.openapi.vcs.changes.Change;
import com.intellij.openapi.vcs.changes.ChangeList;
import com.intellij.openapi.vcs.versionBrowser.CommittedChangeList;
import com.intellij.util.containers.Convertor;
import javax.swing.*;
@@ -36,6 +38,22 @@ public class RevertSelectedChangesAction extends RevertCommittedStuffAbstractAct
presentation.setIcon(ourIcon);
presentation.setText(ourText);
super.update(e);
presentation.setEnabled(allSelectedChangeListsAreRevertable(e));
}
private static boolean allSelectedChangeListsAreRevertable(AnActionEvent e) {
ChangeList[] changeLists = e.getData(VcsDataKeys.CHANGE_LISTS);
if (changeLists == null) {
return true;
}
for (ChangeList list : changeLists) {
if (list instanceof CommittedChangeList) {
if (!((CommittedChangeList)list).isModifiable()) {
return false;
}
}
}
return true;
}
private static void initPresentation() {
@@ -120,6 +120,11 @@ public class CvsChangeList implements CommittedChangeList {
return CommittedChangeListImpl.getChangesWithMovedTreesImpl(this);
}
@Override
public boolean isModifiable() {
return true;
}
@Nullable
public String getBranch() {
if (myRevisions.size() > 0) {
+2 -2
View File
@@ -522,7 +522,7 @@ public class GitUtil {
if ((!firstStep) && lineIsAStart) {
final StringScanner innerScanner = new StringScanner(sb.toString());
sb.setLength(0);
consumer.consume(GitChangeUtils.parseChangeList(project, root, innerScanner, skipDiffsForMerge, h, false));
consumer.consume(GitChangeUtils.parseChangeList(project, root, innerScanner, skipDiffsForMerge, h, false, false));
}
sb.append(lineIsAStart ? line.substring(2) : line).append('\n');
firstStep = false;
@@ -530,7 +530,7 @@ public class GitUtil {
if (sb.length() > 0) {
final StringScanner innerScanner = new StringScanner(sb.toString());
sb.setLength(0);
consumer.consume(GitChangeUtils.parseChangeList(project, root, innerScanner, skipDiffsForMerge, h, false));
consumer.consume(GitChangeUtils.parseChangeList(project, root, innerScanner, skipDiffsForMerge, h, false, false));
}
if (s.hasMoreData()) {
throw new IllegalStateException("More input is avaialble: " + s.line());
@@ -86,7 +86,7 @@ public class GitShowAllSubmittedFilesAction extends AnAction implements DumbAwar
* @param file file affected by the revision
*/
public static void showSubmittedFiles(final Project project, final VcsFileRevision revision, final VirtualFile file) {
showSubmittedFiles(project, revision.getRevisionNumber().asString(), file, false);
showSubmittedFiles(project, revision.getRevisionNumber().asString(), file, false, true);
}
/**
@@ -96,14 +96,16 @@ public class GitShowAllSubmittedFilesAction extends AnAction implements DumbAwar
* @param revision a revision number
* @param file file affected by the revision
* @param local
* @param revertable
*/
public static void showSubmittedFiles(final Project project, final String revision, final VirtualFile file, final boolean local) {
public static void showSubmittedFiles(final Project project, final String revision, final VirtualFile file,
final boolean local, final boolean revertable) {
new Task.Backgroundable(project, GitBundle.message("changes.retrieving", revision)) {
public void run(@NotNull ProgressIndicator indicator) {
indicator.setIndeterminate(true);
try {
VirtualFile vcsRoot = GitUtil.getGitRoot(file);
final CommittedChangeList changeList = GitChangeUtils.getRevisionChanges(project, vcsRoot, revision, true, local);
final CommittedChangeList changeList = GitChangeUtils.getRevisionChanges(project, vcsRoot, revision, true, local, revertable);
if (changeList != null) {
UIUtil.invokeLaterIfNeeded(new Runnable() {
public void run() {
@@ -231,11 +231,13 @@ public class GitChangeUtils {
* listed on the the merge that has at least some changes.
*
*
*
* @param project the project file
* @param root the git root
* @param revisionName the name of revision (might be tag)
* @param skipDiffsForMerge
* @param local
* @param revertable
* @return change list for the respective revision
* @throws VcsException in case of problem with running git
*/
@@ -243,7 +245,7 @@ public class GitChangeUtils {
VirtualFile root,
String revisionName,
boolean skipDiffsForMerge,
boolean local) throws VcsException {
boolean local, boolean revertable) throws VcsException {
GitSimpleHandler h = new GitSimpleHandler(project, root, GitCommand.SHOW);
h.setNoSSH(true);
h.setSilent(true);
@@ -251,7 +253,7 @@ public class GitChangeUtils {
revisionName, "--");
String output = h.run();
StringScanner s = new StringScanner(output);
return parseChangeList(project, root, s, skipDiffsForMerge, h, local);
return parseChangeList(project, root, s, skipDiffsForMerge, h, local, revertable);
}
@Nullable
@@ -335,6 +337,7 @@ public class GitChangeUtils {
* Parse changelist
*
*
*
* @param project the project
* @param root the git root
* @param s the scanner for log or show command output
@@ -343,6 +346,7 @@ public class GitChangeUtils {
* @param local pass {@code true} to indicate that this revision should be an editable
* {@link com.intellij.openapi.vcs.changes.CurrentContentRevision}.
* Pass {@code false} for
* @param revertable
* @return the parsed changelist
* @throws VcsException if there is a problem with running git
*/
@@ -351,7 +355,7 @@ public class GitChangeUtils {
StringScanner s,
boolean skipDiffsForMerge,
GitHandler handler,
boolean local) throws VcsException {
boolean local, boolean revertable) throws VcsException {
ArrayList<Change> changes = new ArrayList<Change>();
// parse commit information
final Date commitDate = GitUtil.parseTimestampWithNFEReport(s.line(), handler, s.getAllText());
@@ -403,8 +407,8 @@ public class GitChangeUtils {
}
}
}
return new GitCommittedChangeList(commentSubject + "(" + revisionNumber + ")", fullComment, committerName, number, commitDate,
changes, revisionNumber);
String changeListName = String.format("%s(%s)", commentSubject, revisionNumber);
return new GitCommittedChangeList(changeListName, fullComment, committerName, number, commitDate, changes, revertable);
}
public static long longForSHAHash(String revisionNumber) {
@@ -27,18 +27,17 @@ import java.util.Date;
* Time: 4:03 PM
*/
public class GitCommittedChangeList extends CommittedChangeListImpl {
private final String myFullHash;
public GitCommittedChangeList(String name,
String comment,
String committerName,
long number,
Date commitDate, Collection<Change> changes, String fullHash) {
private final boolean myModifiable;
public GitCommittedChangeList(String name, String comment, String committerName, long number, Date commitDate, Collection<Change> changes,
boolean isModifiable) {
super(name, comment, committerName, number, commitDate, changes);
myFullHash = fullHash;
myModifiable = isModifiable;
}
public String getFullHash() {
return myFullHash;
@Override
public boolean isModifiable() {
return myModifiable;
}
}
@@ -159,7 +159,7 @@ public class GitDiffFromHistoryHandler implements DiffFromHistoryHandler {
else {
// show the initial commit
myChanges = new ArrayList<Change>(GitChangeUtils.getRevisionChanges(repository.getProject(), repository.getRoot(), hash2, false,
true).getChanges());
true, true).getChanges());
}
}
catch (VcsException e) {
@@ -133,7 +133,7 @@ public class GitRebaseEditor extends DialogWrapper {
return;
}
GitRebaseEntry entry = myTableModel.myEntries.get(row);
GitShowAllSubmittedFilesAction.showSubmittedFiles(project, entry.getCommit(), gitRoot, false);
GitShowAllSubmittedFilesAction.showSubmittedFiles(project, entry.getCommit(), gitRoot, false, false);
}
});
@@ -94,7 +94,7 @@ public class GitReferenceValidator {
myLastResult = false;
try {
GitRevisionNumber revision = GitRevisionNumber.resolve(myProject, gitRoot(), revisionExpression);
GitShowAllSubmittedFilesAction.showSubmittedFiles(myProject, revision.asString(), gitRoot(), false);
GitShowAllSubmittedFilesAction.showSubmittedFiles(myProject, revision.asString(), gitRoot(), false, false);
myLastResult = true;
}
catch (VcsException ex) {
@@ -224,7 +224,7 @@ public class GitUnstashDialog extends DialogWrapper {
GitUIUtil.showOperationError(myProject, ex, "resolving revision");
return;
}
GitShowAllSubmittedFilesAction.showSubmittedFiles(myProject, resolvedStash, root, true);
GitShowAllSubmittedFilesAction.showSubmittedFiles(myProject, resolvedStash, root, true, false);
}
});
init();
@@ -594,6 +594,11 @@ public class SvnChangeList implements CommittedChangeList {
return myListsHolder.getDetailedList();
}
@Override
public boolean isModifiable() {
return true;
}
public boolean equals(final Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;