Mercurial > public > mercurial-scm > hg
comparison mercurial/scmutil.py @ 51249:fd1aa5e18f75
rust-revlog: using the ad-hoc `NodeTree` in scmutil
Now that we have an independent `NodeTree` class able to work natively
on the pure Rust index, we use it in `mercurial.scmutil`, with automatic
invalidation after mutation of the index.
This code path is tested by `test-revisions.t` and `test-template-functions.t`
author | Georges Racinet <georges.racinet@octobus.net> |
---|---|
date | Mon, 30 Oct 2023 21:28:30 +0100 |
parents | 18c8c18993f0 |
children | 83c6dceeb10d |
comparison
equal
deleted
inserted
replaced
51248:0409bd6ba663 | 51249:fd1aa5e18f75 |
---|---|
553 if cl.rev(node) in revs: | 553 if cl.rev(node) in revs: |
554 hexnode = hex(node) | 554 hexnode = hex(node) |
555 nodetree = None | 555 nodetree = None |
556 if cache is not None: | 556 if cache is not None: |
557 nodetree = cache.get(b'disambiguationnodetree') | 557 nodetree = cache.get(b'disambiguationnodetree') |
558 is_invalidated = getattr(nodetree, 'is_invalidated', lambda: False) | |
559 if is_invalidated(): | |
560 nodetree = None | |
558 if not nodetree: | 561 if not nodetree: |
559 if hasattr(parsers, 'nodetree'): | 562 if hasattr(parsers, 'nodetree') and isinstance( |
560 # The CExt is the only implementation to provide a nodetree | 563 cl.index, parsers.index |
561 # class so far. | 564 ): |
562 index = cl.index | 565 index = cl.index |
563 if hasattr(index, 'get_cindex'): | |
564 # the rust wrapped need to give access to its internal index | |
565 index = index.get_cindex() | |
566 nodetree = parsers.nodetree(index, len(revs)) | 566 nodetree = parsers.nodetree(index, len(revs)) |
567 for r in revs: | 567 elif getattr(cl.index, 'is_rust', False): |
568 nodetree.insert(r) | 568 nodetree = rustrevlog.NodeTree(cl.index) |
569 if cache is not None: | 569 |
570 cache[b'disambiguationnodetree'] = nodetree | |
571 if nodetree is not None: | 570 if nodetree is not None: |
571 for r in revs: | |
572 nodetree.insert(r) | |
573 if cache is not None: | |
574 cache[b'disambiguationnodetree'] = nodetree | |
572 length = max(nodetree.shortest(node), minlength) | 575 length = max(nodetree.shortest(node), minlength) |
573 prefix = hexnode[:length] | 576 prefix = hexnode[:length] |
574 return disambiguate(prefix) | 577 return disambiguate(prefix) |
575 for length in range(minlength, len(hexnode) + 1): | 578 for length in range(minlength, len(hexnode) + 1): |
576 matches = [] | 579 matches = [] |