62 ''' |
62 ''' |
63 if os.path.exists(repo.join('bookmarks')): |
63 if os.path.exists(repo.join('bookmarks')): |
64 util.copyfile(repo.join('bookmarks'), repo.join('undo.bookmarks')) |
64 util.copyfile(repo.join('bookmarks'), repo.join('undo.bookmarks')) |
65 if current(repo) not in refs: |
65 if current(repo) not in refs: |
66 setcurrent(repo, None) |
66 setcurrent(repo, None) |
67 file = repo.opener('bookmarks', 'w+') |
67 wlock = repo.wlock() |
68 for refspec, node in refs.iteritems(): |
68 try: |
69 file.write("%s %s\n" % (hex(node), refspec)) |
69 file = repo.opener('bookmarks', 'w', atomictemp=True) |
70 file.close() |
70 for refspec, node in refs.iteritems(): |
|
71 file.write("%s %s\n" % (hex(node), refspec)) |
|
72 file.rename() |
|
73 finally: |
|
74 wlock.release() |
71 |
75 |
72 def current(repo): |
76 def current(repo): |
73 '''Get the current bookmark |
77 '''Get the current bookmark |
74 |
78 |
75 If we use gittishsh branches we have a current bookmark that |
79 If we use gittishsh branches we have a current bookmark that |
104 if (mark and mark not in refs and |
108 if (mark and mark not in refs and |
105 current(repo) and refs[current(repo)] == repo.changectx('.').node()): |
109 current(repo) and refs[current(repo)] == repo.changectx('.').node()): |
106 return |
110 return |
107 if mark not in refs: |
111 if mark not in refs: |
108 mark = '' |
112 mark = '' |
109 file = repo.opener('bookmarks.current', 'w+') |
113 wlock = repo.wlock() |
110 file.write(mark) |
114 try: |
111 file.close() |
115 file = repo.opener('bookmarks.current', 'w', atomictemp=True) |
|
116 file.write(mark) |
|
117 file.rename() |
|
118 finally: |
|
119 wlock.release() |
112 repo._bookmarkcurrent = mark |
120 repo._bookmarkcurrent = mark |
113 |
121 |
114 def bookmark(ui, repo, mark=None, rev=None, force=False, delete=False, rename=None): |
122 def bookmark(ui, repo, mark=None, rev=None, force=False, delete=False, rename=None): |
115 '''Mercurial bookmarks |
123 '''Mercurial bookmarks |
116 |
124 |
240 return super(bookmark_repo, self).lookup(key) |
248 return super(bookmark_repo, self).lookup(key) |
241 |
249 |
242 def commit(self, *k, **kw): |
250 def commit(self, *k, **kw): |
243 """Add a revision to the repository and |
251 """Add a revision to the repository and |
244 move the bookmark""" |
252 move the bookmark""" |
245 node = super(bookmark_repo, self).commit(*k, **kw) |
253 wlock = self.wlock() # do both commit and bookmark with lock held |
246 if node is None: |
254 try: |
247 return None |
255 node = super(bookmark_repo, self).commit(*k, **kw) |
248 parents = repo.changelog.parents(node) |
256 if node is None: |
249 if parents[1] == nullid: |
257 return None |
250 parents = (parents[0],) |
258 parents = repo.changelog.parents(node) |
251 marks = parse(repo) |
259 if parents[1] == nullid: |
252 update = False |
260 parents = (parents[0],) |
253 for mark, n in marks.items(): |
261 marks = parse(repo) |
254 if ui.configbool('bookmarks', 'track.current'): |
262 update = False |
255 if mark == current(repo) and n in parents: |
263 for mark, n in marks.items(): |
256 marks[mark] = node |
264 if ui.configbool('bookmarks', 'track.current'): |
257 update = True |
265 if mark == current(repo) and n in parents: |
258 else: |
266 marks[mark] = node |
259 if n in parents: |
267 update = True |
260 marks[mark] = node |
268 else: |
261 update = True |
269 if n in parents: |
262 if update: |
270 marks[mark] = node |
263 write(repo, marks) |
271 update = True |
264 return node |
272 if update: |
|
273 write(repo, marks) |
|
274 return node |
|
275 finally: |
|
276 wlock.release() |
265 |
277 |
266 def addchangegroup(self, source, srctype, url, emptyok=False): |
278 def addchangegroup(self, source, srctype, url, emptyok=False): |
267 parents = repo.dirstate.parents() |
279 parents = repo.dirstate.parents() |
268 |
280 |
269 result = super(bookmark_repo, self).addchangegroup( |
281 result = super(bookmark_repo, self).addchangegroup( |