# HG changeset patch # User Gastón Kleiman # Date 1296847934 10800 # Node ID 104c9ed93fc524a32358c066f78f3fe0a4a6ef40 # Parent 30e103dacd5fa84c99c640cd6f5a72b96955817e diffstat: fix parsing of filenames with spaces The patch changes the output of "hg diff --stat" when one file whose filename has spaces has changed, making it get the full filename instead of just the substring between the last space and the end of the filename. It also changes the diffstat generated by "hg email -d" when one of the commit messages starts with "diff". Because of the regex used to parse the filename, the diffstat generated by "hg email -d" will still be not correct if a commit message starts with "diff -r ". Before the patch Mercurial has the following behavior: $ echo "foobar">"file with spaces" $ hg add "file with spaces" $ hg diff --stat spaces | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) $ hg diff --git --stat file with spaces | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) After the patch: $ echo "foobar">"file with spaces" $ hg add "file with spaces" $ hg diff --stat file with spaces | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) $ hg diff --git --stat file with spaces | 1 + 1 files changed, 1 insertions(+), 0 deletions(-) Before the patch: $ hg add mercurial/patch.py tests/tests-diffstat.t $ hg commit -m "diffstat: fix parsing of filenames" $ hg email -d --test tip This patch series consists of 1 patches. diffstat: fix parsing of filenames [...] filenames | 0 mercurial/patch.py | 6 ++++-- tests/test-diffstat.t | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) [...] After the patch: $ hg email -d --test tip This patch series consists of 1 patches. diffstat: fix parsing of filenames [...] mercurial/patch.py | 6 ++++-- tests/test-diffstat.t | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 2 deletions(-) [...] diff -r 30e103dacd5f -r 104c9ed93fc5 mercurial/patch.py --- a/mercurial/patch.py Thu Feb 10 15:41:34 2011 +0300 +++ b/mercurial/patch.py Fri Feb 04 16:32:14 2011 -0300 @@ -1529,6 +1529,8 @@ 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 @@ 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 -r 30e103dacd5f -r 104c9ed93fc5 tests/test-diffstat.t --- a/tests/test-diffstat.t Thu Feb 10 15:41:34 2011 +0300 +++ b/tests/test-diffstat.t Fri Feb 04 16:32:14 2011 -0300 @@ -46,3 +46,20 @@ 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(-) +