D5709: diffstat: support filenames with whitespaces on renames

navaneeth.suresh (Navaneeth Suresh) phabricator at mercurial-scm.org
Sat Jan 26 08:26:55 UTC 2019


navaneeth.suresh created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  This is a follow-up patch to https://phab.mercurial-scm.org/D5628. `line.split()` cannot get filenames with
  whitespaces as mentioned by @yuja. This patch replaces `split()` method with
  `slice`. Corresponding tests were also added.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D5709

AFFECTED FILES
  mercurial/patch.py
  tests/test-diffstat.t

CHANGE DETAILS

diff --git a/tests/test-diffstat.t b/tests/test-diffstat.t
--- a/tests/test-diffstat.t
+++ b/tests/test-diffstat.t
@@ -255,3 +255,19 @@
   $ hg diff --stat --git
    a => b |  0 
    1 files changed, 0 insertions(+), 0 deletions(-)
+-- filename may contain whitespaces
+  $ echo > c
+  $ hg ci -Am 'add c'
+  adding c
+  $ hg mv c 'new c'
+  $ hg diff --git
+  diff --git a/c b/new c
+  rename from c
+  rename to new c
+  $ hg diff --stat
+   c     |  1 -
+   new c |  1 +
+   2 files changed, 1 insertions(+), 1 deletions(-)
+  $ hg diff --stat --git
+   c => new c |  0 
+   1 files changed, 0 insertions(+), 0 deletions(-)
diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -2809,9 +2809,9 @@
               line.startswith('Binary file')):
             isbinary = True
         elif line.startswith('rename from'):
-            filename = line.split()[-1]
+            filename = line[12:]
         elif line.startswith('rename to'):
-            filename += ' => %s' % line.split()[-1]
+            filename += ' => %s' % line[10:]
     addresult()
     return results
 



To: navaneeth.suresh, #hg-reviewers
Cc: yuja, mercurial-devel


More information about the Mercurial-devel mailing list