Patchwork [1,of,4,V2] revset: add helper function to get tree depth

login
register
mail settings
Submitter Alexander Plavin
Date Aug. 9, 2013, 6:54 p.m.
Message ID <10862e95f769e7555ee5.1376074495@debian-alexander.dolgopa>
Download mbox | patch
Permalink /patch/2104/
State Changes Requested
Headers show

Comments

Alexander Plavin - Aug. 9, 2013, 6:54 p.m.
# HG changeset patch
# User Alexander Plavin <alexander@plav.in>
# Date 1376074378 -14400
#      Fri Aug 09 22:52:58 2013 +0400
# Node ID 10862e95f769e7555ee54c0647595d508d5672ef
# Parent  da2209742e39683a5a42672e69133b1a20898973
revset: add helper function to get tree depth
Augie Fackler - Aug. 12, 2013, 2:29 p.m.
On Fri, Aug 09, 2013 at 10:54:55PM +0400, Alexander Plavin wrote:
> # HG changeset patch
> # User Alexander Plavin <alexander@plav.in>
> # Date 1376074378 -14400
> #      Fri Aug 09 22:52:58 2013 +0400
> # Node ID 10862e95f769e7555ee54c0647595d508d5672ef
> # Parent  da2209742e39683a5a42672e69133b1a20898973
> revset: add helper function to get tree depth

I might mention that it's the depth of the parse tree for the revset -
that wasn't immediately obvious to me.

>
> diff -r da2209742e39 -r 10862e95f769 mercurial/revset.py
> --- a/mercurial/revset.py	Fri Jul 19 02:09:13 2013 +0400
> +++ b/mercurial/revset.py	Fri Aug 09 22:52:58 2013 +0400
> @@ -1972,5 +1972,11 @@
>      output = '\n'.join(('  '*l + s) for l, s in lines)
>      return output
>
> +def depth(tree):
> +    if isinstance(tree, tuple):
> +        return max(map(depth, tree)) + 1
> +    else:
> +        return 0
> +
>  # tell hggettext to extract docstrings from these functions:
>  i18nfunctions = symbols.values()
> _______________________________________________
> Mercurial-devel mailing list
> Mercurial-devel@selenic.com
> http://selenic.com/mailman/listinfo/mercurial-devel
Alexander Plavin - Aug. 12, 2013, 6:03 p.m.
12.08.2013, 18:29, "Augie Fackler" <raf@durin42.com>:
> On Fri, Aug 09, 2013 at 10:54:55PM +0400, Alexander Plavin wrote:
>
>>  # HG changeset patch
>>  # User Alexander Plavin <alexander@plav.in>
>>  # Date 1376074378 -14400
>>  #      Fri Aug 09 22:52:58 2013 +0400
>>  # Node ID 10862e95f769e7555ee54c0647595d508d5672ef
>>  # Parent  da2209742e39683a5a42672e69133b1a20898973
>>  revset: add helper function to get tree depth
>
> I might mention that it's the depth of the parse tree for the revset -
> that wasn't immediately obvious to me.

Ok, will add this. But what else could it possibly mean? :)

>
>>  diff -r da2209742e39 -r 10862e95f769 mercurial/revset.py
>>  --- a/mercurial/revset.py Fri Jul 19 02:09:13 2013 +0400
>>  +++ b/mercurial/revset.py Fri Aug 09 22:52:58 2013 +0400
>>  @@ -1972,5 +1972,11 @@
>>       output = '\n'.join(('  '*l + s) for l, s in lines)
>>       return output
>>
>>  +def depth(tree):
>>  +    if isinstance(tree, tuple):
>>  +        return max(map(depth, tree)) + 1
>>  +    else:
>>  +        return 0
>>  +
>>   # tell hggettext to extract docstrings from these functions:
>>   i18nfunctions = symbols.values()
>>  _______________________________________________
>>  Mercurial-devel mailing list
>>  Mercurial-devel@selenic.com
>>  http://selenic.com/mailman/listinfo/mercurial-devel

Patch

diff -r da2209742e39 -r 10862e95f769 mercurial/revset.py
--- a/mercurial/revset.py	Fri Jul 19 02:09:13 2013 +0400
+++ b/mercurial/revset.py	Fri Aug 09 22:52:58 2013 +0400
@@ -1972,5 +1972,11 @@ 
     output = '\n'.join(('  '*l + s) for l, s in lines)
     return output
 
+def depth(tree):
+    if isinstance(tree, tuple):
+        return max(map(depth, tree)) + 1
+    else:
+        return 0
+
 # tell hggettext to extract docstrings from these functions:
 i18nfunctions = symbols.values()