##// END OF EJS Templates
bookmarks: turn repo._bookmarks into a propertycache
Nicolas Dumazet -
r10105:dc5b5cc5 default
parent child Browse files
Show More
@@ -43,15 +43,13 b' def parse(repo):'
43 43 The parsed dictionary is cached until a write() operation is done.
44 44 '''
45 45 try:
46 if repo._bookmarks:
47 return repo._bookmarks
48 repo._bookmarks = {}
46 bookmarks = {}
49 47 for line in repo.opener('bookmarks'):
50 48 sha, refspec = line.strip().split(' ', 1)
51 repo._bookmarks[refspec] = repo.lookup(sha)
49 bookmarks[refspec] = repo.lookup(sha)
52 50 except:
53 51 pass
54 return repo._bookmarks
52 return bookmarks
55 53
56 54 def write(repo, refs):
57 55 '''Write bookmarks
@@ -104,7 +102,7 b' def setcurrent(repo, mark):'
104 102 if current(repo) == mark:
105 103 return
106 104
107 refs = parse(repo)
105 refs = repo._bookmarks
108 106
109 107 # do not update if we do update to a rev equal to the current bookmark
110 108 if (mark and mark not in refs and
@@ -135,7 +133,7 b' def bookmark(ui, repo, mark=None, rev=No'
135 133 the bookmark is assigned to that revision.
136 134 '''
137 135 hexfn = ui.debugflag and hex or short
138 marks = parse(repo)
136 marks = repo._bookmarks
139 137 cur = repo.changectx('.').node()
140 138
141 139 if rename:
@@ -219,7 +217,7 b' def strip(oldstrip, ui, repo, node, back'
219 217 the mercurial.strip method. This usually happens during
220 218 qpush and qpop"""
221 219 revisions = _revstostrip(repo.changelog, node)
222 marks = parse(repo)
220 marks = repo._bookmarks
223 221 update = []
224 222 for mark, n in marks.iteritems():
225 223 if repo.changelog.rev(n) in revisions:
@@ -236,18 +234,20 b' def reposetup(ui, repo):'
236 234
237 235 # init a bookmark cache as otherwise we would get a infinite reading
238 236 # in lookup()
239 repo._bookmarks = None
240 237 repo._bookmarkcurrent = None
241 238
242 239 class bookmark_repo(repo.__class__):
240
241 @util.propertycache
242 def _bookmarks(self):
243 return parse(self)
244
243 245 def rollback(self):
244 246 if os.path.exists(self.join('undo.bookmarks')):
245 247 util.rename(self.join('undo.bookmarks'), self.join('bookmarks'))
246 248 return super(bookmark_repo, self).rollback()
247 249
248 250 def lookup(self, key):
249 if self._bookmarks is None:
250 self._bookmarks = parse(self)
251 251 if key in self._bookmarks:
252 252 key = self._bookmarks[key]
253 253 return super(bookmark_repo, self).lookup(key)
@@ -263,7 +263,7 b' def reposetup(ui, repo):'
263 263 parents = self.changelog.parents(node)
264 264 if parents[1] == nullid:
265 265 parents = (parents[0],)
266 marks = parse(self)
266 marks = self._bookmarks
267 267 update = False
268 268 if ui.configbool('bookmarks', 'track.current'):
269 269 mark = current(self)
@@ -290,7 +290,7 b' def reposetup(ui, repo):'
290 290 # We have more heads than before
291 291 return result
292 292 node = self.changelog.tip()
293 marks = parse(self)
293 marks = self._bookmarks
294 294 update = False
295 295 if ui.configbool('bookmarks', 'track.current'):
296 296 mark = current(self)
@@ -309,7 +309,7 b' def reposetup(ui, repo):'
309 309 def _findtags(self):
310 310 """Merge bookmarks with normal tags"""
311 311 (tags, tagtypes) = super(bookmark_repo, self)._findtags()
312 tags.update(parse(self))
312 tags.update(self._bookmarks)
313 313 return (tags, tagtypes)
314 314
315 315 repo.__class__ = bookmark_repo
General Comments 0
You need to be logged in to leave comments. Login now