##// END OF EJS Templates
branchmap: move validity logic in the object itself...
Pierre-Yves David -
r18132:db25bf1d default
parent child Browse files
Show More
@@ -9,7 +9,6 b' from node import bin, hex, nullid, nullr'
9 import encoding
9 import encoding
10
10
11 def read(repo):
11 def read(repo):
12 partial = branchcache()
13 try:
12 try:
14 f = repo.opener("cache/branchheads")
13 f = repo.opener("cache/branchheads")
15 lines = f.read().split('\n')
14 lines = f.read().split('\n')
@@ -20,7 +19,8 b' def read(repo):'
20 try:
19 try:
21 last, lrev = lines.pop(0).split(" ", 1)
20 last, lrev = lines.pop(0).split(" ", 1)
22 last, lrev = bin(last), int(lrev)
21 last, lrev = bin(last), int(lrev)
23 if lrev >= len(repo) or repo[lrev].node() != last:
22 partial = branchcache(tipnode=last, tiprev=lrev)
23 if not partial.validfor(repo):
24 # invalidate the cache
24 # invalidate the cache
25 raise ValueError('invalidating branch cache (tip differs)')
25 raise ValueError('invalidating branch cache (tip differs)')
26 for l in lines:
26 for l in lines:
@@ -32,8 +32,6 b' def read(repo):'
32 raise ValueError('invalidating branch cache because node '+
32 raise ValueError('invalidating branch cache because node '+
33 '%s does not exist' % node)
33 '%s does not exist' % node)
34 partial.setdefault(label, []).append(bin(node))
34 partial.setdefault(label, []).append(bin(node))
35 partial.tipnode = last
36 partial.tiprev = lrev
37 except KeyboardInterrupt:
35 except KeyboardInterrupt:
38 raise
36 raise
39 except Exception, inst:
37 except Exception, inst:
@@ -47,12 +45,9 b' def read(repo):'
47 def updatecache(repo):
45 def updatecache(repo):
48 repo = repo.unfiltered() # Until we get a smarter cache management
46 repo = repo.unfiltered() # Until we get a smarter cache management
49 cl = repo.changelog
47 cl = repo.changelog
50 tip = cl.tip()
51 partial = repo._branchcache
48 partial = repo._branchcache
52 if partial is not None and partial.tipnode == tip:
53 return
54
49
55 if partial is None or partial.tipnode not in cl.nodemap:
50 if partial is None or not partial.validfor(repo):
56 partial = read(repo)
51 partial = read(repo)
57
52
58 catip = repo._cacheabletip()
53 catip = repo._cacheabletip()
@@ -80,6 +75,17 b' class branchcache(dict):'
80 self.tipnode = tipnode
75 self.tipnode = tipnode
81 self.tiprev = tiprev
76 self.tiprev = tiprev
82
77
78 def validfor(self, repo):
79 """Is the cache content valide regarding a repo
80
81 - False when cached tipnode are unknown or if we detect a strip.
82 - True when cache is up to date or a subset of current repo."""
83 try:
84 return self.tipnode == repo.changelog.node(self.tiprev)
85 except IndexError:
86 return False
87
88
83 def write(self, repo):
89 def write(self, repo):
84 try:
90 try:
85 f = repo.opener("cache/branchheads", "w", atomictemp=True)
91 f = repo.opener("cache/branchheads", "w", atomictemp=True)
@@ -157,12 +163,8 b' class branchcache(dict):'
157 if not nodes:
163 if not nodes:
158 droppednodes.extend(nodes)
164 droppednodes.extend(nodes)
159 del self[branch]
165 del self[branch]
160 try:
166 if ((not self.validfor(repo)) or (self.tipnode in droppednodes)):
161 node = cl.node(self.tiprev)
167
162 except IndexError:
163 node = None
164 if ((self.tipnode != node)
165 or (self.tipnode in droppednodes)):
166 # cache key are not valid anymore
168 # cache key are not valid anymore
167 self.tipnode = nullid
169 self.tipnode = nullid
168 self.tiprev = nullrev
170 self.tiprev = nullrev
@@ -507,6 +507,7 b' amend'
507 $ hg -q commit -d '14 1' -m 'prepare amend'
507 $ hg -q commit -d '14 1' -m 'prepare amend'
508
508
509 $ hg --debug commit --amend -d '15 1' -m 'amend without changes' | grep keywords
509 $ hg --debug commit --amend -d '15 1' -m 'amend without changes' | grep keywords
510 invalidating branch cache (tip differs)
510 overwriting a expanding keywords
511 overwriting a expanding keywords
511 $ hg -q id
512 $ hg -q id
512 67d8c481a6be
513 67d8c481a6be
General Comments 0
You need to be logged in to leave comments. Login now