Patchwork [2,of,2,V2] stack: add indexedrevs property to contain a list of stack revs and its base

login
register
mail settings
Submitter Anton Shestakov
Date Sept. 25, 2019, 9:58 a.m.
Message ID <b85dea9c83a01ae6c604.1569405526@df1>
Download mbox | patch
Permalink /patch/41750/
State New
Headers show

Comments

Anton Shestakov - Sept. 25, 2019, 9:58 a.m.
# HG changeset patch
# User Anton Shestakov <av6@dwimlabs.net>
# Date 1569139071 -25200
#      Sun Sep 22 14:57:51 2019 +0700
# Node ID b85dea9c83a01ae6c6045b7dc5e4aa10dfbec8c7
# Parent  2c9d35029c27f3d0e63afc8f618268f079f337c3
# 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 property specifically for this task.

indexedrevs also contains stack base at index 0, so actual stack revisions
start from index 1.
Yuya Nishihara - Sept. 26, 2019, 11:13 p.m.
On Wed, 25 Sep 2019 17:58:46 +0800, Anton Shestakov wrote:
> # HG changeset patch
> # User Anton Shestakov <av6@dwimlabs.net>
> # Date 1569139071 -25200
> #      Sun Sep 22 14:57:51 2019 +0700
> # Node ID b85dea9c83a01ae6c6045b7dc5e4aa10dfbec8c7
> # Parent  2c9d35029c27f3d0e63afc8f618268f079f337c3
> # 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 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
> @@ -31,3 +31,11 @@ class stack(object):
>          return bool(self.revs)
>  
>      __bool__ = __nonzero__
> +
> +    @property
> +    def indexedrevs(self):
> +        if self.revs:
> +            base = self._repo[self.revs.first()].p1()
> +        else:
> +            base = self._repo['.']
> +        return [base.rev()] + list(self.revs)

It might be nit-picky, but I feel making this a plain function is better
than pretending a property. If it looked like a property, I would write
for i in ...: stack.indexedrevs[i], which is expensive.

Patch

diff --git a/mercurial/stack.py b/mercurial/stack.py
--- a/mercurial/stack.py
+++ b/mercurial/stack.py
@@ -31,3 +31,11 @@  class stack(object):
         return bool(self.revs)
 
     __bool__ = __nonzero__
+
+    @property
+    def indexedrevs(self):
+        if self.revs:
+            base = self._repo[self.revs.first()].p1()
+        else:
+            base = self._repo['.']
+        return [base.rev()] + list(self.revs)