comparison hgext/commitextras.py @ 33546:77c0c36654c8

commitextras: move fb extension to core which add extras to a commit This patch moves the Facebook extension to add extra fields to a commit to a in-core extension.
author Pulkit Goyal <7895pulkit@gmail.com>
date Wed, 12 Jul 2017 00:23:45 +0530
parents
children a6af8560494e
comparison
equal deleted inserted replaced
33545:8074e2d006c0 33546:77c0c36654c8
1 # commitextras.py
2 #
3 # Copyright 2013 Facebook, Inc.
4 #
5 # This software may be used and distributed according to the terms of the
6 # GNU General Public License version 2 or any later version.
7
8 '''adds a new flag extras to commit'''
9
10 from __future__ import absolute_import
11
12 from mercurial.i18n import _
13 from mercurial import (
14 commands,
15 extensions,
16 registrar,
17 )
18
19 cmdtable = {}
20 command = registrar.command(cmdtable)
21 testedwith = 'ships-with-hg-core'
22
23 def extsetup(ui):
24 entry = extensions.wrapcommand(commands.table, 'commit', _commit)
25 options = entry[1]
26 options.append(('', 'extra', [],
27 _('set a changeset\'s extra values'), _("KEY=VALUE")))
28
29 def _commit(orig, ui, repo, *pats, **opts):
30 origcommit = repo.commit
31 try:
32 def _wrappedcommit(*innerpats, **inneropts):
33 extras = opts.get('extra')
34 if extras:
35 for raw in extras:
36 k, v = raw.split('=', 1)
37 inneropts['extra'][k] = v
38 return origcommit(*innerpats, **inneropts)
39
40 # This __dict__ logic is needed because the normal
41 # extension.wrapfunction doesn't seem to work.
42 repo.__dict__['commit'] = _wrappedcommit
43 return orig(ui, repo, *pats, **opts)
44 finally:
45 del repo.__dict__['commit']