patch for issue 3183

Laurens Holst laurens.nospam at grauw.nl
Thu Jan 5 11:44:33 CST 2012


Hey Hynek,

Please quote the patch in-line, if you attach it it is hard to respond 
to it.

Comment below:

> # HG changeset patch
> # User Hynek Cernoch<hynek at sdb.cz>
> # Date 1325736432 -3600
> # Node ID e78ecbdf430e66ec8af9af127953e344cfeae38d
> # Parent  1a36c9f53e11bf4fa97254828785f467d870eb8c
> opener: diff stat fixed for mq extension (issue3183)
>
> It is important to ignore two lines after lines starting with "diff"
> whereas "+++" or "---" is unimportant because a line starting
> with "++" or "--" can be part of the compared text.
>
> diff -r 1a36c9f53e11 -r e78ecbdf430e patch.py
> --- a/mercurial/patch.py	Thu Jan 05 04:18:39 2012 +0100
> +++ b/mercurial/patch.py	Thu Jan 05 05:07:12 2012 +0100
> @@ -1785,8 +1785,10 @@
>               isbinary = adds == 0 and removes == 0
>               results.append((filename, adds, removes, isbinary))
>
> +    linenum = 0
>       for line in lines:

Instead of maintaining a counter yourself, you can use:

for linenum, line in enumerate(lines)

>           if line.startswith('diff'):
> +            linenum = 0
>               addresult()
>               # set numbers to 0 anyway when starting new file
>               adds, removes = 0, 0
> @@ -1795,10 +1797,11 @@
>               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 linenum>  2:
>               adds += 1
> -        elif line.startswith('-') and not line.startswith('---'):
> +        elif line.startswith('-') and linenum>  2:
>               removes += 1
> +        linenum += 1
>       addresult()
>       return results



More information about the Mercurial-devel mailing list