[PATCH 1 of 7 bm-refactor V3] bookmarks: factor out delete logic from commands

Sean Farley sean at farley.io
Fri Jun 23 18:33:17 UTC 2017


# HG changeset patch
# User Sean Farley <sean at farley.io>
# Date 1497333768 25200
#      Mon Jun 12 23:02:48 2017 -0700
# Branch bm-refactor
# Node ID d8b560800ad7ae1c0cbb83a2e810af891d26c0d5
# Parent  1c97df5e3b46d1b8dc3e0df3ae07b35c55c0db68
bookmarks: factor out delete logic from commands

We keep the lock in the caller so that future devs are aware of the
locking implications.

diff --git a/mercurial/bookmarks.py b/mercurial/bookmarks.py
index 451c557..0371a52 100644
--- a/mercurial/bookmarks.py
+++ b/mercurial/bookmarks.py
@@ -689,5 +689,20 @@ def checkformat(repo, mark):
     if not mark:
         raise error.Abort(_("bookmark names cannot consist entirely of "
                             "whitespace"))
     scmutil.checknewlabel(repo, mark, 'bookmark')
     return mark
+
+def delete(repo, tr, names):
+    """remove a mark from the bookmark store
+
+    Raises an abort error if mark does not exist.
+    """
+    marks = repo._bookmarks
+    for mark in names:
+        if mark not in marks:
+            raise error.Abort(_("bookmark '%s' does not exist") %
+                              mark)
+        if mark == repo._activebookmark:
+            deactivate(repo)
+        del marks[mark]
+    marks.recordchange(tr)
diff --git a/mercurial/commands.py b/mercurial/commands.py
index 4dd2521..876fb3e 100644
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -973,18 +973,11 @@ def bookmark(ui, repo, *names, **opts):
             lock = repo.lock()
             cur = repo.changectx('.').node()
             marks = repo._bookmarks
             if delete:
                 tr = repo.transaction('bookmark')
-                for mark in names:
-                    if mark not in marks:
-                        raise error.Abort(_("bookmark '%s' does not exist") %
-                                         mark)
-                    if mark == repo._activebookmark:
-                        bookmarks.deactivate(repo)
-                    del marks[mark]
-
+                bookmarks.delete(repo, tr, names)
             elif rename:
                 tr = repo.transaction('bookmark')
                 if not names:
                     raise error.Abort(_("new bookmark name required"))
                 elif len(names) > 1:


More information about the Mercurial-devel mailing list