Mercurial > hg
comparison hgext/bookmarks.py @ 10108:b6fcb5c55884
bookmarks: refactor code responsible for updates of bookmarks
introduce _bookmarksupdate for common parts from commitctx and addchangegroup
author | Nicolas Dumazet <nicdumz.commits@gmail.com> |
---|---|
date | Mon, 21 Dec 2009 15:17:28 +0900 |
parents | c03f467423f3 |
children | be041d6714ed |
comparison
equal
deleted
inserted
replaced
10107:c03f467423f3 | 10108:b6fcb5c55884 |
---|---|
250 def lookup(self, key): | 250 def lookup(self, key): |
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 _bookmarksupdate(self, parents, node): |
256 """Add a revision to the repository and | |
257 move the bookmark""" | |
258 wlock = self.wlock() # do both commit and bookmark with lock held | |
259 try: | |
260 node = super(bookmark_repo, self).commitctx(ctx, error) | |
261 if node is None: | |
262 return None | |
263 parents = self.changelog.parents(node) | |
264 if parents[1] == nullid: | |
265 parents = (parents[0],) | |
266 marks = self._bookmarks | |
267 update = False | |
268 if ui.configbool('bookmarks', 'track.current'): | |
269 mark = self._bookmarkcurrent | |
270 if mark and marks[mark] in parents: | |
271 marks[mark] = node | |
272 update = True | |
273 else: | |
274 for mark, n in marks.items(): | |
275 if n in parents: | |
276 marks[mark] = node | |
277 update = True | |
278 if update: | |
279 write(self) | |
280 return node | |
281 finally: | |
282 wlock.release() | |
283 | |
284 def addchangegroup(self, source, srctype, url, emptyok=False): | |
285 parents = self.dirstate.parents() | |
286 | |
287 result = super(bookmark_repo, self).addchangegroup( | |
288 source, srctype, url, emptyok) | |
289 if result > 1: | |
290 # We have more heads than before | |
291 return result | |
292 node = self.changelog.tip() | |
293 marks = self._bookmarks | 256 marks = self._bookmarks |
294 update = False | 257 update = False |
295 if ui.configbool('bookmarks', 'track.current'): | 258 if ui.configbool('bookmarks', 'track.current'): |
296 mark = self._bookmarkcurrent | 259 mark = self._bookmarkcurrent |
297 if mark and marks[mark] in parents: | 260 if mark and marks[mark] in parents: |
302 if n in parents: | 265 if n in parents: |
303 marks[mark] = node | 266 marks[mark] = node |
304 update = True | 267 update = True |
305 if update: | 268 if update: |
306 write(self) | 269 write(self) |
270 | |
271 def commitctx(self, ctx, error=False): | |
272 """Add a revision to the repository and | |
273 move the bookmark""" | |
274 wlock = self.wlock() # do both commit and bookmark with lock held | |
275 try: | |
276 node = super(bookmark_repo, self).commitctx(ctx, error) | |
277 if node is None: | |
278 return None | |
279 parents = self.changelog.parents(node) | |
280 if parents[1] == nullid: | |
281 parents = (parents[0],) | |
282 | |
283 self._bookmarksupdate(parents, node) | |
284 return node | |
285 finally: | |
286 wlock.release() | |
287 | |
288 def addchangegroup(self, source, srctype, url, emptyok=False): | |
289 parents = self.dirstate.parents() | |
290 | |
291 result = super(bookmark_repo, self).addchangegroup( | |
292 source, srctype, url, emptyok) | |
293 if result > 1: | |
294 # We have more heads than before | |
295 return result | |
296 node = self.changelog.tip() | |
297 | |
298 self._bookmarksupdate(parents, node) | |
307 return result | 299 return result |
308 | 300 |
309 def _findtags(self): | 301 def _findtags(self): |
310 """Merge bookmarks with normal tags""" | 302 """Merge bookmarks with normal tags""" |
311 (tags, tagtypes) = super(bookmark_repo, self)._findtags() | 303 (tags, tagtypes) = super(bookmark_repo, self)._findtags() |