##// END OF EJS Templates
bookmarks: move pushkey functions into core
Matt Mackall -
r13353:689bf32b default
parent child Browse files
Show More
@@ -276,34 +276,6 b' def reposetup(ui, repo):'
276
276
277 repo.__class__ = bookmark_repo
277 repo.__class__ = bookmark_repo
278
278
279 def listbookmarks(repo):
280 # We may try to list bookmarks on a repo type that does not
281 # support it (e.g., statichttprepository).
282 if not hasattr(repo, '_bookmarks'):
283 return {}
284
285 d = {}
286 for k, v in repo._bookmarks.iteritems():
287 d[k] = hex(v)
288 return d
289
290 def pushbookmark(repo, key, old, new):
291 w = repo.wlock()
292 try:
293 marks = repo._bookmarks
294 if hex(marks.get(key, '')) != old:
295 return False
296 if new == '':
297 del marks[key]
298 else:
299 if new not in repo:
300 return False
301 marks[key] = repo[new].node()
302 bookmarks.write(repo)
303 return True
304 finally:
305 w.release()
306
307 def pull(oldpull, ui, repo, source="default", **opts):
279 def pull(oldpull, ui, repo, source="default", **opts):
308 # translate bookmark args to rev args for actual pull
280 # translate bookmark args to rev args for actual pull
309 if opts.get('bookmark'):
281 if opts.get('bookmark'):
@@ -424,8 +396,6 b' def uisetup(ui):'
424 entry[1].append(('B', 'bookmarks', False,
396 entry[1].append(('B', 'bookmarks', False,
425 _("compare bookmark")))
397 _("compare bookmark")))
426
398
427 pushkey.register('bookmarks', pushbookmark, listbookmarks)
428
429 def updatecurbookmark(orig, ui, repo, *args, **opts):
399 def updatecurbookmark(orig, ui, repo, *args, **opts):
430 '''Set the current bookmark
400 '''Set the current bookmark
431
401
@@ -449,11 +419,12 b' def bmrevset(repo, subset, x):'
449 bm = revset.getstring(args[0],
419 bm = revset.getstring(args[0],
450 # i18n: "bookmark" is a keyword
420 # i18n: "bookmark" is a keyword
451 _('the argument to bookmark must be a string'))
421 _('the argument to bookmark must be a string'))
452 bmrev = listbookmarks(repo).get(bm, None)
422 bmrev = bookmarks.listbookmarks(repo).get(bm, None)
453 if bmrev:
423 if bmrev:
454 bmrev = repo.changelog.rev(bin(bmrev))
424 bmrev = repo.changelog.rev(bin(bmrev))
455 return [r for r in subset if r == bmrev]
425 return [r for r in subset if r == bmrev]
456 bms = set([repo.changelog.rev(bin(r)) for r in listbookmarks(repo).values()])
426 bms = set([repo.changelog.rev(bin(r))
427 for r in bookmarks.listbookmarks(repo).values()])
457 return [r for r in subset if r in bms]
428 return [r for r in subset if r in bms]
458
429
459 def extsetup(ui):
430 def extsetup(ui):
@@ -121,3 +121,31 b' def update(repo, parents, node):'
121 update = True
121 update = True
122 if update:
122 if update:
123 write(repo)
123 write(repo)
124
125 def listbookmarks(repo):
126 # We may try to list bookmarks on a repo type that does not
127 # support it (e.g., statichttprepository).
128 if not hasattr(repo, '_bookmarks'):
129 return {}
130
131 d = {}
132 for k, v in repo._bookmarks.iteritems():
133 d[k] = hex(v)
134 return d
135
136 def pushbookmark(repo, key, old, new):
137 w = repo.wlock()
138 try:
139 marks = repo._bookmarks
140 if hex(marks.get(key, '')) != old:
141 return False
142 if new == '':
143 del marks[key]
144 else:
145 if new not in repo:
146 return False
147 marks[key] = repo[new].node()
148 write(repo)
149 return True
150 finally:
151 w.release()
@@ -5,13 +5,16 b''
5 # This software may be used and distributed according to the terms of the
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
6 # GNU General Public License version 2 or any later version.
7
7
8 import bookmarks
9
8 def _nslist(repo):
10 def _nslist(repo):
9 n = {}
11 n = {}
10 for k in _namespaces:
12 for k in _namespaces:
11 n[k] = ""
13 n[k] = ""
12 return n
14 return n
13
15
14 _namespaces = {"namespaces": (lambda *x: False, _nslist)}
16 _namespaces = {"namespaces": (lambda *x: False, _nslist),
17 "bookmarks": (bookmarks.pushbookmark, bookmarks.listbookmarks)}
15
18
16 def register(namespace, pushkey, listkeys):
19 def register(namespace, pushkey, listkeys):
17 _namespaces[namespace] = (pushkey, listkeys)
20 _namespaces[namespace] = (pushkey, listkeys)
General Comments 0
You need to be logged in to leave comments. Login now