Mercurial > hg
annotate hgext/commitextras.py @ 37047:fddcb51b5084
wireproto: define permissions-based routing of HTTPv2 wire protocol
Now that we have a scaffolding for serving version 2 of the HTTP
protocol, let's start implementing it.
A good place to start is URL routing and basic request processing
semantics. We can focus on content types, capabilities detect, etc
later.
Version 2 of the HTTP wire protocol encodes the needed permissions
of the request in the URL path. The reasons for this are documented
in the added documentation. In short, a) it makes it really easy and
fail proof for server administrators to implement path-based
authentication and b) it will enable clients to realize very early in
a server exchange that authentication will be required to complete
the operation. This latter point avoids all kinds of complexity and
problems, like dealing with Expect: 100-continue and clients finding
out later during `hg push` that they need to provide authentication.
This will avoid the current badness where clients send a full bundle,
get an HTTP 403, provide authentication, then retransmit the bundle.
In order to implement command checking, we needed to implement a
protocol handler for the new wire protocol. Our handler is just
small enough to run the code we've implemented.
Tests for the defined functionality have been added.
I very much want to refactor the permissions checking code and define
a better response format. But this can be done later. Nothing is
covered by backwards compatibility at this point.
Differential Revision: https://phab.mercurial-scm.org/D2836
author | Gregory Szorc <gregory.szorc@gmail.com> |
---|---|
date | Mon, 19 Mar 2018 16:43:47 -0700 |
parents | 75c76cee1b1b |
children | 1cb7c9777852 |
rev | line source |
---|---|
33546
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
1 # commitextras.py |
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
2 # |
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
3 # Copyright 2013 Facebook, Inc. |
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
4 # |
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
5 # This software may be used and distributed according to the terms of the |
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
6 # GNU General Public License version 2 or any later version. |
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
7 |
33562
3cfabb6cfd51
commitextras: mark the extension as ADVANCED
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33547
diff
changeset
|
8 '''adds a new flag extras to commit (ADVANCED)''' |
33546
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
9 |
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
10 from __future__ import absolute_import |
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
11 |
33602
27fbca750b4d
commitextras: make sure keys contains ascii letters, numbers, '_' and '-' only
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33562
diff
changeset
|
12 import re |
27fbca750b4d
commitextras: make sure keys contains ascii letters, numbers, '_' and '-' only
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33562
diff
changeset
|
13 |
33546
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
14 from mercurial.i18n import _ |
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
15 from mercurial import ( |
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
16 commands, |
33547
a6af8560494e
commitextras: check the format of the arguments and no internal key is used
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33546
diff
changeset
|
17 error, |
33546
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
18 extensions, |
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
19 registrar, |
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
20 ) |
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
21 |
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
22 cmdtable = {} |
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
23 command = registrar.command(cmdtable) |
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
24 testedwith = 'ships-with-hg-core' |
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
25 |
33547
a6af8560494e
commitextras: check the format of the arguments and no internal key is used
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33546
diff
changeset
|
26 usedinternally = { |
a6af8560494e
commitextras: check the format of the arguments and no internal key is used
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33546
diff
changeset
|
27 'amend_source', |
a6af8560494e
commitextras: check the format of the arguments and no internal key is used
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33546
diff
changeset
|
28 'branch', |
a6af8560494e
commitextras: check the format of the arguments and no internal key is used
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33546
diff
changeset
|
29 'close', |
a6af8560494e
commitextras: check the format of the arguments and no internal key is used
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33546
diff
changeset
|
30 'histedit_source', |
a6af8560494e
commitextras: check the format of the arguments and no internal key is used
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33546
diff
changeset
|
31 'topic', |
a6af8560494e
commitextras: check the format of the arguments and no internal key is used
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33546
diff
changeset
|
32 'rebase_source', |
a6af8560494e
commitextras: check the format of the arguments and no internal key is used
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33546
diff
changeset
|
33 'intermediate-source', |
a6af8560494e
commitextras: check the format of the arguments and no internal key is used
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33546
diff
changeset
|
34 '__touch-noise__', |
a6af8560494e
commitextras: check the format of the arguments and no internal key is used
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33546
diff
changeset
|
35 'source', |
a6af8560494e
commitextras: check the format of the arguments and no internal key is used
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33546
diff
changeset
|
36 'transplant_source', |
a6af8560494e
commitextras: check the format of the arguments and no internal key is used
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33546
diff
changeset
|
37 } |
a6af8560494e
commitextras: check the format of the arguments and no internal key is used
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33546
diff
changeset
|
38 |
33546
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
39 def extsetup(ui): |
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
40 entry = extensions.wrapcommand(commands.table, 'commit', _commit) |
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
41 options = entry[1] |
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
42 options.append(('', 'extra', [], |
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
43 _('set a changeset\'s extra values'), _("KEY=VALUE"))) |
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
44 |
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
45 def _commit(orig, ui, repo, *pats, **opts): |
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
46 origcommit = repo.commit |
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
47 try: |
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
48 def _wrappedcommit(*innerpats, **inneropts): |
34975
901a18b03e00
py3: handle keyword arguments in hgext/commitextras.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33606
diff
changeset
|
49 extras = opts.get(r'extra') |
33546
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
50 if extras: |
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
51 for raw in extras: |
33547
a6af8560494e
commitextras: check the format of the arguments and no internal key is used
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33546
diff
changeset
|
52 if '=' not in raw: |
a6af8560494e
commitextras: check the format of the arguments and no internal key is used
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33546
diff
changeset
|
53 msg = _("unable to parse '%s', should follow " |
a6af8560494e
commitextras: check the format of the arguments and no internal key is used
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33546
diff
changeset
|
54 "KEY=VALUE format") |
a6af8560494e
commitextras: check the format of the arguments and no internal key is used
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33546
diff
changeset
|
55 raise error.Abort(msg % raw) |
33546
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
56 k, v = raw.split('=', 1) |
33606
806351695c6a
commitextras: make sure keys are not empty
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33602
diff
changeset
|
57 if not k: |
806351695c6a
commitextras: make sure keys are not empty
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33602
diff
changeset
|
58 msg = _("unable to parse '%s', keys can't be empty") |
806351695c6a
commitextras: make sure keys are not empty
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33602
diff
changeset
|
59 raise error.Abort(msg % raw) |
33602
27fbca750b4d
commitextras: make sure keys contains ascii letters, numbers, '_' and '-' only
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33562
diff
changeset
|
60 if re.search('[^\w-]', k): |
27fbca750b4d
commitextras: make sure keys contains ascii letters, numbers, '_' and '-' only
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33562
diff
changeset
|
61 msg = _("keys can only contain ascii letters, digits," |
27fbca750b4d
commitextras: make sure keys contains ascii letters, numbers, '_' and '-' only
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33562
diff
changeset
|
62 " '_' and '-'") |
27fbca750b4d
commitextras: make sure keys contains ascii letters, numbers, '_' and '-' only
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33562
diff
changeset
|
63 raise error.Abort(msg) |
33547
a6af8560494e
commitextras: check the format of the arguments and no internal key is used
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33546
diff
changeset
|
64 if k in usedinternally: |
a6af8560494e
commitextras: check the format of the arguments and no internal key is used
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33546
diff
changeset
|
65 msg = _("key '%s' is used internally, can't be set " |
a6af8560494e
commitextras: check the format of the arguments and no internal key is used
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33546
diff
changeset
|
66 "manually") |
a6af8560494e
commitextras: check the format of the arguments and no internal key is used
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33546
diff
changeset
|
67 raise error.Abort(msg % k) |
34975
901a18b03e00
py3: handle keyword arguments in hgext/commitextras.py
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33606
diff
changeset
|
68 inneropts[r'extra'][k] = v |
33546
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
69 return origcommit(*innerpats, **inneropts) |
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
70 |
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
71 # This __dict__ logic is needed because the normal |
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
72 # extension.wrapfunction doesn't seem to work. |
36419
75c76cee1b1b
commitextras: fix on Python 3 by using sysstrs for __dict__ ops
Augie Fackler <augie@google.com>
parents:
34975
diff
changeset
|
73 repo.__dict__[r'commit'] = _wrappedcommit |
33546
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
74 return orig(ui, repo, *pats, **opts) |
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
75 finally: |
36419
75c76cee1b1b
commitextras: fix on Python 3 by using sysstrs for __dict__ ops
Augie Fackler <augie@google.com>
parents:
34975
diff
changeset
|
76 del repo.__dict__[r'commit'] |