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

login
register
mail settings
Submitter Yuya Nishihara
Date Sept. 21, 2018, 1:24 p.m.
Message ID <530665a75d5e7daa842d.1537536247@mimosa>
Download mbox | patch
Permalink /patch/34898/
State Accepted
Headers show

Comments

Yuya Nishihara - Sept. 21, 2018, 1:24 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@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.

Patch

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: