Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/commands.py @ 39764:78ee63c77bb3
bookmarks: refactor option checking to pick one from --delete/rename/active
author | Yuya Nishihara <yuya@tcha.org> |
---|---|
date | Sat, 15 Sep 2018 12:04:29 +0900 |
parents | 81d1c963e94a |
children | 2b91805e34c7 |
comparison
equal
deleted
inserted
replaced
39763:81d1c963e94a | 39764:78ee63c77bb3 |
---|---|
959 hg book -f @ | 959 hg book -f @ |
960 ''' | 960 ''' |
961 opts = pycompat.byteskwargs(opts) | 961 opts = pycompat.byteskwargs(opts) |
962 force = opts.get('force') | 962 force = opts.get('force') |
963 rev = opts.get('rev') | 963 rev = opts.get('rev') |
964 delete = opts.get('delete') | |
965 rename = opts.get('rename') | 964 rename = opts.get('rename') |
966 inactive = opts.get('inactive') | 965 inactive = opts.get('inactive') |
967 active = opts.get('active') | 966 |
968 | 967 selactions = [k for k in ['delete', 'rename', 'active'] if opts.get(k)] |
969 if delete and rename: | 968 if len(selactions) > 1: |
970 raise error.Abort(_("--delete and --rename are incompatible")) | 969 raise error.Abort(_('--%s and --%s are incompatible') |
971 if delete and rev: | 970 % tuple(selactions[:2])) |
972 raise error.Abort(_("--rev is incompatible with --delete")) | 971 if selactions: |
973 if rename and rev: | 972 action = selactions[0] |
974 raise error.Abort(_("--rev is incompatible with --rename")) | 973 else: |
975 if delete and active: | 974 action = None |
976 raise error.Abort(_("--delete is incompatible with --active")) | 975 |
977 if rev and active: | 976 if rev and action in {'delete', 'rename', 'active'}: |
978 raise error.Abort(_("--rev is incompatible with --active")) | 977 raise error.Abort(_("--rev is incompatible with --%s") % action) |
979 if rename and active: | 978 if names and action == 'active': |
980 raise error.Abort(_("--rename is incompatible with --active")) | |
981 if names and active: | |
982 raise error.Abort(_("NAMES is incompatible with --active")) | 979 raise error.Abort(_("NAMES is incompatible with --active")) |
983 if inactive and active: | 980 if inactive and action == 'active': |
984 raise error.Abort(_("--inactive is incompatible with --active")) | 981 raise error.Abort(_("--inactive is incompatible with --active")) |
985 if not names and (delete or rev): | 982 if not names and (action == 'delete' or rev): |
986 raise error.Abort(_("bookmark name required")) | 983 raise error.Abort(_("bookmark name required")) |
987 | 984 |
988 if delete or rename or names or inactive: | 985 if action in {'delete', 'rename'} or names or inactive: |
989 with repo.wlock(), repo.lock(), repo.transaction('bookmark') as tr: | 986 with repo.wlock(), repo.lock(), repo.transaction('bookmark') as tr: |
990 if delete: | 987 if action == 'delete': |
991 names = pycompat.maplist(repo._bookmarks.expandname, names) | 988 names = pycompat.maplist(repo._bookmarks.expandname, names) |
992 bookmarks.delete(repo, tr, names) | 989 bookmarks.delete(repo, tr, names) |
993 elif rename: | 990 elif action == 'rename': |
994 if not names: | 991 if not names: |
995 raise error.Abort(_("new bookmark name required")) | 992 raise error.Abort(_("new bookmark name required")) |
996 elif len(names) > 1: | 993 elif len(names) > 1: |
997 raise error.Abort(_("only one new bookmark name allowed")) | 994 raise error.Abort(_("only one new bookmark name allowed")) |
998 rename = repo._bookmarks.expandname(rename) | 995 rename = repo._bookmarks.expandname(rename) |
1004 ui.status(_("no bookmarks set\n")) | 1001 ui.status(_("no bookmarks set\n")) |
1005 elif not repo._activebookmark: | 1002 elif not repo._activebookmark: |
1006 ui.status(_("no active bookmark\n")) | 1003 ui.status(_("no active bookmark\n")) |
1007 else: | 1004 else: |
1008 bookmarks.deactivate(repo) | 1005 bookmarks.deactivate(repo) |
1009 elif active: | 1006 elif action == 'active': |
1010 book = repo._activebookmark | 1007 book = repo._activebookmark |
1011 if book is None: | 1008 if book is None: |
1012 return 1 | 1009 return 1 |
1013 ui.write("%s\n" % book, label=bookmarks.activebookmarklabel) | 1010 ui.write("%s\n" % book, label=bookmarks.activebookmarklabel) |
1014 else: # show bookmarks | 1011 else: # show bookmarks |