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

login
register
mail settings
Submitter Sean Farley
Date June 23, 2017, 6:33 p.m.
Message ID <d8b560800ad7ae1c0cbb.1498242797@1.0.0.127.in-addr.arpa>
Download mbox | patch
Permalink /patch/21639/
State Accepted
Headers show

Comments

Sean Farley - June 23, 2017, 6:33 p.m.
# HG changeset patch
# User Sean Farley <sean@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.

Patch

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: