mercurial/commands.py
changeset 50827 aad6e62d64f8
parent 50826 36901c182d70
child 50828 13ad1b2ad3b4
equal deleted inserted replaced
50826:36901c182d70 50827:aad6e62d64f8
  1237 
  1237 
  1238       - print only the active bookmark name::
  1238       - print only the active bookmark name::
  1239 
  1239 
  1240           hg book -ql .
  1240           hg book -ql .
  1241     """
  1241     """
  1242     opts = pycompat.byteskwargs(opts)
  1242     force = opts.get('force')
  1243     force = opts.get(b'force')
  1243     rev = opts.get('rev')
  1244     rev = opts.get(b'rev')
  1244     inactive = opts.get('inactive')  # meaning add/rename to inactive bookmark
  1245     inactive = opts.get(b'inactive')  # meaning add/rename to inactive bookmark
  1245 
  1246 
  1246     action = cmdutil.check_at_most_one_arg(opts, 'delete', 'rename', 'list')
  1247     action = cmdutil.check_at_most_one_arg(opts, b'delete', b'rename', b'list')
       
  1248     if action:
  1247     if action:
  1249         cmdutil.check_incompatible_arguments(opts, action, [b'rev'])
  1248         cmdutil.check_incompatible_arguments(opts, action, ['rev'])
  1250     elif names or rev:
  1249     elif names or rev:
  1251         action = b'add'
  1250         action = 'add'
  1252     elif inactive:
  1251     elif inactive:
  1253         action = b'inactive'  # meaning deactivate
  1252         action = 'inactive'  # meaning deactivate
  1254     else:
  1253     else:
  1255         action = b'list'
  1254         action = 'list'
  1256 
  1255 
  1257     cmdutil.check_incompatible_arguments(
  1256     cmdutil.check_incompatible_arguments(opts, 'inactive', ['delete', 'list'])
  1258         opts, b'inactive', [b'delete', b'list']
  1257     if not names and action in {'add', 'delete'}:
  1259     )
       
  1260     if not names and action in {b'add', b'delete'}:
       
  1261         raise error.InputError(_(b"bookmark name required"))
  1258         raise error.InputError(_(b"bookmark name required"))
  1262 
  1259 
  1263     if action in {b'add', b'delete', b'rename', b'inactive'}:
  1260     if action in {'add', 'delete', 'rename', 'inactive'}:
  1264         with repo.wlock(), repo.lock(), repo.transaction(b'bookmark') as tr:
  1261         with repo.wlock(), repo.lock(), repo.transaction(b'bookmark') as tr:
  1265             if action == b'delete':
  1262             if action == 'delete':
  1266                 names = pycompat.maplist(repo._bookmarks.expandname, names)
  1263                 names = pycompat.maplist(repo._bookmarks.expandname, names)
  1267                 bookmarks.delete(repo, tr, names)
  1264                 bookmarks.delete(repo, tr, names)
  1268             elif action == b'rename':
  1265             elif action == 'rename':
  1269                 if not names:
  1266                 if not names:
  1270                     raise error.InputError(_(b"new bookmark name required"))
  1267                     raise error.InputError(_(b"new bookmark name required"))
  1271                 elif len(names) > 1:
  1268                 elif len(names) > 1:
  1272                     raise error.InputError(
  1269                     raise error.InputError(
  1273                         _(b"only one new bookmark name allowed")
  1270                         _(b"only one new bookmark name allowed")
  1274                     )
  1271                     )
  1275                 oldname = repo._bookmarks.expandname(opts[b'rename'])
  1272                 oldname = repo._bookmarks.expandname(opts['rename'])
  1276                 bookmarks.rename(repo, tr, oldname, names[0], force, inactive)
  1273                 bookmarks.rename(repo, tr, oldname, names[0], force, inactive)
  1277             elif action == b'add':
  1274             elif action == 'add':
  1278                 bookmarks.addbookmarks(repo, tr, names, rev, force, inactive)
  1275                 bookmarks.addbookmarks(repo, tr, names, rev, force, inactive)
  1279             elif action == b'inactive':
  1276             elif action == 'inactive':
  1280                 if len(repo._bookmarks) == 0:
  1277                 if len(repo._bookmarks) == 0:
  1281                     ui.status(_(b"no bookmarks set\n"))
  1278                     ui.status(_(b"no bookmarks set\n"))
  1282                 elif not repo._activebookmark:
  1279                 elif not repo._activebookmark:
  1283                     ui.status(_(b"no active bookmark\n"))
  1280                     ui.status(_(b"no active bookmark\n"))
  1284                 else:
  1281                 else:
  1285                     bookmarks.deactivate(repo)
  1282                     bookmarks.deactivate(repo)
  1286     elif action == b'list':
  1283     elif action == 'list':
  1287         names = pycompat.maplist(repo._bookmarks.expandname, names)
  1284         names = pycompat.maplist(repo._bookmarks.expandname, names)
  1288         with ui.formatter(b'bookmarks', opts) as fm:
  1285         with ui.formatter(b'bookmarks', pycompat.byteskwargs(opts)) as fm:
  1289             bookmarks.printbookmarks(ui, repo, fm, names)
  1286             bookmarks.printbookmarks(ui, repo, fm, names)
  1290     else:
  1287     else:
  1291         raise error.ProgrammingError(b'invalid action: %s' % action)
  1288         raise error.ProgrammingError(
       
  1289             b'invalid action: %s' % pycompat.sysbytes(action)
       
  1290         )
  1292 
  1291 
  1293 
  1292 
  1294 @command(
  1293 @command(
  1295     b'branch',
  1294     b'branch',
  1296     [
  1295     [