From e6d5ea60e804a43c6363a515395a3f04258e7be0 Mon Sep 17 00:00:00 2001 From: Nadya Zabrodina Date: Fri, 18 Apr 2014 16:23:24 +0400 Subject: [PATCH] IDEA-86665 hg annotate: ignore whitespace changes *option to ignore whitespace differences in annotations added to mercurial configuration panel; *annotate with ignored whitespace option if supported; *supported version added; *tests added --- .../org/zmlx/hg4idea/HgVcsMessages.properties | 2 ++ .../org/zmlx/hg4idea/HgProjectSettings.java | 22 ++++++++++-- .../hg4idea/command/HgAnnotateCommand.java | 7 ++++ .../ui/HgConfigurationProjectPanel.form | 11 +++++- .../ui/HgConfigurationProjectPanel.java | 9 +++-- .../src/org/zmlx/hg4idea/util/HgVersion.java | 5 +++ .../test/annotation/HgAnnotationTest.java | 34 ++++++++++++++++--- 7 files changed, 80 insertions(+), 10 deletions(-) diff --git a/plugins/hg4idea/resources/org/zmlx/hg4idea/HgVcsMessages.properties b/plugins/hg4idea/resources/org/zmlx/hg4idea/HgVcsMessages.properties index f0be716bf856..d04ad38630a0 100644 --- a/plugins/hg4idea/resources/org/zmlx/hg4idea/HgVcsMessages.properties +++ b/plugins/hg4idea/resources/org/zmlx/hg4idea/HgVcsMessages.properties @@ -55,6 +55,8 @@ hg4idea.unable.to.run.hg=Unable to run hg: {0} hg4idea.run.success.title=Hg Executed Successfully hg4idea.run.failed.title=Hg Execution Failed +hg4idea.configuration.ignore.whitespace.in.annotate=Ignore &whitespace differences in annotations + hg4idea.command.executable.error=Error executing \"{0}\". Make sure you have setup the right executable in Mercurial configuration hg4idea.commit.success=Repository \"{0}\" committed diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/HgProjectSettings.java b/plugins/hg4idea/src/org/zmlx/hg4idea/HgProjectSettings.java index 246a3f667f48..ff82720bab0b 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/HgProjectSettings.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/HgProjectSettings.java @@ -16,6 +16,8 @@ import com.intellij.openapi.components.PersistentStateComponent; import com.intellij.openapi.components.State; import com.intellij.openapi.components.Storage; import com.intellij.openapi.components.StoragePathMacros; +import com.intellij.openapi.project.Project; +import com.intellij.openapi.vcs.changes.VcsAnnotationRefresher; import org.jetbrains.annotations.NotNull; @State( @@ -23,11 +25,14 @@ import org.jetbrains.annotations.NotNull; storages = @Storage(file = StoragePathMacros.WORKSPACE_FILE) ) public class HgProjectSettings implements PersistentStateComponent { - @NotNull private final HgGlobalSettings myAppSettings; + + @NotNull private final HgGlobalSettings myAppSettings; + @NotNull private final Project myProject; private State myState = new State(); - public HgProjectSettings(@NotNull HgGlobalSettings appSettings) { + public HgProjectSettings(@NotNull Project project, @NotNull HgGlobalSettings appSettings) { + myProject = project; myAppSettings = appSettings; } @@ -35,6 +40,7 @@ public class HgProjectSettings implements PersistentStateComponent execute(@NotNull HgFile hgFile, VcsFileRevision revision) { final List arguments = new ArrayList(); arguments.add("-cvnudl"); + HgVcs vcs = HgVcs.getInstance(myProject); + if (vcs != null && + vcs.getProjectSettings().isWhitespacesIgnoredInAnnotations() && + vcs.getVersion().isIgnoreWhitespaceDiffInAnnotationsSupported()) { + arguments.add("-w"); + } if (revision != null) { arguments.add("-r"); HgRevisionNumber revisionNumber = (HgRevisionNumber)revision.getRevisionNumber(); diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgConfigurationProjectPanel.form b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgConfigurationProjectPanel.form index a9fbc3389067..38dc6eb52908 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgConfigurationProjectPanel.form +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgConfigurationProjectPanel.form @@ -8,7 +8,7 @@ - + @@ -28,6 +28,15 @@ + + + + + + + + + diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgConfigurationProjectPanel.java b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgConfigurationProjectPanel.java index d90680861438..2aff9073d266 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgConfigurationProjectPanel.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/ui/HgConfigurationProjectPanel.java @@ -33,6 +33,7 @@ public class HgConfigurationProjectPanel { private JPanel myMainPanel; private JCheckBox myCheckIncomingOutgoingCbx; + private JCheckBox myIgnoredWhitespacesInAnnotationsCbx; private TextFieldWithBrowseButton myPathSelector; private JButton myTestButton; private final HgVcs myVcs; @@ -61,11 +62,14 @@ public class HgConfigurationProjectPanel { public boolean isModified() { boolean executableModified = !getCurrentPath().equals(myProjectSettings.getHgExecutable()); - return executableModified || myCheckIncomingOutgoingCbx.isSelected() != myProjectSettings.isCheckIncomingOutgoing(); + return executableModified || + myCheckIncomingOutgoingCbx.isSelected() != myProjectSettings.isCheckIncomingOutgoing() || + myIgnoredWhitespacesInAnnotationsCbx.isSelected() != myProjectSettings.isWhitespacesIgnoredInAnnotations(); } public void saveSettings() { myProjectSettings.setCheckIncomingOutgoing(myCheckIncomingOutgoingCbx.isSelected()); + myProjectSettings.setIgnoreWhitespacesInAnnotations(myIgnoredWhitespacesInAnnotationsCbx.isSelected()); myProjectSettings.setHgExecutable(getCurrentPath()); myVcs.checkVersion(); } @@ -75,7 +79,8 @@ public class HgConfigurationProjectPanel { } public void loadSettings() { - myCheckIncomingOutgoingCbx.setSelected(myProjectSettings.isCheckIncomingOutgoing() ); + myCheckIncomingOutgoingCbx.setSelected(myProjectSettings.isCheckIncomingOutgoing()); + myIgnoredWhitespacesInAnnotationsCbx.setSelected(myProjectSettings.isWhitespacesIgnoredInAnnotations()); myPathSelector.setText(myProjectSettings.getGlobalSettings().getHgExecutable()); } diff --git a/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgVersion.java b/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgVersion.java index 1883f2978611..a01e6549b890 100644 --- a/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgVersion.java +++ b/plugins/hg4idea/src/org/zmlx/hg4idea/util/HgVersion.java @@ -56,6 +56,7 @@ public final class HgVersion implements Comparable { public static final HgVersion PARENT_REVISION_TEMPLATES_SUPPORTED = new HgVersion(2, 4, 0); public static final HgVersion BRANCH_HEADS_BASE_SERVED_FILE_EXIST = new HgVersion(2, 5, 0); public static final HgVersion BRANCH2_FILE_EXIST = new HgVersion(2, 9, 0); + public static final HgVersion IGNORE_WHITESPACE_DIFF_IN_ANNOTATIONS = new HgVersion(2, 1, 0); //see http://selenic.com/pipermail/mercurial-devel/2013-May/051209.html fixed since 2.7 private static final HgVersion LARGEFILES_WITH_FOLLOW_SUPPORTED = new HgVersion(2, 7, 0); @@ -163,6 +164,10 @@ public final class HgVersion implements Comparable { return compareTo(PARENT_REVISION_TEMPLATES_SUPPORTED) >= 0; } + public boolean isIgnoreWhitespaceDiffInAnnotationsSupported() { + return compareTo(IGNORE_WHITESPACE_DIFF_IN_ANNOTATIONS) >= 0; + } + public boolean hasBranchHeadsBaseServed() { return compareTo(BRANCH_HEADS_BASE_SERVED_FILE_EXIST) >= 0 && compareTo(BRANCH2_FILE_EXIST) < 0; } diff --git a/plugins/hg4idea/testSrc/hg4idea/test/annotation/HgAnnotationTest.java b/plugins/hg4idea/testSrc/hg4idea/test/annotation/HgAnnotationTest.java index 86487916a687..eec9de127af8 100644 --- a/plugins/hg4idea/testSrc/hg4idea/test/annotation/HgAnnotationTest.java +++ b/plugins/hg4idea/testSrc/hg4idea/test/annotation/HgAnnotationTest.java @@ -14,13 +14,9 @@ import java.util.Arrays; import java.util.Date; import java.util.List; -import static com.intellij.openapi.vcs.Executor.cd; -import static com.intellij.openapi.vcs.Executor.echo; +import static com.intellij.openapi.vcs.Executor.*; import static hg4idea.test.HgExecutor.hg; -/** - * @author Nadya Zabrodina - */ public class HgAnnotationTest extends HgPlatformTest { String firstCreatedFile = "file.txt"; static final String author1 = "a.bacaba@jetbrains.com"; @@ -53,4 +49,32 @@ public class HgAnnotationTest extends HgPlatformTest { assertEquals(date, line.get(HgAnnotation.FIELD.DATE)); } } + + public void testAnnotationWithIgnoredWhitespaces() { + annotationWithWhitespaceOption(true); + } + + public void testAnnotationWithoutIgnoredWhitespaces() { + annotationWithWhitespaceOption(false); + } + + private void annotationWithWhitespaceOption(boolean ignoreWhitespaces) { + cd(myRepository); + String whitespaceFile = "whitespaces.txt"; + touch(whitespaceFile, "not whitespaces"); + myRepository.refresh(false, true); + String whiteSpaceAuthor = "Mr.Whitespace"; + final VirtualFile file = myRepository.findFileByRelativePath(whitespaceFile); + assert file != null; + hg("add " + whitespaceFile); + hg("commit -m modify -u '" + defaultAuthor + "'"); + echo(whitespaceFile, " ");//add several whitespaces + hg("commit -m whitespaces -u '" + whiteSpaceAuthor + "'"); + final HgFile hgFile = new HgFile(myRepository, VfsUtilCore.virtualToIoFile(file)); + myVcs.getProjectSettings().setIgnoreWhitespacesInAnnotations(ignoreWhitespaces); + List annotationLines = + new HgAnnotateCommand(myProject).execute(hgFile, null); + HgAnnotationLine line = annotationLines.get(0); + assertEquals(ignoreWhitespaces ? defaultAuthor : whiteSpaceAuthor, line.get(HgAnnotation.FIELD.USER)); + } }