hgext/bookflow.py
changeset 43077 687b865b95ad
parent 43076 2372284d9457
child 43506 9f70512ae2cf
equal deleted inserted replaced
43076:2372284d9457 43077:687b865b95ad
    22     error,
    22     error,
    23     extensions,
    23     extensions,
    24     registrar,
    24     registrar,
    25 )
    25 )
    26 
    26 
    27 MY_NAME = 'bookflow'
    27 MY_NAME = b'bookflow'
    28 
    28 
    29 configtable = {}
    29 configtable = {}
    30 configitem = registrar.configitem(configtable)
    30 configitem = registrar.configitem(configtable)
    31 
    31 
    32 configitem(MY_NAME, 'protect', ['@'])
    32 configitem(MY_NAME, b'protect', [b'@'])
    33 configitem(MY_NAME, 'require-bookmark', True)
    33 configitem(MY_NAME, b'require-bookmark', True)
    34 configitem(MY_NAME, 'enable-branches', False)
    34 configitem(MY_NAME, b'enable-branches', False)
    35 
    35 
    36 cmdtable = {}
    36 cmdtable = {}
    37 command = registrar.command(cmdtable)
    37 command = registrar.command(cmdtable)
    38 
    38 
    39 
    39 
    40 def commit_hook(ui, repo, **kwargs):
    40 def commit_hook(ui, repo, **kwargs):
    41     active = repo._bookmarks.active
    41     active = repo._bookmarks.active
    42     if active:
    42     if active:
    43         if active in ui.configlist(MY_NAME, 'protect'):
    43         if active in ui.configlist(MY_NAME, b'protect'):
    44             raise error.Abort(
    44             raise error.Abort(
    45                 _('cannot commit, bookmark %s is protected') % active
    45                 _(b'cannot commit, bookmark %s is protected') % active
    46             )
    46             )
    47         if not cwd_at_bookmark(repo, active):
    47         if not cwd_at_bookmark(repo, active):
    48             raise error.Abort(
    48             raise error.Abort(
    49                 _(
    49                 _(
    50                     'cannot commit, working directory out of sync with active bookmark'
    50                     b'cannot commit, working directory out of sync with active bookmark'
    51                 ),
    51                 ),
    52                 hint=_("run 'hg up %s'") % active,
    52                 hint=_(b"run 'hg up %s'") % active,
    53             )
    53             )
    54     elif ui.configbool(MY_NAME, 'require-bookmark', True):
    54     elif ui.configbool(MY_NAME, b'require-bookmark', True):
    55         raise error.Abort(_('cannot commit without an active bookmark'))
    55         raise error.Abort(_(b'cannot commit without an active bookmark'))
    56     return 0
    56     return 0
    57 
    57 
    58 
    58 
    59 def bookmarks_update(orig, repo, parents, node):
    59 def bookmarks_update(orig, repo, parents, node):
    60     if len(parents) == 2:
    60     if len(parents) == 2:
    72         marks = repo._bookmarks
    72         marks = repo._bookmarks
    73         for name in names:
    73         for name in names:
    74             if name in marks:
    74             if name in marks:
    75                 raise error.Abort(
    75                 raise error.Abort(
    76                     _(
    76                     _(
    77                         "bookmark %s already exists, to move use the --rev option"
    77                         b"bookmark %s already exists, to move use the --rev option"
    78                     )
    78                     )
    79                     % name
    79                     % name
    80                 )
    80                 )
    81     return orig(repo, tr, names, rev, force, inactive)
    81     return orig(repo, tr, names, rev, force, inactive)
    82 
    82 
    90     rc = orig(ui, repo, *args, **opts)
    90     rc = orig(ui, repo, *args, **opts)
    91     active = repo._bookmarks.active
    91     active = repo._bookmarks.active
    92     if active and not cwd_at_bookmark(repo, active):
    92     if active and not cwd_at_bookmark(repo, active):
    93         ui.warn(
    93         ui.warn(
    94             _(
    94             _(
    95                 "working directory out of sync with active bookmark, run "
    95                 b"working directory out of sync with active bookmark, run "
    96                 "'hg up %s'"
    96                 b"'hg up %s'"
    97             )
    97             )
    98             % active
    98             % active
    99         )
    99         )
   100     return rc
   100     return rc
   101 
   101 
   102 
   102 
   103 def commands_branch(orig, ui, repo, label=None, **opts):
   103 def commands_branch(orig, ui, repo, label=None, **opts):
   104     if label and not opts.get(r'clean') and not opts.get(r'rev'):
   104     if label and not opts.get(r'clean') and not opts.get(r'rev'):
   105         raise error.Abort(
   105         raise error.Abort(
   106             _(
   106             _(
   107                 "creating named branches is disabled and you should use bookmarks"
   107                 b"creating named branches is disabled and you should use bookmarks"
   108             ),
   108             ),
   109             hint="see 'hg help bookflow'",
   109             hint=b"see 'hg help bookflow'",
   110         )
   110         )
   111     return orig(ui, repo, label, **opts)
   111     return orig(ui, repo, label, **opts)
   112 
   112 
   113 
   113 
   114 def cwd_at_bookmark(repo, mark):
   114 def cwd_at_bookmark(repo, mark):
   115     mark_id = repo._bookmarks[mark]
   115     mark_id = repo._bookmarks[mark]
   116     cur_id = repo.lookup('.')
   116     cur_id = repo.lookup(b'.')
   117     return cur_id == mark_id
   117     return cur_id == mark_id
   118 
   118 
   119 
   119 
   120 def uisetup(ui):
   120 def uisetup(ui):
   121     extensions.wrapfunction(bookmarks, 'update', bookmarks_update)
   121     extensions.wrapfunction(bookmarks, b'update', bookmarks_update)
   122     extensions.wrapfunction(bookmarks, 'addbookmarks', bookmarks_addbookmarks)
   122     extensions.wrapfunction(bookmarks, b'addbookmarks', bookmarks_addbookmarks)
   123     extensions.wrapcommand(commands.table, 'commit', commands_commit)
   123     extensions.wrapcommand(commands.table, b'commit', commands_commit)
   124     extensions.wrapcommand(commands.table, 'pull', commands_pull)
   124     extensions.wrapcommand(commands.table, b'pull', commands_pull)
   125     if not ui.configbool(MY_NAME, 'enable-branches'):
   125     if not ui.configbool(MY_NAME, b'enable-branches'):
   126         extensions.wrapcommand(commands.table, 'branch', commands_branch)
   126         extensions.wrapcommand(commands.table, b'branch', commands_branch)