diff mercurial/bookmarks.py @ 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
line wrap: on
line diff
--- 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()