Patchwork [6,of,7] patch.difffeatureopts: add a feature for format-changing diffopts

login
register
mail settings
Submitter Siddharth Agarwal
Date Nov. 26, 2014, 3:54 a.m.
Message ID <7451bf7e463e2932817a.1416974041@devbig136.prn2.facebook.com>
Download mbox | patch
Permalink /patch/6862/
State Accepted
Commit 60300a4c0ae52829931eaf24e30fac016d5ee9f8
Headers show

Comments

Siddharth Agarwal - Nov. 26, 2014, 3:54 a.m.
# HG changeset patch
# User Siddharth Agarwal <sid0@fb.com>
# Date 1416360123 28800
#      Tue Nov 18 17:22:03 2014 -0800
# Node ID 7451bf7e463e2932817a08d6b7114ecd363e0cfd
# Parent  f093ffdbc8f5227848dc753edc9c576abd7dbbaa
patch.difffeatureopts: add a feature for format-changing diffopts

Typically, callers that are interested in this set are also interested in the
others. We still add it as a first-class flag for convenience.

Patch

diff --git mercurial/patch.py mercurial/patch.py
--- mercurial/patch.py
+++ mercurial/patch.py
@@ -1561,17 +1561,19 @@ 
 def diffallopts(ui, opts=None, untrusted=False, section='diff'):
     '''return diffopts with all features supported and parsed'''
     return difffeatureopts(ui, opts=opts, untrusted=untrusted, section=section,
-                           git=True, whitespace=True)
+                           git=True, whitespace=True, formatchanging=True)
 
 diffopts = diffallopts
 
 def difffeatureopts(ui, opts=None, untrusted=False, section='diff', git=False,
-                    whitespace=False):
+                    whitespace=False, formatchanging=False):
     '''return diffopts with only opted-in features parsed
 
     Features:
     - git: git-style diffs
     - whitespace: whitespace options like ignoreblanklines and ignorews
+    - formatchanging: options that will likely break or cause correctness issues
+      with most diff parsers
     '''
     def get(key, name=None, getter=ui.configbool, forceplain=None):
         if opts:
@@ -1582,11 +1584,9 @@ 
             return forceplain
         return getter(section, name or key, None, untrusted=untrusted)
 
+    # core options, expected to be understood by every diff parser
     buildopts = {
-        'text': opts and opts.get('text'),
         'nodates': get('nodates'),
-        'nobinary': get('nobinary'),
-        'noprefix': get('noprefix', forceplain=False),
         'showfunc': get('show_function', 'showfunc'),
         'context': get('unified', getter=ui.config),
     }
@@ -1599,6 +1599,10 @@ 
                                           'ignorewsamount')
         buildopts['ignoreblanklines'] = get('ignore_blank_lines',
                                             'ignoreblanklines')
+    if formatchanging:
+        buildopts['text'] = opts and opts.get('text')
+        buildopts['nobinary'] = get('nobinary')
+        buildopts['noprefix'] = get('noprefix', forceplain=False)
 
     return mdiff.diffopts(**buildopts)