[PATCH] log: make {diffstat} work with diff.noprefix (issue4755)
Jun Wu
quark at fb.com
Mon Dec 21 16:08:57 UTC 2015
# HG changeset patch
# User Jun Wu <quark at fb.com>
# Date 1450210516 0
# Tue Dec 15 20:15:16 2015 +0000
# Node ID a71a4c67b0d1505c68364b13a525f2dbef886a90
# Parent 5df74b2f296df7f44a08106df4f9dd97a5aa726a
log: make {diffstat} work with diff.noprefix (issue4755)
We expect "diff --git a/$PATHA b/$PATHB" with diff.git=1. But diff.noprefix=1
breaks such expection. Fix it by reading file paths from following lines.
diff --git a/mercurial/patch.py b/mercurial/patch.py
--- a/mercurial/patch.py
+++ b/mercurial/patch.py
@@ -2482,9 +2482,11 @@
if line.startswith('diff'):
addresult()
# set numbers to 0 anyway when starting new file
- adds, removes, isbinary = 0, 0, False
+ filename, adds, removes, isbinary = None, 0, 0, False
if line.startswith('diff --git a/'):
- filename = gitre.search(line).group(2)
+ match = gitre.search(line)
+ if match:
+ filename = match.group(2)
elif line.startswith('diff -r'):
# format: "diff -r ... -r ... filename"
filename = diffre.search(line).group(1)
@@ -2492,6 +2494,11 @@
adds += 1
elif line.startswith('-') and not line.startswith('--- '):
removes += 1
+ elif not filename:
+ if line[:4] in ('+++ ', '--- ') and line[4:] != '/dev/null':
+ filename = line[4:]
+ elif line.startswith('rename to '):
+ filename = line[10:]
elif (line.startswith('GIT binary patch') or
line.startswith('Binary file')):
isbinary = True
diff --git a/tests/test-issue4755.t b/tests/test-issue4755.t
new file mode 100644
--- /dev/null
+++ b/tests/test-issue4755.t
@@ -0,0 +1,79 @@
+https://bz.mercurial-scm.org/4755
+
+ $ hg init
+
+Add a file
+
+ $ echo 1 > foo
+ $ hg add foo
+ $ hg ci -m 'add foo'
+ $ hg log -r . --stat -T '{diffstat}\n' --config diff.git=1 --config diff.noprefix=1
+ 1: +1/-0
+ foo | 1 +
+ 1 files changed, 1 insertions(+), 0 deletions(-)
+
+ $ hg log -r . --stat -T '{diffstat}\n' --config diff.git=1
+ 1: +1/-0
+ foo | 1 +
+ 1 files changed, 1 insertions(+), 0 deletions(-)
+
+Change a file
+
+ $ (echo 2; echo 3) > foo
+ $ hg ci -m 'change foo'
+ $ hg log -r . --stat -T '{diffstat}\n' --config diff.git=1 --config diff.noprefix=1
+ 1: +2/-1
+ foo | 3 ++-
+ 1 files changed, 2 insertions(+), 1 deletions(-)
+
+ $ hg log -r . --stat -T '{diffstat}\n' --config diff.git=1
+ 1: +2/-1
+ foo | 3 ++-
+ 1 files changed, 2 insertions(+), 1 deletions(-)
+
+Rename a file
+
+ $ hg rename foo bar
+ $ hg ci -m 'rename foo to bar'
+ $ hg log -r . --stat -T '{diffstat}\n' --config diff.git=1 --config diff.noprefix=1
+ 1: +0/-0
+ bar | 0
+ 1 files changed, 0 insertions(+), 0 deletions(-)
+
+ $ hg log -r . --stat -T '{diffstat}\n' --config diff.git=1
+ 1: +0/-0
+ bar | 0
+ 1 files changed, 0 insertions(+), 0 deletions(-)
+
+Rename without using hg rename
+
+ $ cp bar aha
+ $ hg remove bar
+ $ hg add aha
+ $ hg ci -m 'rename using add and remove'
+ $ hg log -r . --stat -T '{diffstat}\n' --config diff.git=1 --config diff.noprefix=1
+ 2: +2/-2
+ aha | 2 ++
+ bar | 2 --
+ 2 files changed, 2 insertions(+), 2 deletions(-)
+
+ $ hg log -r . --stat -T '{diffstat}\n' --config diff.git=1
+ 2: +2/-2
+ aha | 2 ++
+ bar | 2 --
+ 2 files changed, 2 insertions(+), 2 deletions(-)
+
+Delete a file
+
+ $ hg remove aha
+ $ hg ci -m 'remove aha'
+ $ hg log -r . --stat -T '{diffstat}\n' --config diff.git=1 --config diff.noprefix=1
+ 1: +0/-2
+ aha | 2 --
+ 1 files changed, 0 insertions(+), 2 deletions(-)
+
+ $ hg log -r . --stat -T '{diffstat}\n' --config diff.git=1
+ 1: +0/-2
+ aha | 2 --
+ 1 files changed, 0 insertions(+), 2 deletions(-)
+
More information about the Mercurial-devel
mailing list