Patchwork [3,of,3,STABLE] templatekw: don't use format changing diff options for {diffstat} (issue4755)

login
register
mail settings
Submitter Gregory Szorc
Date July 18, 2015, 9:24 p.m.
Message ID <0a23d0a4531838fb63e6.1437254671@vm-ubuntu-main.gateway.sonic.net>
Download mbox | patch
Permalink /patch/10039/
State Changes Requested
Delegated to: Matt Mackall
Headers show

Comments

Gregory Szorc - July 18, 2015, 9:24 p.m.
# HG changeset patch
# User Gregory Szorc <gregory.szorc@gmail.com>
# Date 1437254250 25200
#      Sat Jul 18 14:17:30 2015 -0700
# Node ID 0a23d0a4531838fb63e664da24c7aa1703cb0243
# Parent  b6ab3a470c0196159e8931c8c6dd4b5c4a52a4f6
templatekw: don't use format changing diff options for {diffstat} (issue4755)

Before this patch, diff.noprefix + diff.git would produce diffs that
patch.diffstatdata() would be unable to parse (it relies on the a/ prefix
to detect git style diffs).

We prevent the parsing issue by not honoring format changing options when
producing the diffs used to compute {diffstat}. Along with "noprefix," this
also prevents the "nobinary" and "text" options from impacting results.
It is possible there is a valid case where someone would want different
{diffstat} output depending on the "nobinary" setting. But this patch
assumes it isn't a supported use case and ignores that possible regression.

Patch

diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py
--- a/mercurial/templatekw.py
+++ b/mercurial/templatekw.py
@@ -247,9 +247,10 @@  def showdescription(repo, ctx, templ, **
 def showdiffstat(repo, ctx, templ, **args):
     """:diffstat: 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(allowformatchanging=False)))
     maxname, maxtotal, adds, removes, binary = patch.diffstatsum(stats)
     return '%s: +%s/-%s' % (len(stats), adds, removes)
 
 def showextras(**args):
diff --git a/tests/test-diffstat.t b/tests/test-diffstat.t
--- a/tests/test-diffstat.t
+++ b/tests/test-diffstat.t
@@ -127,9 +127,9 @@  diff.git should not impact {diffstat}
 
 diff.git and diff.noprefix together should not impact {diffstat}
 
   $ hg --config diff.git=true --config diff.noprefix=true log -T '{rev} {diffstat}\n'
-  2 0: +0/-0
-  1 0: +0/-0
-  0 0: +0/-0
+  2 2: +0/-0
+  1 1: +3/-0
+  0 2: +426/-0
 
   $ cd ..