[PATCH 4 of 6 V2] rust: hooking into Python code
Georges Racinet
gracinet at anybox.fr
Fri Oct 12 09:39:18 UTC 2018
On 10/12/2018 07:03 AM, Yuya Nishihara wrote:
> 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.
Yes, I was wondering about that. Will do it in PATCH 6 v3.
>
>> + 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.
The reason was that ancestor.lazyancestors is initialized from the
parents function, whereas the Rust bascked implementation needs the
index. I'd be glad to push that down to ancestors.py and harmonize over
passing the index, but that's a bigger change.
--
Georges Racinet
Anybox SAS, http://anybox.fr
Téléphone: +33 6 51 32 07 27
GPG: B59E 22AB B842 CAED 77F7 7A7F C34F A519 33AB 0A35, sur serveurs publics
More information about the Mercurial-devel
mailing list