[PATCH 2 of 2] diff: makes diff.noprefix not breaks diffstat template (issue4755)

liscju piotr.listkiewicz at gmail.com
Tue Apr 19 13:22:37 EDT 2016


# HG changeset patch
# User liscju <piotr.listkiewicz at gmail.com>
# Date 1461081437 -7200
#      Tue Apr 19 17:57:17 2016 +0200
# Branch stable
# Node ID d259dc8d0ea0ecdb937d7b9528934f14c639d5c1
# Parent  d528ea7502ab7fc0ef01d3a8a44dc78df8d73563
diff: makes diff.noprefix not breaks diffstat template (issue4755)

Before diff.noprefix with diff.git made diffstat to be "0: +0/-0"
no matter how stat looks like, because patch.diffstatdata function
didn't recognise git diff header properly searching for a nonexisting
"a/" prefix in filenames. It is fixed by always passing prefixes in
diff no matter what configuration states.

Other option to fix this would be to change how patch.diffstatdata
parse git diff without prefixes, but for the files that names
contain spaces inside would be impossible, for example distinguishing
between input/output name in git diff header:

diff --git file with spaces file with spaces

diff -r d528ea7502ab -r d259dc8d0ea0 mercurial/templatekw.py
--- a/mercurial/templatekw.py	Tue Apr 19 17:32:34 2016 +0200
+++ b/mercurial/templatekw.py	Tue Apr 19 17:57:17 2016 +0200
@@ -292,7 +292,7 @@ def showdiffstat(repo, ctx, templ, **arg
     """String. Statistics of changes with the following format:
     "modified files: +added/-removed lines"
     """
-    stats = patch.diffstatdata(util.iterlines(ctx.diff()))
+    stats = patch.diffstatdata(util.iterlines(ctx.diff(noprefix=False)))
     maxname, maxtotal, adds, removes, binary = patch.diffstatsum(stats)
     return '%s: +%s/-%s' % (len(stats), adds, removes)
 
diff -r d528ea7502ab -r d259dc8d0ea0 tests/test-diffstat.t
--- a/tests/test-diffstat.t	Tue Apr 19 17:32:34 2016 +0200
+++ b/tests/test-diffstat.t	Tue Apr 19 17:57:17 2016 +0200
@@ -104,4 +104,10 @@ diffstat within directories:
 
   $ hg diff --stat --root . -I old
 
+  $ hg commit -m "commit with dir1/new"
+  $ hg log -r . -T '{diffstat}\n' --config diff.noprefix=1
+  2: +2/-0
+  $ hg log -r . -T '{diffstat}\n' --config diff.noprefix=1 --config diff.git=1
+  2: +2/-0
+
   $ cd ..


More information about the Mercurial-devel mailing list