[PATCH 4 of 6 V2] rust: hooking into Python code

Yuya Nishihara yuya at tcha.org
Fri Oct 12 01:03:42 EDT 2018


On Tue, 09 Oct 2018 17:22:48 +0200, Georges Racinet wrote:
> # HG changeset patch
> # User Georges Racinet <gracinet at anybox.fr>
> # Date 1538060144 -7200
> #      Thu Sep 27 16:55:44 2018 +0200
> # Node ID 210cd79d35d50e989a7eabbcebb4addde9365f9e
> # Parent  cf5c799e65a1225538fa1246887e2efd94c09acc
> # EXP-Topic rustancestors-rfc
> rust: hooking into Python code

> +class rustlazyancestors(lazyancestors):
> +
> +    def __init__(self, index, revs, stoprev=0, inclusive=False):

It's probably better to duplicate __nonzero__() instead of inheriting
lazyancestors and not initializing the super class.

> +        self._index = index
> +        self._stoprev = stoprev
> +        self._inclusive = inclusive
> +        # no need to prefilter out init revs that are smaller than stoprev,
> +        # it's done by rustlazyancestors constructor.
> +        # we need to convert to a list, because our ruslazyancestors
> +        # constructor (from C code) doesn't understand anything else yet
> +        self._initrevs = initrevs = list(revs)
> +
> +        self._containsseen = set()
> +        self._containsiter = parsers.rustlazyancestors(
> +            index, initrevs, stoprev, inclusive)

> diff -r cf5c799e65a1 -r 210cd79d35d5 mercurial/changelog.py
> --- a/mercurial/changelog.py	Thu Sep 27 16:56:15 2018 +0200
> +++ b/mercurial/changelog.py	Thu Sep 27 16:55:44 2018 +0200

> +    def ancestors(self, revs, *args, **kwargs):
> +        if util.safehasattr(parsers, 'rustlazyancestors') and self.filteredrevs:
> +            missing = self.filteredrevs.difference(revs)
> +            if missing:
> +                # raise the lookup error
> +                self.rev(min(missing))
> +        return super(changelog, self).ancestors(revs, *args, **kwargs)

>      def reachableroots(self, minroot, heads, roots, includepath=False):
>          return self.index.reachableroots2(minroot, heads, roots, includepath)
>  
> diff -r cf5c799e65a1 -r 210cd79d35d5 mercurial/revlog.py
> --- a/mercurial/revlog.py	Thu Sep 27 16:56:15 2018 +0200
> +++ b/mercurial/revlog.py	Thu Sep 27 16:55:44 2018 +0200
> @@ -747,6 +747,10 @@
>  
>          See the documentation for ancestor.lazyancestors for more details."""
>  
> +        if util.safehasattr(parsers, 'rustlazyancestors'):
> +            return ancestor.rustlazyancestors(
> +                self.index, revs,
> +                stoprev=stoprev, inclusive=inclusive)
>          return ancestor.lazyancestors(self.parentrevs, revs, stoprev=stoprev,
>                                        inclusive=inclusive)

I think these "if WITH_RUST" things can be handled in ancestors.py.


More information about the Mercurial-devel mailing list