diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/versionBrowser/CommittedChangeList.java b/platform/vcs-api/src/com/intellij/openapi/vcs/versionBrowser/CommittedChangeList.java index c906df023532..70c77fc07ea4 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/versionBrowser/CommittedChangeList.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/versionBrowser/CommittedChangeList.java @@ -40,4 +40,9 @@ public interface CommittedChangeList extends ChangeList { AbstractVcs getVcs(); Collection getChangesWithMovedTrees(); + + /** + * @return true if this change list can be modified, for example, by reverting some of the changes. + */ + boolean isModifiable(); } diff --git a/platform/vcs-api/src/com/intellij/openapi/vcs/versionBrowser/CommittedChangeListImpl.java b/platform/vcs-api/src/com/intellij/openapi/vcs/versionBrowser/CommittedChangeListImpl.java index eaef768df1ba..1dc210317bfa 100644 --- a/platform/vcs-api/src/com/intellij/openapi/vcs/versionBrowser/CommittedChangeListImpl.java +++ b/platform/vcs-api/src/com/intellij/openapi/vcs/versionBrowser/CommittedChangeListImpl.java @@ -68,6 +68,11 @@ public class CommittedChangeListImpl implements CommittedChangeList { return getChangesWithMovedTreesImpl(this); } + @Override + public boolean isModifiable() { + return true; + } + public static Collection getChangesWithMovedTreesImpl(final CommittedChangeList list) { return list.getChanges(); } diff --git a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/RevertSelectedChangesAction.java b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/RevertSelectedChangesAction.java index 27df5e17ac9d..72ce233427cd 100644 --- a/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/RevertSelectedChangesAction.java +++ b/platform/vcs-impl/src/com/intellij/openapi/vcs/changes/actions/RevertSelectedChangesAction.java @@ -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() { diff --git a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/changeBrowser/CvsChangeList.java b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/changeBrowser/CvsChangeList.java index 2385591da6f6..3fba48f96e90 100644 --- a/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/changeBrowser/CvsChangeList.java +++ b/plugins/cvs/cvs-plugin/src/com/intellij/cvsSupport2/changeBrowser/CvsChangeList.java @@ -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) { diff --git a/plugins/git4idea/src/git4idea/GitUtil.java b/plugins/git4idea/src/git4idea/GitUtil.java index 6b6cd8405420..bf17f84d4c27 100644 --- a/plugins/git4idea/src/git4idea/GitUtil.java +++ b/plugins/git4idea/src/git4idea/GitUtil.java @@ -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()); diff --git a/plugins/git4idea/src/git4idea/actions/GitShowAllSubmittedFilesAction.java b/plugins/git4idea/src/git4idea/actions/GitShowAllSubmittedFilesAction.java index b0f760edd2c8..31b0d0bef8c6 100644 --- a/plugins/git4idea/src/git4idea/actions/GitShowAllSubmittedFilesAction.java +++ b/plugins/git4idea/src/git4idea/actions/GitShowAllSubmittedFilesAction.java @@ -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() { diff --git a/plugins/git4idea/src/git4idea/changes/GitChangeUtils.java b/plugins/git4idea/src/git4idea/changes/GitChangeUtils.java index d6e9f92de9b2..c90c26ff7eb1 100644 --- a/plugins/git4idea/src/git4idea/changes/GitChangeUtils.java +++ b/plugins/git4idea/src/git4idea/changes/GitChangeUtils.java @@ -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 changes = new ArrayList(); // 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) { diff --git a/plugins/git4idea/src/git4idea/changes/GitCommittedChangeList.java b/plugins/git4idea/src/git4idea/changes/GitCommittedChangeList.java index aad4974987aa..4c53287d6819 100644 --- a/plugins/git4idea/src/git4idea/changes/GitCommittedChangeList.java +++ b/plugins/git4idea/src/git4idea/changes/GitCommittedChangeList.java @@ -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 changes, String fullHash) { + private final boolean myModifiable; + + public GitCommittedChangeList(String name, String comment, String committerName, long number, Date commitDate, Collection 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; } } diff --git a/plugins/git4idea/src/git4idea/history/GitDiffFromHistoryHandler.java b/plugins/git4idea/src/git4idea/history/GitDiffFromHistoryHandler.java index dcfdf1f4c63f..0f38874ced5c 100644 --- a/plugins/git4idea/src/git4idea/history/GitDiffFromHistoryHandler.java +++ b/plugins/git4idea/src/git4idea/history/GitDiffFromHistoryHandler.java @@ -159,7 +159,7 @@ public class GitDiffFromHistoryHandler implements DiffFromHistoryHandler { else { // show the initial commit myChanges = new ArrayList(GitChangeUtils.getRevisionChanges(repository.getProject(), repository.getRoot(), hash2, false, - true).getChanges()); + true, true).getChanges()); } } catch (VcsException e) { diff --git a/plugins/git4idea/src/git4idea/rebase/GitRebaseEditor.java b/plugins/git4idea/src/git4idea/rebase/GitRebaseEditor.java index a0225ad98d98..2ec97fc95d70 100644 --- a/plugins/git4idea/src/git4idea/rebase/GitRebaseEditor.java +++ b/plugins/git4idea/src/git4idea/rebase/GitRebaseEditor.java @@ -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); } }); diff --git a/plugins/git4idea/src/git4idea/ui/GitReferenceValidator.java b/plugins/git4idea/src/git4idea/ui/GitReferenceValidator.java index 125992f17c6e..eb1c76c671d8 100644 --- a/plugins/git4idea/src/git4idea/ui/GitReferenceValidator.java +++ b/plugins/git4idea/src/git4idea/ui/GitReferenceValidator.java @@ -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) { diff --git a/plugins/git4idea/src/git4idea/ui/GitUnstashDialog.java b/plugins/git4idea/src/git4idea/ui/GitUnstashDialog.java index df7051f224de..5f1c8b1a5a23 100644 --- a/plugins/git4idea/src/git4idea/ui/GitUnstashDialog.java +++ b/plugins/git4idea/src/git4idea/ui/GitUnstashDialog.java @@ -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(); diff --git a/plugins/svn4idea/src/org/jetbrains/idea/svn/history/SvnChangeList.java b/plugins/svn4idea/src/org/jetbrains/idea/svn/history/SvnChangeList.java index 8666df90b99f..d7b96a141f8e 100644 --- a/plugins/svn4idea/src/org/jetbrains/idea/svn/history/SvnChangeList.java +++ b/plugins/svn4idea/src/org/jetbrains/idea/svn/history/SvnChangeList.java @@ -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;