Patchwork [6,of,9] bookmarks: parse out --inactive to action early

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

Comments

Yuya Nishihara - Sept. 21, 2018, 1:24 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1536982321 -32400
#      Sat Sep 15 12:32:01 2018 +0900
# Node ID 99d6d63325c1b44de2985413ead1ac0a53948be2
# Parent  530665a75d5e7daa842d0a3931eadf0a904c01ea
bookmarks: parse out --inactive to action early

The --inactive option can't be directly mapped to an action or a modifier.
With any names, it means to add/rename to inactive bookmarks. Without names,
it means to deactivate the current bookmark. This patch separates them to
"inactive" flag and "action == 'inactive'".

Patch

diff --git a/mercurial/commands.py b/mercurial/commands.py
--- a/mercurial/commands.py
+++ b/mercurial/commands.py
@@ -961,7 +961,7 @@  def bookmark(ui, repo, *names, **opts):
     opts = pycompat.byteskwargs(opts)
     force = opts.get('force')
     rev = opts.get('rev')
-    inactive = opts.get('inactive')
+    inactive = opts.get('inactive')  # meaning add/rename to inactive bookmark
 
     selactions = [k for k in ['delete', 'rename', 'active'] if opts.get(k)]
     if len(selactions) > 1:
@@ -971,6 +971,8 @@  def bookmark(ui, repo, *names, **opts):
         action = selactions[0]
     elif names or rev:
         action = 'add'
+    elif inactive:
+        action = 'inactive'  # meaning deactivate
     else:
         action = None
 
@@ -983,7 +985,7 @@  def bookmark(ui, repo, *names, **opts):
     if not names and action in {'add', 'delete'}:
         raise error.Abort(_("bookmark name required"))
 
-    if action in {'add', 'delete', 'rename'} or inactive:
+    if action in {'add', 'delete', 'rename', 'inactive'}:
         with repo.wlock(), repo.lock(), repo.transaction('bookmark') as tr:
             if action == 'delete':
                 names = pycompat.maplist(repo._bookmarks.expandname, names)
@@ -997,7 +999,7 @@  def bookmark(ui, repo, *names, **opts):
                 bookmarks.rename(repo, tr, oldname, names[0], force, inactive)
             elif action == 'add':
                 bookmarks.addbookmarks(repo, tr, names, rev, force, inactive)
-            elif inactive:
+            elif action == 'inactive':
                 if len(repo._bookmarks) == 0:
                     ui.status(_("no bookmarks set\n"))
                 elif not repo._activebookmark: