Mercurial > hg
annotate hgext/commitextras.py @ 50995:80c243eab724
openvms: duck-punch a bugfix into `environb` object
The official Python3 build for OpenVMS has some crippling bug that we need to
patch dynamically
OpenVMS patches
author | Jean-Francois Pieronne <jf.pieronne@laposte.net> |
---|---|
date | Thu, 03 Aug 2023 02:28:52 +0200 |
parents | d718eddf01d9 |
children | f4733654f144 |
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 |
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, |
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
19 ) |
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 cmdtable = {} |
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
22 command = registrar.command(cmdtable) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
23 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
|
24 |
33547
a6af8560494e
commitextras: check the format of the arguments and no internal key is used
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33546
diff
changeset
|
25 usedinternally = { |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
26 b'amend_source', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
27 b'branch', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
28 b'close', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
29 b'histedit_source', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
30 b'topic', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
31 b'rebase_source', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
32 b'intermediate-source', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
33 b'__touch-noise__', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
34 b'source', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
35 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
|
36 } |
a6af8560494e
commitextras: check the format of the arguments and no internal key is used
Pulkit Goyal <7895pulkit@gmail.com>
parents:
33546
diff
changeset
|
37 |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41532
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): |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
40 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
|
41 options = entry[1] |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41532
diff
changeset
|
42 options.append( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
43 ( |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
44 b'', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
45 b'extra', |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
46 [], |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
47 _(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
|
48 _(b"KEY=VALUE"), |
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
49 ) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41532
diff
changeset
|
50 ) |
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41532
diff
changeset
|
51 |
33546
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
52 |
77c0c36654c8
commitextras: move fb extension to core which add extras to a commit
Pulkit Goyal <7895pulkit@gmail.com>
parents:
diff
changeset
|
53 def _commit(orig, ui, repo, *pats, **opts): |
50928
d718eddf01d9
safehasattr: drop usage in favor of hasattr
Pierre-Yves David <pierre-yves.david@octobus.net>
parents:
48875
diff
changeset
|
54 if hasattr(repo, 'unfiltered'): |
39294
1cb7c9777852
commitextras: work nicely with other extensions
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
36419
diff
changeset
|
55 repo = repo.unfiltered() |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41532
diff
changeset
|
56 |
39294
1cb7c9777852
commitextras: work nicely with other extensions
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
36419
diff
changeset
|
57 class repoextra(repo.__class__): |
1cb7c9777852
commitextras: work nicely with other extensions
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
36419
diff
changeset
|
58 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
|
59 extras = opts.get('extra') |
39295
3a60416c4fd8
commitextras: no need to special case extras=[]
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
39294
diff
changeset
|
60 for raw in extras: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
61 if b'=' not in raw: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41532
diff
changeset
|
62 msg = _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
63 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
|
64 b"KEY=VALUE format" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41532
diff
changeset
|
65 ) |
48370
45a073af50a2
errors: use detailed error for invalid commit-extras argument
Martin von Zweigbergk <martinvonz@google.com>
parents:
43506
diff
changeset
|
66 raise error.InputError(msg % raw) |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
67 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
|
68 if not k: |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
69 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
|
70 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
|
71 if re.search(br'[^\w-]', k): |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41532
diff
changeset
|
72 msg = _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
73 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
|
74 b" '_' and '-'" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41532
diff
changeset
|
75 ) |
48370
45a073af50a2
errors: use detailed error for invalid commit-extras argument
Martin von Zweigbergk <martinvonz@google.com>
parents:
43506
diff
changeset
|
76 raise error.InputError(msg) |
39295
3a60416c4fd8
commitextras: no need to special case extras=[]
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
39294
diff
changeset
|
77 if k in usedinternally: |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41532
diff
changeset
|
78 msg = _( |
43077
687b865b95ad
formatting: byteify all mercurial/ and hgext/ string literals
Augie Fackler <augie@google.com>
parents:
43076
diff
changeset
|
79 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
|
80 b"manually" |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41532
diff
changeset
|
81 ) |
48370
45a073af50a2
errors: use detailed error for invalid commit-extras argument
Martin von Zweigbergk <martinvonz@google.com>
parents:
43506
diff
changeset
|
82 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
|
83 inneropts['extra'][k] = v |
39294
1cb7c9777852
commitextras: work nicely with other extensions
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
36419
diff
changeset
|
84 return super(repoextra, self).commit(*innerpats, **inneropts) |
43076
2372284d9457
formatting: blacken the codebase
Augie Fackler <augie@google.com>
parents:
41532
diff
changeset
|
85 |
39294
1cb7c9777852
commitextras: work nicely with other extensions
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
36419
diff
changeset
|
86 repo.__class__ = repoextra |
1cb7c9777852
commitextras: work nicely with other extensions
Valentin Gatien-Baron <vgatien-baron@janestreet.com>
parents:
36419
diff
changeset
|
87 return orig(ui, repo, *pats, **opts) |