[PATCH 1/1] churn: add --paths option

Benoit Boissinot benoit.boissinot at ens-lyon.org
Fri Jan 9 18:44:12 CST 2009


On Fri, Jan 09, 2009 at 06:19:24PM -0500, Marc Bevand wrote:
> I enhanced the churn extension to add a new option:
> 
>   -p --paths       group by file paths or path prefixes
> 
[snip]

> I also added a churn config option:
> 
>   [churn]
>   prefixes = foo bar
> 
> It will cause -p to group the changesets according to the specified path
> prefixes:
> 
>   $ hg churn -p
>   foo      4 **************************************************
>   bar      1 ***********
> 
> Of course -p can also be combined with -c to count by number of changesets.
> The patch applies cleanly to the current tip (dafcc96c1285). I'd like to
> have it applied. Comments ?

Not sure about the ui, there may be a better way to add this. Any ideas?

> -def changedlines(ui, repo, ctx1, ctx2):
> -    lines = 0
> +def changedlines(ui, repo, ctx1, ctx2, per_file):
>      diff = ''.join(patch.diff(repo, ctx1.node(), ctx2.node()))
> -    for l in diff.split('\n'):
> -        if (l.startswith("+") and not l.startswith("+++ ") or
> -            l.startswith("-") and not l.startswith("--- ")):
> -            lines += 1
> -    return lines
> +    if per_file:
> +        # report per-file statistics
> +        filename = None
> +        res = {}
> +        p = re.compile('^diff -r [^ ]+ -r [^ ]+ (.+)')
> +        for l in diff.split('\n'):
> +            if l.startswith("diff "):
> +                if filename is not None:
> +                    res[filename] = lines
> +                m = p.match(l)
> +                filename = m.group(1)
> +                lines = 0
> +            elif (l.startswith("+") and not l.startswith("+++ ") or
> +                l.startswith("-") and not l.startswith("--- ")):
> +                lines += 1
> +        if filename is not None:
> +            res[filename] = lines
> +        return res
> +    else:
> +        # report overall number of changed lines
> +        lines = 0
> +        for l in diff.split('\n'):
> +            if (l.startswith("+") and not l.startswith("+++ ") or
> +                l.startswith("-") and not l.startswith("--- ")):
> +                lines += 1
> +        return lines

You really want to use patch.diffstatdatat() here :)
(separate patch welcome)

regards,

Benoit
-- 
:wq


More information about the Mercurial mailing list