[PATCH] annotate: split the logic to two functions

Pierre-Yves David pierre-yves.david at ens-lyon.org
Fri Jun 17 13:12:17 EDT 2016



On 06/11/2016 03:00 AM, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark at fb.com>
> # Date 1465605860 -3600
> #      Sat Jun 11 01:44:20 2016 +0100
> # Node ID ce07999816426aeb56965c9ae9ffd25f82ce5102
> # Parent  baab9ea4426ca658d191119bfa8715eb40a39d82
> # Available At https://bitbucket.org/quark-zju/hg-draft
> #              hg pull https://bitbucket.org/quark-zju/hg-draft -r ce0799981642
> annotate: split the logic to two functions
> 
> Before this patch, fctx.annotate will visit all reachable revisions in its
> dfs (depth-first search) process.
> 
> This patch splits the search logic to a standalone function, receiving
> "parents", "decorate", "pair" as parameters, making it much more flexible.
> The change is minimal but opens up a lot of possibilities.
> 
> Customizing "parents" will allow us to:
> - stop dfs early, ex. the user only care about "draft()"
> - manually mark a "move", ex. the user forgot "hg mv"
> - enforce linear history, ex. the user just want to see merges
> - skip revs, also doable using "pair"
> 
> Customizing "decorate" will allow us to:
> - change "content", ex. the user wants to annotate a single line
> - add other fields to the tuple associated with each line
> 
> Customizing "pair" will allow us to:
> - choose a diff algorithm, in git world, diff algorithm is an option
> - ignore non-whitespace changes, ex. ignore iteritems -> items
> 
> diff --git a/mercurial/context.py b/mercurial/context.py
> --- a/mercurial/context.py
> +++ b/mercurial/context.py
> @@ -993,6 +993,9 @@
>                  ac = cl.ancestors([introrev], inclusive=True)
>              base._ancestrycontext = ac
>  
> +        return base._annotate(parents, decorate, pair)
> +
> +    def _annotate(base, parents, decorate, pair):
>          # This algorithm would prefer to be recursive, but Python is a
>          # bit recursion-hostile. Instead we do an iterative
>          # depth-first search.

I would like to suguest to take advantage of this rework to document the
thing. As 'annotate' and '_annotate' are each doing a defined subset of
the logic, having a docstring stating there purpose would help us to
ensure the split is right and en-light future contributor (and also help
me to review this patch).

Can you send a V2?

Cheers,

-- 
Pierre-Yves DAvid


More information about the Mercurial-devel mailing list