comparison mercurial/commands.py @ 39769:b05b4b91de3d

bookmarks: add explicit option to list bookmarks of the given names This is a generalized form of the --active option. A redundant sorted() call is removed. There was no point to update dict items in lexicographical order.
author Yuya Nishihara <yuya@tcha.org>
date Sat, 15 Sep 2018 12:44:23 +0900
parents 2d478b05fb14
children c48738923dba
comparison
equal deleted inserted replaced
39768:2d478b05fb14 39769:b05b4b91de3d
901 [('f', 'force', False, _('force')), 901 [('f', 'force', False, _('force')),
902 ('r', 'rev', '', _('revision for bookmark action'), _('REV')), 902 ('r', 'rev', '', _('revision for bookmark action'), _('REV')),
903 ('d', 'delete', False, _('delete a given bookmark')), 903 ('d', 'delete', False, _('delete a given bookmark')),
904 ('m', 'rename', '', _('rename a given bookmark'), _('OLD')), 904 ('m', 'rename', '', _('rename a given bookmark'), _('OLD')),
905 ('i', 'inactive', False, _('mark a bookmark inactive')), 905 ('i', 'inactive', False, _('mark a bookmark inactive')),
906 ('l', 'list', False, _('list existing bookmarks')),
906 ('', 'active', False, _('display the active bookmark')), 907 ('', 'active', False, _('display the active bookmark')),
907 ] + formatteropts, 908 ] + formatteropts,
908 _('hg bookmarks [OPTIONS]... [NAME]...')) 909 _('hg bookmarks [OPTIONS]... [NAME]...'))
909 def bookmark(ui, repo, *names, **opts): 910 def bookmark(ui, repo, *names, **opts):
910 '''create a new bookmark or list existing bookmarks 911 '''create a new bookmark or list existing bookmarks
922 Bookmarks can be pushed and pulled between repositories (see 923 Bookmarks can be pushed and pulled between repositories (see
923 :hg:`help push` and :hg:`help pull`). If a shared bookmark has 924 :hg:`help push` and :hg:`help pull`). If a shared bookmark has
924 diverged, a new 'divergent bookmark' of the form 'name@path' will 925 diverged, a new 'divergent bookmark' of the form 'name@path' will
925 be created. Using :hg:`merge` will resolve the divergence. 926 be created. Using :hg:`merge` will resolve the divergence.
926 927
927 Specifying bookmark as '.' to -m or -d options is equivalent to specifying 928 Specifying bookmark as '.' to -m/-d/-l options is equivalent to specifying
928 the active bookmark's name. 929 the active bookmark's name.
929 930
930 A bookmark named '@' has the special property that :hg:`clone` will 931 A bookmark named '@' has the special property that :hg:`clone` will
931 check it out by default if it exists. 932 check it out by default if it exists.
932 933
961 opts = pycompat.byteskwargs(opts) 962 opts = pycompat.byteskwargs(opts)
962 force = opts.get('force') 963 force = opts.get('force')
963 rev = opts.get('rev') 964 rev = opts.get('rev')
964 inactive = opts.get('inactive') # meaning add/rename to inactive bookmark 965 inactive = opts.get('inactive') # meaning add/rename to inactive bookmark
965 966
966 selactions = [k for k in ['delete', 'rename', 'active'] if opts.get(k)] 967 selactions = [k for k in ['delete', 'rename', 'active', 'list']
968 if opts.get(k)]
967 if len(selactions) > 1: 969 if len(selactions) > 1:
968 raise error.Abort(_('--%s and --%s are incompatible') 970 raise error.Abort(_('--%s and --%s are incompatible')
969 % tuple(selactions[:2])) 971 % tuple(selactions[:2]))
970 if selactions: 972 if selactions:
971 action = selactions[0] 973 action = selactions[0]
972 elif names or rev: 974 elif names or rev:
973 action = 'add' 975 action = 'add'
974 elif inactive: 976 elif inactive:
975 action = 'inactive' # meaning deactivate 977 action = 'inactive' # meaning deactivate
976 else: 978 else:
977 action = None 979 action = 'list'
978 980
979 if rev and action in {'delete', 'rename', 'active'}: 981 if rev and action in {'delete', 'rename', 'active', 'list'}:
980 raise error.Abort(_("--rev is incompatible with --%s") % action) 982 raise error.Abort(_("--rev is incompatible with --%s") % action)
981 if names and action == 'active': 983 if names and action == 'active':
982 raise error.Abort(_("NAMES is incompatible with --active")) 984 raise error.Abort(_("NAMES is incompatible with --active"))
983 if inactive and action in {'delete', 'active'}: 985 if inactive and action in {'delete', 'active', 'list'}:
984 raise error.Abort(_("--inactive is incompatible with --%s") % action) 986 raise error.Abort(_("--inactive is incompatible with --%s") % action)
985 if not names and action in {'add', 'delete'}: 987 if not names and action in {'add', 'delete'}:
986 raise error.Abort(_("bookmark name required")) 988 raise error.Abort(_("bookmark name required"))
987 989
988 if action in {'add', 'delete', 'rename', 'inactive'}: 990 if action in {'add', 'delete', 'rename', 'inactive'}:
1009 elif action == 'active': 1011 elif action == 'active':
1010 book = repo._activebookmark 1012 book = repo._activebookmark
1011 if book is None: 1013 if book is None:
1012 return 1 1014 return 1
1013 ui.write("%s\n" % book, label=bookmarks.activebookmarklabel) 1015 ui.write("%s\n" % book, label=bookmarks.activebookmarklabel)
1014 else: # show bookmarks 1016 elif action == 'list':
1017 names = pycompat.maplist(repo._bookmarks.expandname, names)
1015 with ui.formatter('bookmarks', opts) as fm: 1018 with ui.formatter('bookmarks', opts) as fm:
1016 bookmarks.printbookmarks(ui, repo, fm) 1019 bookmarks.printbookmarks(ui, repo, fm, names)
1020 else:
1021 raise error.ProgrammingError('invalid action: %s' % action)
1017 1022
1018 @command('branch', 1023 @command('branch',
1019 [('f', 'force', None, 1024 [('f', 'force', None,
1020 _('set branch name even if it shadows an existing branch')), 1025 _('set branch name even if it shadows an existing branch')),
1021 ('C', 'clean', None, _('reset branch name to parent branch name')), 1026 ('C', 'clean', None, _('reset branch name to parent branch name')),