[PATCH 1 of 5] revlog: make commonancestorsheads accept revision numbers
Pierre-Yves David
pierre-yves.david at ens-lyon.org
Tue Nov 1 23:05:32 UTC 2016
On 11/01/2016 09:51 AM, Jun Wu wrote:
> # HG changeset patch
> # User Jun Wu <quark at fb.com>
> # Date 1477987839 0
> # Tue Nov 01 08:10:39 2016 +0000
> # Node ID ac063914b3a3c01f1d7ed253c73113903fccb7a9
> # Parent 264f00b3e5f045ac5b58d79e2a3976585f4e7739
> # Available At https://bitbucket.org/quark-zju/hg-draft
> # hg pull https://bitbucket.org/quark-zju/hg-draft -r ac063914b3a3
> revlog: make commonancestorsheads accept revision numbers
>
> This avoids overhead converting arguments between revision numbers and nodes
> in the following patches.
I think I would rather see a two methods, one for revs and one for nodes
that would keep the signature of each function clearer. One of the
function would probably all into the other one to keep the code common.
What do you think?
> diff --git a/mercurial/revlog.py b/mercurial/revlog.py
> --- a/mercurial/revlog.py
> +++ b/mercurial/revlog.py
> @@ -885,14 +885,24 @@ class revlog(object):
>
> def commonancestorsheads(self, a, b):
> - """calculate all the heads of the common ancestors of nodes a and b"""
> - a, b = self.rev(a), self.rev(b)
> + """calculate all the heads of the common ancestors of a and b
> +
> + a and b can be both revision numbers, or nodes. The return value will
> + be the same type.
> + """
> + isnode = not (isinstance(a, int) and isinstance(b, int))
> + if isnode:
> + a, b = self.rev(a), self.rev(b)
> try:
> ancs = self.index.commonancestorsheads(a, b)
> except (AttributeError, OverflowError): # C implementation failed
> ancs = ancestor.commonancestorsheads(self.parentrevs, a, b)
> - return map(self.node, ancs)
> + if isnode:
> + ancs = map(self.node, ancs)
> + return ancs
>
> def isancestor(self, a, b):
> - """return True if node a is an ancestor of node b
> + """return True if a is an ancestor of b
> +
> + a and b can be both revision numbers, or nodes.
>
> The implementation of this is trivial but the use of
--
Pierre-Yves David
More information about the Mercurial-devel
mailing list