# HG changeset patch # User Matt Mackall # Date 2011-02-10 19:46:27 # Node ID 689bf32b3bbd48a22ba161cc6a5c4a95d75f4533 # Parent f9cd37fca5ba5a637826e10593902ae1a392dfe9 bookmarks: move pushkey functions into core diff --git a/hgext/bookmarks.py b/hgext/bookmarks.py --- a/hgext/bookmarks.py +++ b/hgext/bookmarks.py @@ -276,34 +276,6 @@ def reposetup(ui, repo): repo.__class__ = bookmark_repo -def listbookmarks(repo): - # We may try to list bookmarks on a repo type that does not - # support it (e.g., statichttprepository). - if not hasattr(repo, '_bookmarks'): - return {} - - d = {} - for k, v in repo._bookmarks.iteritems(): - d[k] = hex(v) - return d - -def pushbookmark(repo, key, old, new): - w = repo.wlock() - try: - marks = repo._bookmarks - if hex(marks.get(key, '')) != old: - return False - if new == '': - del marks[key] - else: - if new not in repo: - return False - marks[key] = repo[new].node() - bookmarks.write(repo) - return True - finally: - w.release() - def pull(oldpull, ui, repo, source="default", **opts): # translate bookmark args to rev args for actual pull if opts.get('bookmark'): @@ -424,8 +396,6 @@ def uisetup(ui): entry[1].append(('B', 'bookmarks', False, _("compare bookmark"))) - pushkey.register('bookmarks', pushbookmark, listbookmarks) - def updatecurbookmark(orig, ui, repo, *args, **opts): '''Set the current bookmark @@ -449,11 +419,12 @@ def bmrevset(repo, subset, x): bm = revset.getstring(args[0], # i18n: "bookmark" is a keyword _('the argument to bookmark must be a string')) - bmrev = listbookmarks(repo).get(bm, None) + bmrev = bookmarks.listbookmarks(repo).get(bm, None) if bmrev: bmrev = repo.changelog.rev(bin(bmrev)) return [r for r in subset if r == bmrev] - bms = set([repo.changelog.rev(bin(r)) for r in listbookmarks(repo).values()]) + bms = set([repo.changelog.rev(bin(r)) + for r in bookmarks.listbookmarks(repo).values()]) return [r for r in subset if r in bms] def extsetup(ui): diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py --- a/mercurial/bookmarks.py +++ b/mercurial/bookmarks.py @@ -121,3 +121,31 @@ def update(repo, parents, node): update = True if update: write(repo) + +def listbookmarks(repo): + # We may try to list bookmarks on a repo type that does not + # support it (e.g., statichttprepository). + if not hasattr(repo, '_bookmarks'): + return {} + + d = {} + for k, v in repo._bookmarks.iteritems(): + d[k] = hex(v) + return d + +def pushbookmark(repo, key, old, new): + w = repo.wlock() + try: + marks = repo._bookmarks + if hex(marks.get(key, '')) != old: + return False + if new == '': + del marks[key] + else: + if new not in repo: + return False + marks[key] = repo[new].node() + write(repo) + return True + finally: + w.release() diff --git a/mercurial/pushkey.py b/mercurial/pushkey.py --- a/mercurial/pushkey.py +++ b/mercurial/pushkey.py @@ -5,13 +5,16 @@ # This software may be used and distributed according to the terms of the # GNU General Public License version 2 or any later version. +import bookmarks + def _nslist(repo): n = {} for k in _namespaces: n[k] = "" return n -_namespaces = {"namespaces": (lambda *x: False, _nslist)} +_namespaces = {"namespaces": (lambda *x: False, _nslist), + "bookmarks": (bookmarks.pushbookmark, bookmarks.listbookmarks)} def register(namespace, pushkey, listkeys): _namespaces[namespace] = (pushkey, listkeys)