comparison mercurial/templater.py @ 30232:362740e05460 stable

templater: use unfiltered changelog to calculate shortest() at constant time cl._partialmatch() can be pretty slow if hidden revisions are involved. This patch cancels the slowdown introduced by the previous patch by using an unfiltered changelog, which means shortest(node) isn't always the shortest. The result isn't perfect, but seems okay as long as shortest(node) is short enough to type and can be used as an identifier. (with hidden revisions) % hg log -R hg-committed -r0:20000 -T '{node|shortest}\n' --time > /dev/null (.^^) time: real 1.530 secs (user 1.480+0.000 sys 0.040+0.000) (.^) time: real 43.080 secs (user 43.060+0.000 sys 0.030+0.000) (.) time: real 1.680 secs (user 1.650+0.000 sys 0.020+0.000)
author Yuya Nishihara <yuya@tcha.org>
date Tue, 25 Oct 2016 21:49:30 +0900
parents 741e5d7f282d
children 318a24b52eeb
comparison
equal deleted inserted replaced
30231:741e5d7f282d 30232:362740e05460
835 if len(args) > 1: 835 if len(args) > 1:
836 minlength = evalinteger(context, mapping, args[1], 836 minlength = evalinteger(context, mapping, args[1],
837 # i18n: "shortest" is a keyword 837 # i18n: "shortest" is a keyword
838 _("shortest() expects an integer minlength")) 838 _("shortest() expects an integer minlength"))
839 839
840 cl = mapping['ctx']._repo.changelog 840 # _partialmatch() of filtered changelog could take O(len(repo)) time,
841 # which would be unacceptably slow. so we look for hash collision in
842 # unfiltered space, which means some hashes may be slightly longer.
843 cl = mapping['ctx']._repo.unfiltered().changelog
841 def isvalid(test): 844 def isvalid(test):
842 try: 845 try:
843 if cl._partialmatch(test) is None: 846 if cl._partialmatch(test) is None:
844 return False 847 return False
845 848