hgext/commitextras.py
changeset 43076 2372284d9457
parent 41532 bd3f03d8cc9f
child 43077 687b865b95ad
equal deleted inserted replaced
43075:57875cf423c9 43076:2372284d9457
    35     '__touch-noise__',
    35     '__touch-noise__',
    36     'source',
    36     'source',
    37     'transplant_source',
    37     'transplant_source',
    38 }
    38 }
    39 
    39 
       
    40 
    40 def extsetup(ui):
    41 def extsetup(ui):
    41     entry = extensions.wrapcommand(commands.table, 'commit', _commit)
    42     entry = extensions.wrapcommand(commands.table, 'commit', _commit)
    42     options = entry[1]
    43     options = entry[1]
    43     options.append(('', 'extra', [],
    44     options.append(
    44         _('set a changeset\'s extra values'), _("KEY=VALUE")))
    45         ('', 'extra', [], _('set a changeset\'s extra values'), _("KEY=VALUE"))
       
    46     )
       
    47 
    45 
    48 
    46 def _commit(orig, ui, repo, *pats, **opts):
    49 def _commit(orig, ui, repo, *pats, **opts):
    47     if util.safehasattr(repo, 'unfiltered'):
    50     if util.safehasattr(repo, 'unfiltered'):
    48         repo = repo.unfiltered()
    51         repo = repo.unfiltered()
       
    52 
    49     class repoextra(repo.__class__):
    53     class repoextra(repo.__class__):
    50         def commit(self, *innerpats, **inneropts):
    54         def commit(self, *innerpats, **inneropts):
    51             extras = opts.get(r'extra')
    55             extras = opts.get(r'extra')
    52             for raw in extras:
    56             for raw in extras:
    53                 if '=' not in raw:
    57                 if '=' not in raw:
    54                     msg = _("unable to parse '%s', should follow "
    58                     msg = _(
    55                             "KEY=VALUE format")
    59                         "unable to parse '%s', should follow "
       
    60                         "KEY=VALUE format"
       
    61                     )
    56                     raise error.Abort(msg % raw)
    62                     raise error.Abort(msg % raw)
    57                 k, v = raw.split('=', 1)
    63                 k, v = raw.split('=', 1)
    58                 if not k:
    64                 if not k:
    59                     msg = _("unable to parse '%s', keys can't be empty")
    65                     msg = _("unable to parse '%s', keys can't be empty")
    60                     raise error.Abort(msg % raw)
    66                     raise error.Abort(msg % raw)
    61                 if re.search(br'[^\w-]', k):
    67                 if re.search(br'[^\w-]', k):
    62                     msg = _("keys can only contain ascii letters, digits,"
    68                     msg = _(
    63                             " '_' and '-'")
    69                         "keys can only contain ascii letters, digits,"
       
    70                         " '_' and '-'"
       
    71                     )
    64                     raise error.Abort(msg)
    72                     raise error.Abort(msg)
    65                 if k in usedinternally:
    73                 if k in usedinternally:
    66                     msg = _("key '%s' is used internally, can't be set "
    74                     msg = _(
    67                             "manually")
    75                         "key '%s' is used internally, can't be set " "manually"
       
    76                     )
    68                     raise error.Abort(msg % k)
    77                     raise error.Abort(msg % k)
    69                 inneropts[r'extra'][k] = v
    78                 inneropts[r'extra'][k] = v
    70             return super(repoextra, self).commit(*innerpats, **inneropts)
    79             return super(repoextra, self).commit(*innerpats, **inneropts)
       
    80 
    71     repo.__class__ = repoextra
    81     repo.__class__ = repoextra
    72     return orig(ui, repo, *pats, **opts)
    82     return orig(ui, repo, *pats, **opts)