Mercurial > hg > mercurial-source
comparison mercurial/scmutil.py @ 40012:7a759ad2d06d
shortest: use nodetree for finding shortest node within revset
This speeds up `hg log -T '{shortest(node,1)}\n'` in my repo from 12s
to 4.5s. That's very close to the 4.1s it takes without the
disambiguation revset configured. My repo has 69.5k revisions, of
which 550 were in the configured revset ("not public()").
Differential Revision: https://phab.mercurial-scm.org/D4120
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Sun, 05 Aug 2018 00:42:07 -0700 |
parents | ad88726d6982 |
children | f98d3c57906f |
comparison
equal
deleted
inserted
replaced
40011:fcaffbd7e635 | 40012:7a759ad2d06d |
---|---|
32 match as matchmod, | 32 match as matchmod, |
33 obsolete, | 33 obsolete, |
34 obsutil, | 34 obsutil, |
35 pathutil, | 35 pathutil, |
36 phases, | 36 phases, |
37 policy, | |
37 pycompat, | 38 pycompat, |
38 revsetlang, | 39 revsetlang, |
39 similar, | 40 similar, |
40 url, | 41 url, |
41 util, | 42 util, |
49 | 50 |
50 if pycompat.iswindows: | 51 if pycompat.iswindows: |
51 from . import scmwindows as scmplatform | 52 from . import scmwindows as scmplatform |
52 else: | 53 else: |
53 from . import scmposix as scmplatform | 54 from . import scmposix as scmplatform |
55 | |
56 parsers = policy.importmod(r'parsers') | |
54 | 57 |
55 termsize = scmplatform.termsize | 58 termsize = scmplatform.termsize |
56 | 59 |
57 class status(tuple): | 60 class status(tuple): |
58 '''Named tuple with a list of files per status. The 'deleted', 'unknown' | 61 '''Named tuple with a list of files per status. The 'deleted', 'unknown' |
512 revs = repo.anyrevs([revset], user=True) | 515 revs = repo.anyrevs([revset], user=True) |
513 if cache is not None: | 516 if cache is not None: |
514 cache['disambiguationrevset'] = revs | 517 cache['disambiguationrevset'] = revs |
515 if cl.rev(node) in revs: | 518 if cl.rev(node) in revs: |
516 hexnode = hex(node) | 519 hexnode = hex(node) |
520 nodetree = None | |
521 if cache is not None: | |
522 nodetree = cache.get('disambiguationnodetree') | |
523 if not nodetree: | |
524 try: | |
525 nodetree = parsers.nodetree(cl.index, len(revs)) | |
526 except AttributeError: | |
527 # no native nodetree | |
528 pass | |
529 else: | |
530 for r in revs: | |
531 nodetree.insert(r) | |
532 if cache is not None: | |
533 cache['disambiguationnodetree'] = nodetree | |
534 if nodetree is not None: | |
535 length = max(nodetree.shortest(node), minlength) | |
536 prefix = hexnode[:length] | |
537 return disambiguate(prefix) | |
517 for length in range(minlength, len(hexnode) + 1): | 538 for length in range(minlength, len(hexnode) + 1): |
518 matches = [] | 539 matches = [] |
519 prefix = hexnode[:length] | 540 prefix = hexnode[:length] |
520 for rev in revs: | 541 for rev in revs: |
521 otherhexnode = repo[rev].hex() | 542 otherhexnode = repo[rev].hex() |