changeset 13353:689bf32b3bbd

bookmarks: move pushkey functions into core
author Matt Mackall <mpm@selenic.com>
date Thu, 10 Feb 2011 13:46:27 -0600
parents f9cd37fca5ba
children 4e1ba6ead69c
files hgext/bookmarks.py mercurial/bookmarks.py mercurial/pushkey.py
diffstat 3 files changed, 35 insertions(+), 33 deletions(-) [+]
line wrap: on
line diff
--- a/hgext/bookmarks.py	Thu Feb 10 13:46:27 2011 -0600
+++ b/hgext/bookmarks.py	Thu Feb 10 13:46:27 2011 -0600
@@ -276,34 +276,6 @@
 
     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 @@
     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 @@
         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):
--- a/mercurial/bookmarks.py	Thu Feb 10 13:46:27 2011 -0600
+++ b/mercurial/bookmarks.py	Thu Feb 10 13:46:27 2011 -0600
@@ -121,3 +121,31 @@
                 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()
--- a/mercurial/pushkey.py	Thu Feb 10 13:46:27 2011 -0600
+++ b/mercurial/pushkey.py	Thu Feb 10 13:46:27 2011 -0600
@@ -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)