Mercurial > hg
comparison hgext/bookmarks.py @ 10105:dc5b5cc5ca34
bookmarks: turn repo._bookmarks into a propertycache
author | Nicolas Dumazet <nicdumz.commits@gmail.com> |
---|---|
date | Mon, 21 Dec 2009 13:55:56 +0900 |
parents | 013cc052a926 |
children | cb3f6da91646 |
comparison
equal
deleted
inserted
replaced
10104:e533fc8a058b | 10105:dc5b5cc5ca34 |
---|---|
41 returned as a dictionary with name => hash values. | 41 returned as a dictionary with name => hash values. |
42 | 42 |
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 |
58 | 56 |
59 Write the given bookmark => hash dictionary to the .hg/bookmarks file | 57 Write the given bookmark => hash dictionary to the .hg/bookmarks file |
102 The name is recorded in .hg/bookmarks.current | 100 The name is recorded in .hg/bookmarks.current |
103 ''' | 101 ''' |
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 |
111 current(repo) and refs[current(repo)] == repo.changectx('.').node()): | 109 current(repo) and refs[current(repo)] == repo.changectx('.').node()): |
112 return | 110 return |
133 directory's parent revision with the given name. If you specify | 131 directory's parent revision with the given name. If you specify |
134 a revision using -r REV (where REV may be an existing bookmark), | 132 a revision using -r REV (where REV may be an existing bookmark), |
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: |
142 if rename not in marks: | 140 if rename not in marks: |
143 raise util.Abort(_("a bookmark of this name does not exist")) | 141 raise util.Abort(_("a bookmark of this name does not exist")) |
217 def strip(oldstrip, ui, repo, node, backup="all"): | 215 def strip(oldstrip, ui, repo, node, backup="all"): |
218 """Strip bookmarks if revisions are stripped using | 216 """Strip bookmarks if revisions are stripped using |
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: |
226 update.append(mark) | 224 update.append(mark) |
227 oldstrip(ui, repo, node, backup) | 225 oldstrip(ui, repo, node, backup) |
234 if not repo.local(): | 232 if not repo.local(): |
235 return | 233 return |
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) |
254 | 254 |
255 def commitctx(self, ctx, error=False): | 255 def commitctx(self, ctx, error=False): |
261 if node is None: | 261 if node is None: |
262 return None | 262 return None |
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) |
270 if mark and marks[mark] in parents: | 270 if mark and marks[mark] in parents: |
271 marks[mark] = node | 271 marks[mark] = node |
288 source, srctype, url, emptyok) | 288 source, srctype, url, emptyok) |
289 if result > 1: | 289 if result > 1: |
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) |
297 if mark and marks[mark] in parents: | 297 if mark and marks[mark] in parents: |
298 marks[mark] = node | 298 marks[mark] = node |
307 return result | 307 return result |
308 | 308 |
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 |
316 | 316 |
317 def uisetup(ui): | 317 def uisetup(ui): |