bookmarks: parse out implicit "add" action early
authorYuya Nishihara <yuya@tcha.org>
Sat, 15 Sep 2018 12:25:19 +0900
changeset 39750 ec723284d07a
parent 39749 2b91805e34c7
child 39751 5dfc0ca02aa0
bookmarks: parse out implicit "add" action early This prepares for adding -l/--list option, which can be combined with the positional arguments.
mercurial/commands.py
--- a/mercurial/commands.py	Sat Sep 15 12:07:38 2018 +0900
+++ b/mercurial/commands.py	Sat Sep 15 12:25:19 2018 +0900
@@ -969,6 +969,8 @@
                           % tuple(selactions[:2]))
     if selactions:
         action = selactions[0]
+    elif names or rev:
+        action = 'add'
     else:
         action = None
 
@@ -978,10 +980,10 @@
         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 @@
                     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: