Patchwork [1,of,8,git-diff] patch: add config knob for displaying the index header

login
register
mail settings
Submitter Sean Farley
Date Jan. 9, 2017, 7:49 p.m.
Message ID <f83be3a6c9e0e39efee9.1483991374@1.0.0.127.in-addr.arpa>
Download mbox | patch
Permalink /patch/18148/
State Accepted
Headers show

Comments

Sean Farley - Jan. 9, 2017, 7:49 p.m.
# HG changeset patch
# User Sean Farley <sean@farley.io>
# Date 1483989227 28800
#      Mon Jan 09 11:13:47 2017 -0800
# Node ID f83be3a6c9e0e39efee95c1e4059030733a0371e
# Parent  ee47e951c6f9dbe6aceeb10d2f4acbc998a27bd3
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.

Patch

diff --git a/mercurial/mdiff.py b/mercurial/mdiff.py
--- a/mercurial/mdiff.py
+++ b/mercurial/mdiff.py
@@ -50,10 +50,11 @@  class diffopts(object):
         'showfunc': False,
         'git': False,
         'nodates': False,
         'nobinary': False,
         'noprefix': False,
+        'index': 0,
         'ignorews': False,
         'ignorewsamount': False,
         'ignoreblanklines': False,
         'upgrade': False,
         }
diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -2166,10 +2166,35 @@  def difffeatureopts(ui, opts=None, untru
         'context': get('unified', getter=ui.config),
     }
 
     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',
                                           'ignorewsamount')
         buildopts['ignoreblanklines'] = get('ignore_blank_lines',