[PATCH 2 of 8 git-diff] patch: add index line for diff output
Sean Farley
sean at farley.io
Mon Jan 9 14:49:35 EST 2017
# HG changeset patch
# User Sean Farley <sean at 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.
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'
More information about the Mercurial-devel
mailing list