comparison mercurial/branchmap.py @ 21031:05cfcecb3aef

branchmap: log events related to branch cache The blackblox log will now contain log events when the branch caches are updated and written.
author Gregory Szorc <gregory.szorc@gmail.com>
date Sat, 22 Mar 2014 17:14:37 -0700
parents d9e1c167943b
children c20843aee8a4
comparison
equal deleted inserted replaced
21030:9ea132aee96c 21031:05cfcecb3aef
6 # GNU General Public License version 2 or any later version. 6 # GNU General Public License version 2 or any later version.
7 7
8 from node import bin, hex, nullid, nullrev 8 from node import bin, hex, nullid, nullrev
9 import encoding 9 import encoding
10 import util 10 import util
11 import time
11 12
12 def _filename(repo): 13 def _filename(repo):
13 """name of a branchcache file for a given repo or repoview""" 14 """name of a branchcache file for a given repo or repoview"""
14 filename = "cache/branch2" 15 filename = "cache/branch2"
15 if repo.filtername: 16 if repo.filtername:
204 f = repo.opener(_filename(repo), "w", atomictemp=True) 205 f = repo.opener(_filename(repo), "w", atomictemp=True)
205 cachekey = [hex(self.tipnode), str(self.tiprev)] 206 cachekey = [hex(self.tipnode), str(self.tiprev)]
206 if self.filteredhash is not None: 207 if self.filteredhash is not None:
207 cachekey.append(hex(self.filteredhash)) 208 cachekey.append(hex(self.filteredhash))
208 f.write(" ".join(cachekey) + '\n') 209 f.write(" ".join(cachekey) + '\n')
210 nodecount = 0
209 for label, nodes in sorted(self.iteritems()): 211 for label, nodes in sorted(self.iteritems()):
210 for node in nodes: 212 for node in nodes:
213 nodecount += 1
211 if node in self._closednodes: 214 if node in self._closednodes:
212 state = 'c' 215 state = 'c'
213 else: 216 else:
214 state = 'o' 217 state = 'o'
215 f.write("%s %s %s\n" % (hex(node), state, 218 f.write("%s %s %s\n" % (hex(node), state,
216 encoding.fromlocal(label))) 219 encoding.fromlocal(label)))
217 f.close() 220 f.close()
221 repo.ui.log('branchcache',
222 'wrote %s branch cache with %d labels and %d nodes\n',
223 repo.filtername, len(self), nodecount)
218 except (IOError, OSError, util.Abort): 224 except (IOError, OSError, util.Abort):
219 # Abort may be raise by read only opener 225 # Abort may be raise by read only opener
220 pass 226 pass
221 227
222 def update(self, repo, revgen): 228 def update(self, repo, revgen):
223 """Given a branchhead cache, self, that may have extra nodes or be 229 """Given a branchhead cache, self, that may have extra nodes or be
224 missing heads, and a generator of nodes that are strictly a superset of 230 missing heads, and a generator of nodes that are strictly a superset of
225 heads missing, this function updates self to be correct. 231 heads missing, this function updates self to be correct.
226 """ 232 """
233 starttime = time.time()
227 cl = repo.changelog 234 cl = repo.changelog
228 # collect new branch entries 235 # collect new branch entries
229 newbranches = {} 236 newbranches = {}
230 getbranchinfo = cl.branchinfo 237 getbranchinfo = cl.branchinfo
231 for r in revgen: 238 for r in revgen:
270 tiprev = max(cl.rev(node) for node in heads) 277 tiprev = max(cl.rev(node) for node in heads)
271 if tiprev > self.tiprev: 278 if tiprev > self.tiprev:
272 self.tipnode = cl.node(tiprev) 279 self.tipnode = cl.node(tiprev)
273 self.tiprev = tiprev 280 self.tiprev = tiprev
274 self.filteredhash = self._hashfiltered(repo) 281 self.filteredhash = self._hashfiltered(repo)
282
283 duration = time.time() - starttime
284 repo.ui.log('branchcache', 'updated %s branch cache in %.4f seconds\n',
285 repo.filtername, duration)