On Sun, Mar 12, 2017 at 01:32:05PM +0900, Matthieu Laneuville wrote: > # HG changeset patch > # User Matthieu Laneuville <mlaneuvi...@gmail.com> > # Date 1489292061 -32400 > # Sun Mar 12 13:14:21 2017 +0900 > # Node ID a79e4ec615dd14a65d1730e2795be41ffededc9e > # Parent 62939e0148f170b67ca8c7374f36c413b67fd387 > patch: diff --stat can parse lines starting with -- or ++ (issue5479) > > Lines starting with '--' or '++' would look like headers when removed or > added, > and therefore ignored by diffstatdata. This patch allow diffstatdata to make > the > difference between header lines (i.e. first '---' and '+++' lines after a line > starting with 'diff') and usual lines starting with '--' or '++'. > > diff -r 62939e0148f1 -r a79e4ec615dd mercurial/patch.py > --- a/mercurial/patch.py Wed Mar 08 18:11:41 2017 -0500 > +++ b/mercurial/patch.py Sun Mar 12 13:14:21 2017 +0900 > @@ -2597,6 +2597,8 @@ > > for line in lines: > if line.startswith('diff'): > + seen_header_add = False > + seen_header_rem = False > addresult() > # set numbers to 0 anyway when starting new file > adds, removes, isbinary = 0, 0, False > @@ -2605,9 +2607,13 @@ > 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('+++ ') and not seen_header_add: > + seen_header_add = True > + elif line.startswith('--- ') and not seen_header_rem: > + seen_header_rem = True > + elif line.startswith('+') and seen_header_add: I can't think of anything but a misformatted patch, but I think we should check for both seen_header_add and seen_header_rem to determine we have seen the header:
seen_header = seen_header or (seen_header_rem and seen_header_add) elif line.startswith('+') and seen_header: ... elif line.startswith('-') and seen_header: ... that makes it clear that we start counting after we have seen the full header --- and +++ lines. As an alternative we might be able to take the first occurence of @@ ... @@ to denote the end of the header as it's part of unified diffs. _______________________________________________ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel