patch: add config knob for displaying the index header
authorSean Farley <sean@farley.io>
Mon, 09 Jan 2017 11:13:47 -0800
changeset 30788 d1901c4c8ec0
parent 30787 ff020ee5f06c
child 30789 b8ad243f5ded
patch: add config knob for displaying the index header This config knob can take an integer between 0 and 40 or a keyword ('none', 'short', 'full') to control the length of hash to output. It will display diffs with the git index header as such, diff --git a/mercurial/mdiff.py b/mercurial/mdiff.py index 112edf7..d6b52c5 100644 We'll put this in the experimental section for now.
mercurial/mdiff.py
mercurial/patch.py
--- a/mercurial/mdiff.py	Thu Jan 12 12:05:23 2017 -0800
+++ b/mercurial/mdiff.py	Mon Jan 09 11:13:47 2017 -0800
@@ -52,6 +52,7 @@
         'nodates': False,
         'nobinary': False,
         'noprefix': False,
+        'index': 0,
         'ignorews': False,
         'ignorewsamount': False,
         'ignoreblanklines': False,
--- a/mercurial/patch.py	Thu Jan 12 12:05:23 2017 -0800
+++ b/mercurial/patch.py	Mon Jan 09 11:13:47 2017 -0800
@@ -2168,6 +2168,31 @@
 
     if git:
         buildopts['git'] = get('git')
+
+        # need to inspect the ui object instead of using get() since we want to
+        # test for an int
+        hconf = ui.config('experimental', 'extendedheader.index')
+        if hconf is not None:
+            hlen = None
+            try:
+                # the hash config could be an integer (for length of hash) or a
+                # word (e.g. short, full, none)
+                hlen = int(hconf)
+            except ValueError:
+                # default value
+                if hconf == 'short' or hconf == '':
+                    hlen = 12
+                elif hconf == 'full':
+                    hlen = 40
+                elif hconf != 'none':
+                    msg = _("invalid value for extendedheader.index: '%s'\n")
+                    ui.warn(msg % hconf)
+            finally:
+                if hlen < 0 or hlen > 40:
+                    msg = _("invalid length for extendedheader.index: '%d'\n")
+                    ui.warn(msg % hlen)
+                buildopts['index'] = hlen
+
     if whitespace:
         buildopts['ignorews'] = get('ignore_all_space', 'ignorews')
         buildopts['ignorewsamount'] = get('ignore_space_change',