changeset 29948:e40343ce9c4c

diffopts: notice a negated boolean flag in diffopts This means that if you have git-diffs enabled by default (pretty common) and you hit the rare (but real) case where a git-diff breaks patch(1) or some other tool, you can easily disable it by just specifying --no-git on the command line. I feel a little bad about the isinstance() check, but some values in diffopts are not booleans and so we need to preserve false iff the flag is a boolean flag: failing to do this means we end up with empty string defaults for flags clobbering meaningful values from the [diff] section in hgrc.
author Augie Fackler <augie@google.com>
date Tue, 30 Aug 2016 15:55:07 -0400
parents e1f0ec0b7d2d
children e7cacb45c4be
files mercurial/patch.py tests/test-diff-unified.t
diffstat 2 files changed, 24 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/patch.py	Tue Sep 13 22:57:57 2016 -0400
+++ b/mercurial/patch.py	Tue Aug 30 15:55:07 2016 -0400
@@ -2144,7 +2144,14 @@
     def get(key, name=None, getter=ui.configbool, forceplain=None):
         if opts:
             v = opts.get(key)
-            if v:
+            # diffopts flags are either None-default (which is passed
+            # through unchanged, so we can identify unset values), or
+            # some other falsey default (eg --unified, which defaults
+            # to an empty string). We only want to override the config
+            # entries from hgrc with command line values if they
+            # appear to have been set, which is any truthy value,
+            # True, or False.
+            if v or isinstance(v, bool):
                 return v
         if forceplain is not None and ui.plain():
             return forceplain
--- a/tests/test-diff-unified.t	Tue Sep 13 22:57:57 2016 -0400
+++ b/tests/test-diff-unified.t	Tue Aug 30 15:55:07 2016 -0400
@@ -333,4 +333,20 @@
   +    return a + b + c + e;
    }
 
+If [diff] git is set to true, but the user says --no-git, we should
+*not* get git diffs
+  $ hg diff --nodates --config diff.git=1 --no-git
+  diff -r f2c7c817fa55 f1
+  --- a/f1
+  +++ b/f1
+  @@ -2,6 +2,6 @@
+       int a = 0;
+       int b = 1;
+       int c = 2;
+  -    int d = 3;
+  -    return a + b + c + d;
+  +    int e = 3;
+  +    return a + b + c + e;
+   }
+
   $ cd ..