Mercurial > public > mercurial-scm > hg
comparison mercurial/commands.py @ 39754:c48738923dba
bookmarks: remove --active in favor of --list
It's weird that we have both --active and --inactive options meaning
completely different things. Instead of adding a one-off option, let's
document the way to display the active bookmark by using -l/--list.
No deprecated option is added since --active isn't released yet.
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 15 Sep 2018 12:47:49 +0900 |
parents | b05b4b91de3d |
children | a677261e7422 |
comparison
equal
deleted
inserted
replaced
39753:b05b4b91de3d | 39754:c48738923dba |
---|---|
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 ('l', 'list', False, _('list existing bookmarks')), |
907 ('', 'active', False, _('display the active bookmark')), | |
908 ] + formatteropts, | 907 ] + formatteropts, |
909 _('hg bookmarks [OPTIONS]... [NAME]...')) | 908 _('hg bookmarks [OPTIONS]... [NAME]...')) |
910 def bookmark(ui, repo, *names, **opts): | 909 def bookmark(ui, repo, *names, **opts): |
911 '''create a new bookmark or list existing bookmarks | 910 '''create a new bookmark or list existing bookmarks |
912 | 911 |
929 the active bookmark's name. | 928 the active bookmark's name. |
930 | 929 |
931 A bookmark named '@' has the special property that :hg:`clone` will | 930 A bookmark named '@' has the special property that :hg:`clone` will |
932 check it out by default if it exists. | 931 check it out by default if it exists. |
933 | 932 |
934 The '--active' flag will display the current bookmark or return non-zero, | |
935 if combined with other action, they will be performed on the active | |
936 bookmark. | |
937 | |
938 .. container:: verbose | 933 .. container:: verbose |
939 | 934 |
940 Examples: | 935 Examples: |
941 | 936 |
942 - create an active bookmark for a new line of development:: | 937 - create an active bookmark for a new line of development:: |
956 hg book -m turkey dinner | 951 hg book -m turkey dinner |
957 | 952 |
958 - move the '@' bookmark from another branch:: | 953 - move the '@' bookmark from another branch:: |
959 | 954 |
960 hg book -f @ | 955 hg book -f @ |
956 | |
957 - print only the active bookmark name:: | |
958 | |
959 hg book -ql . | |
961 ''' | 960 ''' |
962 opts = pycompat.byteskwargs(opts) | 961 opts = pycompat.byteskwargs(opts) |
963 force = opts.get('force') | 962 force = opts.get('force') |
964 rev = opts.get('rev') | 963 rev = opts.get('rev') |
965 inactive = opts.get('inactive') # meaning add/rename to inactive bookmark | 964 inactive = opts.get('inactive') # meaning add/rename to inactive bookmark |
966 | 965 |
967 selactions = [k for k in ['delete', 'rename', 'active', 'list'] | 966 selactions = [k for k in ['delete', 'rename', 'list'] if opts.get(k)] |
968 if opts.get(k)] | |
969 if len(selactions) > 1: | 967 if len(selactions) > 1: |
970 raise error.Abort(_('--%s and --%s are incompatible') | 968 raise error.Abort(_('--%s and --%s are incompatible') |
971 % tuple(selactions[:2])) | 969 % tuple(selactions[:2])) |
972 if selactions: | 970 if selactions: |
973 action = selactions[0] | 971 action = selactions[0] |
976 elif inactive: | 974 elif inactive: |
977 action = 'inactive' # meaning deactivate | 975 action = 'inactive' # meaning deactivate |
978 else: | 976 else: |
979 action = 'list' | 977 action = 'list' |
980 | 978 |
981 if rev and action in {'delete', 'rename', 'active', 'list'}: | 979 if rev and action in {'delete', 'rename', 'list'}: |
982 raise error.Abort(_("--rev is incompatible with --%s") % action) | 980 raise error.Abort(_("--rev is incompatible with --%s") % action) |
983 if names and action == 'active': | 981 if inactive and action in {'delete', 'list'}: |
984 raise error.Abort(_("NAMES is incompatible with --active")) | |
985 if inactive and action in {'delete', 'active', 'list'}: | |
986 raise error.Abort(_("--inactive is incompatible with --%s") % action) | 982 raise error.Abort(_("--inactive is incompatible with --%s") % action) |
987 if not names and action in {'add', 'delete'}: | 983 if not names and action in {'add', 'delete'}: |
988 raise error.Abort(_("bookmark name required")) | 984 raise error.Abort(_("bookmark name required")) |
989 | 985 |
990 if action in {'add', 'delete', 'rename', 'inactive'}: | 986 if action in {'add', 'delete', 'rename', 'inactive'}: |
1006 ui.status(_("no bookmarks set\n")) | 1002 ui.status(_("no bookmarks set\n")) |
1007 elif not repo._activebookmark: | 1003 elif not repo._activebookmark: |
1008 ui.status(_("no active bookmark\n")) | 1004 ui.status(_("no active bookmark\n")) |
1009 else: | 1005 else: |
1010 bookmarks.deactivate(repo) | 1006 bookmarks.deactivate(repo) |
1011 elif action == 'active': | |
1012 book = repo._activebookmark | |
1013 if book is None: | |
1014 return 1 | |
1015 ui.write("%s\n" % book, label=bookmarks.activebookmarklabel) | |
1016 elif action == 'list': | 1007 elif action == 'list': |
1017 names = pycompat.maplist(repo._bookmarks.expandname, names) | 1008 names = pycompat.maplist(repo._bookmarks.expandname, names) |
1018 with ui.formatter('bookmarks', opts) as fm: | 1009 with ui.formatter('bookmarks', opts) as fm: |
1019 bookmarks.printbookmarks(ui, repo, fm, names) | 1010 bookmarks.printbookmarks(ui, repo, fm, names) |
1020 else: | 1011 else: |