Patchwork [2,of,8,git-diff] patch: add index line for diff output

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

Comments

Sean Farley - Jan. 9, 2017, 7:49 p.m.
# HG changeset patch
# User Sean Farley <sean@farley.io>
# Date 1483220517 21600
#      Sat Dec 31 15:41:57 2016 -0600
# Node ID 95c9da9342914bda2208138af58a38eeaed859b4
# Parent  f83be3a6c9e0e39efee95c1e4059030733a0371e
patch: add index line for diff output

This helps highlighting in third-party diff coloring (which assumes git
output) and maintains pedantic correctness with diff --git.

Tests will be added at the end of the series.

Patch

diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -2524,10 +2524,19 @@  def trydiff(repo, revs, ctx1, ctx2, modi
             text = mdiff.b85diff(content1, content2)
             if text:
                 header.append('index %s..%s' %
                               (gitindex(content1), gitindex(content2)))
         else:
+            if opts.git and opts.index > 0:
+                flag = flag1
+                if flag is None:
+                    flag = flag2
+                header.append('index %s..%s %s' %
+                              (gitindex(content1)[0:opts.index],
+                               gitindex(content2)[0:opts.index],
+                               gitmode[flag]))
+
             text = mdiff.unidiff(content1, date1,
                                  content2, date2,
                                  path1, path2, opts=opts)
         if header and (text or len(header) > 1):
             yield '\n'.join(header) + '\n'