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