Mercurial > public > mercurial-scm > hg-stable
diff mercurial/patch.py @ 32360:0e29ce16ec38
diffstat: properly count lines starting in '--' or '++' (issue5479)
Lines that start in '--' or '++' were previously not counted
as deletions or additions in diffstat, resulting in incorrect
addition/deletion counts. The bug was present if the start
of the line, combined with the diff character resulted
in '---' or '+++'.
diffstatdata will now track, for each file, if it has moved
pas the header section by looking for a line beginning with
'@@'. Once that has happened, lines beginning with '-'
or '+' will be counted for deletions and additions. Once a
line beginning with 'diff' is found, the process starts over.
author | Andrew Zwicky <andrew.zwicky@gmail.com> |
---|---|
date | Wed, 17 May 2017 20:51:17 -0500 |
parents | 4462a981e8df |
children | 017ad85e5ac8 |
line wrap: on
line diff
--- a/mercurial/patch.py Fri May 19 12:38:34 2017 +0200 +++ b/mercurial/patch.py Wed May 17 20:51:17 2017 -0500 @@ -2654,19 +2654,28 @@ if filename: results.append((filename, adds, removes, isbinary)) + # inheader is used to track if a line is in the + # header portion of the diff. This helps properly account + # for lines that start with '--' or '++' + inheader = False + for line in lines: if line.startswith('diff'): addresult() - # set numbers to 0 anyway when starting new file + # starting a new file diff + # set numbers to 0 and reset inheader + inheader = True adds, removes, isbinary = 0, 0, False if line.startswith('diff --git a/'): filename = gitre.search(line).group(2) elif line.startswith('diff -r'): # format: "diff -r ... -r ... filename" filename = diffre.search(line).group(1) - elif line.startswith('+') and not line.startswith('+++ '): + elif line.startswith('@@'): + inheader = False + elif line.startswith('+') and not inheader: adds += 1 - elif line.startswith('-') and not line.startswith('--- '): + elif line.startswith('-') and not inheader: removes += 1 elif (line.startswith('GIT binary patch') or line.startswith('Binary file')):