D5787: diff: support ignoring config settings when parsing optional diffopts

spectral (Kyle Lippincott) phabricator at mercurial-scm.org
Thu Jan 31 23:49:22 UTC 2019


spectral created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  Previously, there was no supported way of respecting diff options set on the
  command line without picking up potentially breaking settings from the config.
  
  With this change, we can call difffeatureopts(..., whitespace='noconfig') to
  ignore the user's config for the `whitespace` category of "optional features",
  but respect options set on the commandline (even whitespace options) and respect
  the user's config for "non-optional features" (nodates, showfunc, context).
  
  It's not clear if that last aspect is useful, but it seemed plausible that
  setting `diff.nodates` or `diff.showfunc` should be respected even when running
  `commit --interactive`, while it seems unlikely that the user intended to have
  diff.ignoreblanklines apply when calling `commit --interactive`.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D5787

AFFECTED FILES
  mercurial/diffutil.py

CHANGE DETAILS

diff --git a/mercurial/diffutil.py b/mercurial/diffutil.py
--- a/mercurial/diffutil.py
+++ b/mercurial/diffutil.py
@@ -30,8 +30,15 @@
     - whitespace: whitespace options like ignoreblanklines and ignorews
     - formatchanging: options that will likely break or cause correctness issues
       with most diff parsers
+
+    For the category settings (whitespace, git, formatchanging), the valid
+    values are True, False, or the string 'noconfig'. If the string 'noconfig'
+    is used, then only values in `opts` are considered, otherwise this returns
+    False (which is the default value for all options besides 'unified', which
+    does not set 'category').
     '''
-    def get(key, name=None, getter=ui.configbool, forceplain=None):
+    def get(key, name=None, getter=ui.configbool, forceplain=None,
+            category=None):
         if opts:
             v = opts.get(key)
             # diffopts flags are either None-default (which is passed
@@ -45,6 +52,8 @@
                 return v
         if forceplain is not None and ui.plain():
             return forceplain
+        if category == 'noconfig':
+            return False
         return getter(section, name or key, untrusted=untrusted)
 
     # core options, expected to be understood by every diff parser
@@ -56,7 +65,7 @@
     buildopts['xdiff'] = ui.configbool('experimental', 'xdiff')
 
     if git:
-        buildopts['git'] = get('git')
+        buildopts['git'] = get('git', category=git)
 
         # since this is in the experimental section, we need to call
         # ui.configbool directory
@@ -88,18 +97,25 @@
                 buildopts['index'] = hlen
 
     if whitespace:
-        buildopts['ignorews'] = get('ignore_all_space', 'ignorews')
-        buildopts['ignorewsamount'] = get('ignore_space_change',
+        getws = lambda *args, **kwargs: get(*args, category=whitespace,
+                                            **kwargs)
+
+        buildopts['ignorews'] = getws('ignore_all_space', 'ignorews')
+        buildopts['ignorewsamount'] = getws('ignore_space_change',
                                           'ignorewsamount')
-        buildopts['ignoreblanklines'] = get('ignore_blank_lines',
+        buildopts['ignoreblanklines'] = getws('ignore_blank_lines',
                                             'ignoreblanklines')
-        buildopts['ignorewseol'] = get('ignore_space_at_eol', 'ignorewseol')
+        buildopts['ignorewseol'] = getws('ignore_space_at_eol', 'ignorewseol')
     if formatchanging:
+        getfc = lambda *args, **kwargs: get(*args, category=formatchanging,
+                                            **kwargs)
+
         buildopts['text'] = opts and opts.get('text')
         binary = None if opts is None else opts.get('binary')
         buildopts['nobinary'] = (not binary if binary is not None
-                                 else get('nobinary', forceplain=False))
-        buildopts['noprefix'] = get('noprefix', forceplain=False)
-        buildopts['worddiff'] = get('word_diff', 'word-diff', forceplain=False)
+                                 else getfc('nobinary', forceplain=False))
+        buildopts['noprefix'] = getfc('noprefix', forceplain=False)
+        buildopts['worddiff'] = getfc('word_diff', 'word-diff',
+                                      forceplain=False)
 
     return mdiff.diffopts(**pycompat.strkwargs(buildopts))



To: spectral, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list