comparison mercurial/patch.py @ 13395:104c9ed93fc5

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(-) [...]
author Gastón Kleiman <gaston.kleiman@gmail.com>
date Fri, 04 Feb 2011 16:32:14 -0300
parents 039a964dbbb3
children d3c0e0033f13
comparison
equal deleted inserted replaced
13394:30e103dacd5f 13395:104c9ed93fc5
1527 yield ''.join(header) 1527 yield ''.join(header)
1528 if text: 1528 if text:
1529 yield text 1529 yield text
1530 1530
1531 def diffstatdata(lines): 1531 def diffstatdata(lines):
1532 diffre = re.compile('^diff .*-r [a-z0-9]+\s(.*)$')
1533
1532 filename, adds, removes = None, 0, 0 1534 filename, adds, removes = None, 0, 0
1533 for line in lines: 1535 for line in lines:
1534 if line.startswith('diff'): 1536 if line.startswith('diff'):
1535 if filename: 1537 if filename:
1536 isbinary = adds == 0 and removes == 0 1538 isbinary = adds == 0 and removes == 0
1537 yield (filename, adds, removes, isbinary) 1539 yield (filename, adds, removes, isbinary)
1538 # set numbers to 0 anyway when starting new file 1540 # set numbers to 0 anyway when starting new file
1539 adds, removes = 0, 0 1541 adds, removes = 0, 0
1540 if line.startswith('diff --git'): 1542 if line.startswith('diff --git'):
1541 filename = gitre.search(line).group(1) 1543 filename = gitre.search(line).group(1)
1542 else: 1544 elif line.startswith('diff -r'):
1543 # format: "diff -r ... -r ... filename" 1545 # format: "diff -r ... -r ... filename"
1544 filename = line.split(None, 5)[-1] 1546 filename = diffre.search(line).group(1)
1545 elif line.startswith('+') and not line.startswith('+++'): 1547 elif line.startswith('+') and not line.startswith('+++'):
1546 adds += 1 1548 adds += 1
1547 elif line.startswith('-') and not line.startswith('---'): 1549 elif line.startswith('-') and not line.startswith('---'):
1548 removes += 1 1550 removes += 1
1549 if filename: 1551 if filename: