[PATCH 3 of 4] bundle2: records processing results in the bundleoperation object

Durham Goode durham at fb.com
Thu Apr 3 21:01:53 CDT 2014


On 4/3/14 3:57 PM, pierre-yves.david at ens-lyon.org wrote:
> # HG changeset patch
> # User Pierre-Yves David <pierre-yves.david at fb.com>
> # Date 1396503470 25200
> #      Wed Apr 02 22:37:50 2014 -0700
> # Node ID 44096fd181296f228c1f2d869b53034b55d2bac9
> # Parent  d47181150c1edace8a5e5da51e99dffe17d52407
> bundle2: records processing results in the bundleoperation object
>
> Part handlers can now add records to the `bundleoperation` object This can be
> used to help other part or to let the caller of the unbundling process to react
> to the results.
>
> diff --git a/mercurial/bundle2.py b/mercurial/bundle2.py
> --- a/mercurial/bundle2.py
> +++ b/mercurial/bundle2.py
> @@ -181,10 +181,50 @@ def parthandler(parttype):
>           assert lparttype not in parthandlermapping
>           parthandlermapping[lparttype] = func
>           return func
>       return _decorator
>   
> +class unbundlerecords(object):
> +    """keep record of what happen during and unbundle
> +
> +    New record are added using `records.add('cat', obj)`. Where 'cat' is a
> +    category of record and obj is an arbitraty object.
> +
> +    `records['cat']` will return all entries of this category 'cat'.
> +
> +    Iterating on the object itself will yield `('category', obj)` tuple for all
> +    entries.
> +
> +    All iterations happens in chronological order.
> +    """
> +
> +    def __init__(self):
> +        self._categories = {}
> +        self._sequences = []
> +
> +    def add(self, category, entry):
> +        """add a new record of a given category.
> +
> +        The entry can then be retrieved in the list returned by
> +        self['category']."""
> +        category = str(category)
> +        self._categories.setdefault(category, []).append(entry)
> +        self._sequences.append((category, entry))
> +
> +    def __getitem__(self, cat):
> +        return tuple(self._categories.get(cat, ()))
> +
add() converts category to a str() before using it, but __getitem__() 
does not.  Seems inconsistent.  Why bother doing the str() at all?



More information about the Mercurial-devel mailing list