author | Raphaël Gomès <rgomes@octobus.net> |
Fri, 13 Jan 2023 00:07:07 +0100 | |
changeset 49954 | a11237723332 |
parent 48875 | 6000f5b25c9b |
child 50928 | d718eddf01d9 |
permissions | -rw-r--r-- |
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 |
|
33602
27fbca750b4d
commitextras: make sure keys contains ascii letters, numbers, '_' and '-' only
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33562
diff
changeset
|
11 |
import re |
27fbca750b4d
commitextras: make sure keys contains ascii letters, numbers, '_' and '-' only
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33562
diff
changeset
|
12 |
|
33546
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
13 |
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
|
14 |
from mercurial import ( |
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
15 |
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
|
16 |
error, |
33546
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
17 |
extensions, |
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
18 |
registrar, |
39294
1cb7c9777852
commitextras: work nicely with other extensions
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
36419
diff
changeset
|
19 |
util, |
33546
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) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
24 |
testedwith = b'ships-with-hg-core' |
33546
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 = { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
27 |
b'amend_source', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
28 |
b'branch', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
29 |
b'close', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
30 |
b'histedit_source', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
31 |
b'topic', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
32 |
b'rebase_source', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
33 |
b'intermediate-source', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
34 |
b'__touch-noise__', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
35 |
b'source', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
36 |
b'transplant_source', |
33547
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 |
|
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41532
diff
changeset
|
39 |
|
33546
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
40 |
def extsetup(ui): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
41 |
entry = extensions.wrapcommand(commands.table, b'commit', _commit) |
33546
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
42 |
options = entry[1] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41532
diff
changeset
|
43 |
options.append( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
44 |
( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
45 |
b'', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
46 |
b'extra', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
47 |
[], |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
48 |
_(b'set a changeset\'s extra values'), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
49 |
_(b"KEY=VALUE"), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
50 |
) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41532
diff
changeset
|
51 |
) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41532
diff
changeset
|
52 |
|
33546
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
53 |
|
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
54 |
def _commit(orig, ui, repo, *pats, **opts): |
43115
4aa72cdf616f
py3: delete b'' prefix from safehasattr arguments
Martin von Zweigbergk <martinvonz@google.com>
parents:
43077
diff
changeset
|
55 |
if util.safehasattr(repo, 'unfiltered'): |
39294
1cb7c9777852
commitextras: work nicely with other extensions
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
36419
diff
changeset
|
56 |
repo = repo.unfiltered() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41532
diff
changeset
|
57 |
|
39294
1cb7c9777852
commitextras: work nicely with other extensions
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
36419
diff
changeset
|
58 |
class repoextra(repo.__class__): |
1cb7c9777852
commitextras: work nicely with other extensions
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
36419
diff
changeset
|
59 |
def commit(self, *innerpats, **inneropts): |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43115
diff
changeset
|
60 |
extras = opts.get('extra') |
39295
3a60416c4fd8
commitextras: no need to special case extras=[]
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
39294
diff
changeset
|
61 |
for raw in extras: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
62 |
if b'=' not in raw: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41532
diff
changeset
|
63 |
msg = _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
64 |
b"unable to parse '%s', should follow " |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
65 |
b"KEY=VALUE format" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41532
diff
changeset
|
66 |
) |
48370
45a073af50a2
errors: use detailed error for invalid commit-extras argument
Martin von Zweigbergk <martinvonz@google.com>
parents:
43506
diff
changeset
|
67 |
raise error.InputError(msg % raw) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
68 |
k, v = raw.split(b'=', 1) |
39295
3a60416c4fd8
commitextras: no need to special case extras=[]
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
39294
diff
changeset
|
69 |
if not k: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
70 |
msg = _(b"unable to parse '%s', keys can't be empty") |
48370
45a073af50a2
errors: use detailed error for invalid commit-extras argument
Martin von Zweigbergk <martinvonz@google.com>
parents:
43506
diff
changeset
|
71 |
raise error.InputError(msg % raw) |
41532
bd3f03d8cc9f
global: use raw strings for regular expressions with escapes
Gregory Szorc <gregory.szorc@gmail.com>
parents:
39295
diff
changeset
|
72 |
if re.search(br'[^\w-]', k): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41532
diff
changeset
|
73 |
msg = _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
74 |
b"keys can only contain ascii letters, digits," |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
75 |
b" '_' and '-'" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41532
diff
changeset
|
76 |
) |
48370
45a073af50a2
errors: use detailed error for invalid commit-extras argument
Martin von Zweigbergk <martinvonz@google.com>
parents:
43506
diff
changeset
|
77 |
raise error.InputError(msg) |
39295
3a60416c4fd8
commitextras: no need to special case extras=[]
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
39294
diff
changeset
|
78 |
if k in usedinternally: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41532
diff
changeset
|
79 |
msg = _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
80 |
b"key '%s' is used internally, can't be set " |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
81 |
b"manually" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41532
diff
changeset
|
82 |
) |
48370
45a073af50a2
errors: use detailed error for invalid commit-extras argument
Martin von Zweigbergk <martinvonz@google.com>
parents:
43506
diff
changeset
|
83 |
raise error.InputError(msg % k) |
43506
9f70512ae2cf
cleanup: remove pointless r-prefixes on single-quoted strings
Augie Fackler <augie@google.com>
parents:
43115
diff
changeset
|
84 |
inneropts['extra'][k] = v |
39294
1cb7c9777852
commitextras: work nicely with other extensions
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
36419
diff
changeset
|
85 |
return super(repoextra, self).commit(*innerpats, **inneropts) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41532
diff
changeset
|
86 |
|
39294
1cb7c9777852
commitextras: work nicely with other extensions
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
36419
diff
changeset
|
87 |
repo.__class__ = repoextra |
1cb7c9777852
commitextras: work nicely with other extensions
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
36419
diff
changeset
|
88 |
return orig(ui, repo, *pats, **opts) |