[PATCH 5 of 9] bookmarks: parse out implicit "add" action early

Yuya Nishihara yuya at tcha.org
Fri Sep 21 09:24:07 EDT 2018


# HG changeset patch
# User Yuya Nishihara <yuya at tcha.org>
# Date 1536981919 -32400
#      Sat Sep 15 12:25:19 2018 +0900
# Node ID 530665a75d5e7daa842d0a3931eadf0a904c01ea
# Parent  ce660bd0ea0b5df62ca61ed0ae90ab08d2cc53e8
bookmarks: parse out implicit "add" action early

This prepares for adding -l/--list option, which can be combined with the
positional arguments.

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -969,6 +969,8 @@ def bookmark(ui, repo, *names, **opts):
                           % tuple(selactions[:2]))
     if selactions:
         action = selactions[0]
+    elif names or rev:
+        action = 'add'
     else:
         action = None
 
@@ -978,10 +980,10 @@ def bookmark(ui, repo, *names, **opts):
         raise error.Abort(_("NAMES is incompatible with --active"))
     if inactive and action == 'active':
         raise error.Abort(_("--inactive is incompatible with --active"))
-    if not names and (action == 'delete' or rev):
+    if not names and action in {'add', 'delete'}:
         raise error.Abort(_("bookmark name required"))
 
-    if action in {'delete', 'rename'} or names or inactive:
+    if action in {'add', 'delete', 'rename'} or inactive:
         with repo.wlock(), repo.lock(), repo.transaction('bookmark') as tr:
             if action == 'delete':
                 names = pycompat.maplist(repo._bookmarks.expandname, names)
@@ -993,7 +995,7 @@ def bookmark(ui, repo, *names, **opts):
                     raise error.Abort(_("only one new bookmark name allowed"))
                 oldname = repo._bookmarks.expandname(opts['rename'])
                 bookmarks.rename(repo, tr, oldname, names[0], force, inactive)
-            elif names:
+            elif action == 'add':
                 bookmarks.addbookmarks(repo, tr, names, rev, force, inactive)
             elif inactive:
                 if len(repo._bookmarks) == 0:


More information about the Mercurial-devel mailing list