comparison mercurial/branchmap.py @ 28364:f1460af18c50

branchmap: check node against changelog instead of repo Testing 'node in repo' requires constructing a changectx, which is a little expensive. Testing 'repo.changelog.hasnode(node)' is notably faster. This saves 10-20ms off of every command, when testing a few thousand nodes from the branch cache. I considered changing the implementation of localrepository.__contains__ so every place would benefit from the change, but since localrepository.__contains__ uses changectx to check if the commit exists, it means it supports a wider range of possible inputs (like revs, hashes, '.', etc), so it seemed unnecessarily risky.
author Durham Goode <durham@fb.com>
date Mon, 07 Mar 2016 17:26:47 -0800
parents 56b2bcea2529
children 0706d60d070f
comparison
equal deleted inserted replaced
28363:1f94ef2bd88d 28364:f1460af18c50
53 partial = branchcache(tipnode=last, tiprev=lrev, 53 partial = branchcache(tipnode=last, tiprev=lrev,
54 filteredhash=filteredhash) 54 filteredhash=filteredhash)
55 if not partial.validfor(repo): 55 if not partial.validfor(repo):
56 # invalidate the cache 56 # invalidate the cache
57 raise ValueError('tip differs') 57 raise ValueError('tip differs')
58 cl = repo.changelog
58 for l in lines: 59 for l in lines:
59 if not l: 60 if not l:
60 continue 61 continue
61 node, state, label = l.split(" ", 2) 62 node, state, label = l.split(" ", 2)
62 if state not in 'oc': 63 if state not in 'oc':
63 raise ValueError('invalid branch state') 64 raise ValueError('invalid branch state')
64 label = encoding.tolocal(label.strip()) 65 label = encoding.tolocal(label.strip())
65 if not node in repo:
66 raise ValueError('node %s does not exist' % node)
67 node = bin(node) 66 node = bin(node)
67 if not cl.hasnode(node):
68 raise ValueError('node %s does not exist' % hex(node))
68 partial.setdefault(label, []).append(node) 69 partial.setdefault(label, []).append(node)
69 if state == 'c': 70 if state == 'c':
70 partial._closednodes.add(node) 71 partial._closednodes.add(node)
71 except KeyboardInterrupt: 72 except KeyboardInterrupt:
72 raise 73 raise