diff --git a/mercurial/patch.py b/mercurial/patch.py --- a/mercurial/patch.py +++ b/mercurial/patch.py @@ -1529,6 +1529,8 @@ def trydiff(repo, revs, ctx1, ctx2, modi yield text def diffstatdata(lines): + diffre = re.compile('^diff .*-r [a-z0-9]+\s(.*)$') + filename, adds, removes = None, 0, 0 for line in lines: if line.startswith('diff'): @@ -1539,9 +1541,9 @@ def diffstatdata(lines): adds, removes = 0, 0 if line.startswith('diff --git'): filename = gitre.search(line).group(1) - else: + elif line.startswith('diff -r'): # format: "diff -r ... -r ... filename" - filename = line.split(None, 5)[-1] + filename = diffre.search(line).group(1) elif line.startswith('+') and not line.startswith('+++'): adds += 1 elif line.startswith('-') and not line.startswith('---'): diff --git a/tests/test-diffstat.t b/tests/test-diffstat.t --- a/tests/test-diffstat.t +++ b/tests/test-diffstat.t @@ -46,3 +46,20 @@ Binary git diffstat: b | Bin 1 files changed, 0 insertions(+), 0 deletions(-) + $ hg ci -m createb + + $ printf '\0' > "file with spaces" + $ hg add "file with spaces" + +Filename with spaces diffstat: + + $ hg diff --stat + file with spaces | 0 + 1 files changed, 0 insertions(+), 0 deletions(-) + +Filename with spaces git diffstat: + + $ hg diff --stat --git + file with spaces | Bin + 1 files changed, 0 insertions(+), 0 deletions(-) +