[PATCH 3 of 4] stack: add indexedrevs property to contain a list of stack revs and its base
Yuya Nishihara
yuya at tcha.org
Mon Sep 23 08:55:04 EDT 2019
On Mon, 23 Sep 2019 10:39:51 +0700, Anton Shestakov wrote:
> # HG changeset patch
> # User Anton Shestakov <av6 at dwimlabs.net>
> # Date 1569139071 -25200
> # Sun Sep 22 14:57:51 2019 +0700
> # Node ID 07af98a1e730c1ffa6911c9ab2cdcc06d4ffe52d
> # Parent 6430e0ae6d86343980578e36fa26c5e4893170fd
> # EXP-Topic stack-object
> stack: add indexedrevs property to contain a list of stack revs and its base
>
> Sometimes we need to access a specific stack revision by its index, but
> stack.revs doesn't support indexing. Obviously we can just do list(st.revs),
> but it's more convenient to have a cached property specifically for this task.
>
> indexedrevs also contains stack base at index 0, so actual stack revisions
> start from index 1.
>
> diff --git a/mercurial/stack.py b/mercurial/stack.py
> --- a/mercurial/stack.py
> +++ b/mercurial/stack.py
> @@ -8,6 +8,7 @@
> from __future__ import absolute_import
>
> from . import (
> + util,
> )
>
> class stack(object):
> @@ -34,3 +35,11 @@ class stack(object):
> return bool(self.revs)
>
> __bool__ = __nonzero__
> +
> + @util.propertycache
> + def indexedrevs(self):
> + if self.revs:
> + base = self._repo[self.revs.first()].p1()
> + else:
> + base = self._repo['.']
> + return [base.rev()] + list(self.revs)
Better to not cache it? self.revs may be reordered since it is a public
interface, and the indexedrevs could get wrong.
More information about the Mercurial-devel
mailing list