comparison mercurial/commands.py @ 39750:ec723284d07a

bookmarks: parse out implicit "add" action early This prepares for adding -l/--list option, which can be combined with the positional arguments.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 15 Sep 2018 12:25:19 +0900
parents 2b91805e34c7
children 5dfc0ca02aa0
comparison
equal deleted inserted replaced
39749:2b91805e34c7 39750:ec723284d07a
967 if len(selactions) > 1: 967 if len(selactions) > 1:
968 raise error.Abort(_('--%s and --%s are incompatible') 968 raise error.Abort(_('--%s and --%s are incompatible')
969 % tuple(selactions[:2])) 969 % tuple(selactions[:2]))
970 if selactions: 970 if selactions:
971 action = selactions[0] 971 action = selactions[0]
972 elif names or rev:
973 action = 'add'
972 else: 974 else:
973 action = None 975 action = None
974 976
975 if rev and action in {'delete', 'rename', 'active'}: 977 if rev and action in {'delete', 'rename', 'active'}:
976 raise error.Abort(_("--rev is incompatible with --%s") % action) 978 raise error.Abort(_("--rev is incompatible with --%s") % action)
977 if names and action == 'active': 979 if names and action == 'active':
978 raise error.Abort(_("NAMES is incompatible with --active")) 980 raise error.Abort(_("NAMES is incompatible with --active"))
979 if inactive and action == 'active': 981 if inactive and action == 'active':
980 raise error.Abort(_("--inactive is incompatible with --active")) 982 raise error.Abort(_("--inactive is incompatible with --active"))
981 if not names and (action == 'delete' or rev): 983 if not names and action in {'add', 'delete'}:
982 raise error.Abort(_("bookmark name required")) 984 raise error.Abort(_("bookmark name required"))
983 985
984 if action in {'delete', 'rename'} or names or inactive: 986 if action in {'add', 'delete', 'rename'} or inactive:
985 with repo.wlock(), repo.lock(), repo.transaction('bookmark') as tr: 987 with repo.wlock(), repo.lock(), repo.transaction('bookmark') as tr:
986 if action == 'delete': 988 if action == 'delete':
987 names = pycompat.maplist(repo._bookmarks.expandname, names) 989 names = pycompat.maplist(repo._bookmarks.expandname, names)
988 bookmarks.delete(repo, tr, names) 990 bookmarks.delete(repo, tr, names)
989 elif action == 'rename': 991 elif action == 'rename':
991 raise error.Abort(_("new bookmark name required")) 993 raise error.Abort(_("new bookmark name required"))
992 elif len(names) > 1: 994 elif len(names) > 1:
993 raise error.Abort(_("only one new bookmark name allowed")) 995 raise error.Abort(_("only one new bookmark name allowed"))
994 oldname = repo._bookmarks.expandname(opts['rename']) 996 oldname = repo._bookmarks.expandname(opts['rename'])
995 bookmarks.rename(repo, tr, oldname, names[0], force, inactive) 997 bookmarks.rename(repo, tr, oldname, names[0], force, inactive)
996 elif names: 998 elif action == 'add':
997 bookmarks.addbookmarks(repo, tr, names, rev, force, inactive) 999 bookmarks.addbookmarks(repo, tr, names, rev, force, inactive)
998 elif inactive: 1000 elif inactive:
999 if len(repo._bookmarks) == 0: 1001 if len(repo._bookmarks) == 0:
1000 ui.status(_("no bookmarks set\n")) 1002 ui.status(_("no bookmarks set\n"))
1001 elif not repo._activebookmark: 1003 elif not repo._activebookmark: