Patchwork [2,of,2,STABLE] diff: disable diff.noprefix option for diffstat (issue5759)

login
register
mail settings
Submitter Yuya Nishihara
Date Dec. 17, 2017, 11:50 a.m.
Message ID <21f4da606ff71e45725b.1513511434@mimosa>
Download mbox | patch
Permalink /patch/26330/
State Accepted
Headers show

Comments

Yuya Nishihara - Dec. 17, 2017, 11:50 a.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1513503785 -32400
#      Sun Dec 17 18:43:05 2017 +0900
# Branch stable
# Node ID 21f4da606ff71e45725bd35db1982e3b02b7127c
# Parent  5a2aea363d40e2a200317d366e61a390e39fd9fa
diff: disable diff.noprefix option for diffstat (issue5759)

We could use patch.diffhunks() instead of patch.diff() to get filenames
without parsing patch content, but that isn't always possible because we
sometimes feed raw patch data to patch.diffstat().
Anton Shestakov - Dec. 17, 2017, 3:38 p.m.
On Sun, 17 Dec 2017 20:50:34 +0900
Yuya Nishihara <yuya@tcha.org> wrote:

> # HG changeset patch
> # User Yuya Nishihara <yuya@tcha.org>
> # Date 1513503785 -32400
> #      Sun Dec 17 18:43:05 2017 +0900
> # Branch stable
> # Node ID 21f4da606ff71e45725bd35db1982e3b02b7127c
> # Parent  5a2aea363d40e2a200317d366e61a390e39fd9fa
> diff: disable diff.noprefix option for diffstat (issue5759)
> 
> We could use patch.diffhunks() instead of patch.diff() to get filenames
> without parsing patch content, but that isn't always possible because we
> sometimes feed raw patch data to patch.diffstat().

This series looks good, but I'll let someone else queue it, as I think
I can only push patches for hgweb.

Patch

diff --git a/mercurial/cmdutil.py b/mercurial/cmdutil.py
--- a/mercurial/cmdutil.py
+++ b/mercurial/cmdutil.py
@@ -1514,7 +1514,7 @@  def diffordiffstat(ui, repo, diffopts, n
                     match.uipath(matchroot), uirelroot))
 
     if stat:
-        diffopts = diffopts.copy(context=0)
+        diffopts = diffopts.copy(context=0, noprefix=False)
         width = 80
         if not ui.plain():
             width = ui.termwidth()
diff --git a/tests/test-diffstat.t b/tests/test-diffstat.t
--- a/tests/test-diffstat.t
+++ b/tests/test-diffstat.t
@@ -69,6 +69,57 @@  Filename with spaces git diffstat:
    file with spaces |  Bin 
    1 files changed, 0 insertions(+), 0 deletions(-)
 
+Filename without "a/" or "b/" (issue5759):
+
+  $ hg diff --config 'diff.noprefix=1' -c1 --stat --git
+   a |  3 +++
+   1 files changed, 3 insertions(+), 0 deletions(-)
+  $ hg diff --config 'diff.noprefix=1' -c2 --stat --git
+   c |  Bin 
+   d |    0 
+   2 files changed, 0 insertions(+), 0 deletions(-)
+
+  $ hg log --config 'diff.noprefix=1' -r '1:' -p --stat --git
+  changeset:   1:3a95b07bb77f
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     appenda
+  
+   a |  3 +++
+   1 files changed, 3 insertions(+), 0 deletions(-)
+  
+  diff --git a a
+  --- a
+  +++ a
+  @@ -211,3 +211,6 @@
+   a
+   a
+   a
+  +a
+  +a
+  +a
+  
+  changeset:   2:c60a6c753773
+  tag:         tip
+  user:        test
+  date:        Thu Jan 01 00:00:00 1970 +0000
+  summary:     createb
+  
+   c |  Bin 
+   d |    0 
+   2 files changed, 0 insertions(+), 0 deletions(-)
+  
+  diff --git c c
+  new file mode 100644
+  index e69de29bb2d1d6434b8b29ae775ad8c2e48c5391..f76dd238ade08917e6712764a16a22005a50573d
+  GIT binary patch
+  literal 1
+  Ic${MZ000310RR91
+  
+  diff --git d d
+  new file mode 100644
+  
+
 diffstat within directories:
 
   $ hg rm -f 'file with spaces'