D4039: shortest: cache disambiguation revset
This revision was automatically updated to reflect the committed changes. Closed by commit rHG3588e41f796d: shortest: cache disambiguation revset (authored by martinvonz, committed by ). REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D4039?vs=9887=9894 REVISION DETAIL https://phab.mercurial-scm.org/D4039 AFFECTED FILES mercurial/scmutil.py mercurial/templatefuncs.py CHANGE DETAILS diff --git a/mercurial/templatefuncs.py b/mercurial/templatefuncs.py --- a/mercurial/templatefuncs.py +++ b/mercurial/templatefuncs.py @@ -596,7 +596,7 @@ yield sep yield argstr -@templatefunc('shortest(node, minlength=4)', requires={'repo'}) +@templatefunc('shortest(node, minlength=4)', requires={'repo', 'cache'}) def shortest(context, mapping, args): """Obtain the shortest representation of a node.""" @@ -629,8 +629,9 @@ return hexnode if not node: return hexnode +cache = context.resource(mapping, 'cache') try: -return scmutil.shortesthexnodeidprefix(repo, node, minlength) +return scmutil.shortesthexnodeidprefix(repo, node, minlength, cache) except error.RepoLookupError: return hexnode diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py --- a/mercurial/scmutil.py +++ b/mercurial/scmutil.py @@ -462,8 +462,12 @@ repo.changelog.rev(node) # make sure node isn't filtered return node -def shortesthexnodeidprefix(repo, node, minlength=1): -"""Find the shortest unambiguous prefix that matches hexnode.""" +def shortesthexnodeidprefix(repo, node, minlength=1, cache=None): +"""Find the shortest unambiguous prefix that matches hexnode. + +If "cache" is not None, it must be a dictionary that can be used for +caching between calls to this method. +""" # _partialmatch() of filtered changelog could take O(len(repo)) time, # which would be unacceptably slow. so we look for hash collision in # unfiltered space, which means some hashes may be slightly longer. @@ -491,7 +495,13 @@ revset = repo.ui.config('experimental', 'revisions.disambiguatewithin') if revset: -revs = repo.anyrevs([revset], user=True) +revs = None +if cache is not None: +revs = cache.get('disambiguationrevset') +if revs is None: +revs = repo.anyrevs([revset], user=True) +if cache is not None: +cache['disambiguationrevset'] = revs if cl.rev(node) in revs: hexnode = hex(node) for length in range(minlength, len(hexnode) + 1): To: martinvonz, #hg-reviewers Cc: yuja, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D4039: shortest: cache disambiguation revset
martinvonz added a comment. I've added support for passing in a cache, so this is ready for review again, thanks. REPOSITORY rHG Mercurial REVISION DETAIL https://phab.mercurial-scm.org/D4039 To: martinvonz, #hg-reviewers Cc: yuja, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel
D4039: shortest: cache disambiguation revset
martinvonz updated this revision to Diff 9887. martinvonz edited the summary of this revision. martinvonz retitled this revision from "[RFC] shortest: cache disambiguation revset" to "shortest: cache disambiguation revset". REPOSITORY rHG Mercurial CHANGES SINCE LAST UPDATE https://phab.mercurial-scm.org/D4039?vs=9755=9887 REVISION DETAIL https://phab.mercurial-scm.org/D4039 AFFECTED FILES mercurial/scmutil.py mercurial/templatefuncs.py CHANGE DETAILS diff --git a/mercurial/templatefuncs.py b/mercurial/templatefuncs.py --- a/mercurial/templatefuncs.py +++ b/mercurial/templatefuncs.py @@ -596,7 +596,7 @@ yield sep yield argstr -@templatefunc('shortest(node, minlength=4)', requires={'repo'}) +@templatefunc('shortest(node, minlength=4)', requires={'repo', 'cache'}) def shortest(context, mapping, args): """Obtain the shortest representation of a node.""" @@ -629,8 +629,9 @@ return hexnode if not node: return hexnode +cache = context.resource(mapping, 'cache') try: -return scmutil.shortesthexnodeidprefix(repo, node, minlength) +return scmutil.shortesthexnodeidprefix(repo, node, minlength, cache) except error.RepoLookupError: return hexnode diff --git a/mercurial/scmutil.py b/mercurial/scmutil.py --- a/mercurial/scmutil.py +++ b/mercurial/scmutil.py @@ -462,8 +462,12 @@ repo.changelog.rev(node) # make sure node isn't filtered return node -def shortesthexnodeidprefix(repo, node, minlength=1): -"""Find the shortest unambiguous prefix that matches hexnode.""" +def shortesthexnodeidprefix(repo, node, minlength=1, cache=None): +"""Find the shortest unambiguous prefix that matches hexnode. + +If "cache" is not None, it must be a dictionary that can be used for +caching between calls to this method. +""" # _partialmatch() of filtered changelog could take O(len(repo)) time, # which would be unacceptably slow. so we look for hash collision in # unfiltered space, which means some hashes may be slightly longer. @@ -491,7 +495,13 @@ revset = repo.ui.config('experimental', 'revisions.disambiguatewithin') if revset: -revs = repo.anyrevs([revset], user=True) +revs = None +if cache is not None: +revs = cache.get('disambiguationrevset') +if revs is None: +revs = repo.anyrevs([revset], user=True) +if cache is not None: +cache['disambiguationrevset'] = revs if cl.rev(node) in revs: hexnode = hex(node) for length in range(minlength, len(hexnode) + 1): To: martinvonz, #hg-reviewers Cc: yuja, mercurial-devel ___ Mercurial-devel mailing list Mercurial-devel@mercurial-scm.org https://www.mercurial-scm.org/mailman/listinfo/mercurial-devel