annotate extensions/kwarchive.py @ 337:cd42b8578901

Place "testedwith" at the begin of global variables
author Franz Glasner <fzglas.hg@dom66.de>
date Wed, 17 Jul 2019 09:03:18 +0200
parents eb1e0f129963
children 038cca685729
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
28
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
1 # -*- coding: utf-8 -*-
125
fb7e1e4e4d2c Provide some SCCS markers also to be able to search with "what(1)" also
Franz Glasner <hg@dom66.de>
parents: 124
diff changeset
2 # @(#) $HGheader$
315
e9ded6c1db41 Add a copyright and license note to the revinfo and kwarchive modules and to the README also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
3 # $HGnodeid$
336
eb1e0f129963 More compliance with the private style guide for Mercurial extensions for the metadata of the extensions
Franz Glasner <fzglas.hg@dom66.de>
parents: 332
diff changeset
4 # :-
315
e9ded6c1db41 Add a copyright and license note to the revinfo and kwarchive modules and to the README also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
5 # :Copyright: (C) 2017-2019 Franz Glasner <fzglas.hg@dom66.de>
e9ded6c1db41 Add a copyright and license note to the revinfo and kwarchive modules and to the README also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
6 # :License: This software may be used and distributed according to the
e9ded6c1db41 Add a copyright and license note to the revinfo and kwarchive modules and to the README also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
7 # terms of the GNU General Public License version 2 or any
e9ded6c1db41 Add a copyright and license note to the revinfo and kwarchive modules and to the README also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
8 # later version.
e9ded6c1db41 Add a copyright and license note to the revinfo and kwarchive modules and to the README also.
Franz Glasner <fzglas.hg@dom66.de>
parents: 314
diff changeset
9 # The license is incorporated herein by reference.
336
eb1e0f129963 More compliance with the private style guide for Mercurial extensions for the metadata of the extensions
Franz Glasner <fzglas.hg@dom66.de>
parents: 332
diff changeset
10 # :-
34
7c4addd60935 Put keyword into the extensions itself
Franz Glasner <hg@dom66.de>
parents: 33
diff changeset
11 #
60
eebebd7acc69 Wording of docu
Franz Glasner <hg@dom66.de>
parents: 57
diff changeset
12 """like :hg:`archive` but with keyword expansion within selected files
33
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
13
129
51a4f1f5df09 Docu: enhanced the docu of "kwarchive"
Franz Glasner <hg@dom66.de>
parents: 126
diff changeset
14 Configuration is done in a versioned ``.hgkwarchive`` configuration
51a4f1f5df09 Docu: enhanced the docu of "kwarchive"
Franz Glasner <hg@dom66.de>
parents: 126
diff changeset
15 file. This file uses the same syntax as all other Mercurial
33
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
16 configuration files.
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
17
129
51a4f1f5df09 Docu: enhanced the docu of "kwarchive"
Franz Glasner <hg@dom66.de>
parents: 126
diff changeset
18 The ``[patterns]`` section specifies which files should have the
51a4f1f5df09 Docu: enhanced the docu of "kwarchive"
Franz Glasner <hg@dom66.de>
parents: 126
diff changeset
19 keywords expanded and possibly the style of expansion. The keys are
51a4f1f5df09 Docu: enhanced the docu of "kwarchive"
Franz Glasner <hg@dom66.de>
parents: 126
diff changeset
20 Mercurial file name patterns as described in :hg:`patterns`.
33
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
21
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
22 Example::
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
23
120
9ed197b60e99 Prepare a [keywords] section with a whitelist of considered keywords and/or aliases
Franz Glasner <hg@dom66.de>
parents: 119
diff changeset
24 #
299
bbbb23202d6e - FIX: Typo in docu
Franz Glasner <hg@dom66.de>
parents: 298
diff changeset
25 # Determine which files are considered for keyword expansion in
120
9ed197b60e99 Prepare a [keywords] section with a whitelist of considered keywords and/or aliases
Franz Glasner <hg@dom66.de>
parents: 119
diff changeset
26 # which style
9ed197b60e99 Prepare a [keywords] section with a whitelist of considered keywords and/or aliases
Franz Glasner <hg@dom66.de>
parents: 119
diff changeset
27 #
33
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
28 [patterns]
299
bbbb23202d6e - FIX: Typo in docu
Franz Glasner <hg@dom66.de>
parents: 298
diff changeset
29 #
bbbb23202d6e - FIX: Typo in docu
Franz Glasner <hg@dom66.de>
parents: 298
diff changeset
30 # Expand keywords in every python file except those matching "x*"
bbbb23202d6e - FIX: Typo in docu
Franz Glasner <hg@dom66.de>
parents: 298
diff changeset
31 # using the default RCS style expansion format
bbbb23202d6e - FIX: Typo in docu
Franz Glasner <hg@dom66.de>
parents: 298
diff changeset
32 #
bbbb23202d6e - FIX: Typo in docu
Franz Glasner <hg@dom66.de>
parents: 298
diff changeset
33 **.py =
bbbb23202d6e - FIX: Typo in docu
Franz Glasner <hg@dom66.de>
parents: 298
diff changeset
34 x* = NO
bbbb23202d6e - FIX: Typo in docu
Franz Glasner <hg@dom66.de>
parents: 298
diff changeset
35 # This file has reStructuredText style keyword expansion "|VCS<kw>|" only
bbbb23202d6e - FIX: Typo in docu
Franz Glasner <hg@dom66.de>
parents: 298
diff changeset
36 path:VERSION = reST
bbbb23202d6e - FIX: Typo in docu
Franz Glasner <hg@dom66.de>
parents: 298
diff changeset
37 # This file has reStructuredText style and RCS style keyword expansion
bbbb23202d6e - FIX: Typo in docu
Franz Glasner <hg@dom66.de>
parents: 298
diff changeset
38 path:README = reST, RCS
33
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
39
246
d23d3d97c106 FIX: Typo in docu: [keyword] -> [keywords]
Franz Glasner <hg@dom66.de>
parents: 160
diff changeset
40 The ``[keywords]`` section specifies which keywords are expanded. Aliases
129
51a4f1f5df09 Docu: enhanced the docu of "kwarchive"
Franz Glasner <hg@dom66.de>
parents: 126
diff changeset
41 can be defined also. By default the pre-defined set of RCC/CVS/SVN-like
51a4f1f5df09 Docu: enhanced the docu of "kwarchive"
Franz Glasner <hg@dom66.de>
parents: 126
diff changeset
42 keywords is expanded. A non-empty ``[keyword]`` section defines an
51a4f1f5df09 Docu: enhanced the docu of "kwarchive"
Franz Glasner <hg@dom66.de>
parents: 126
diff changeset
43 explicit white-list of expanded keywords and/or aliases.
51a4f1f5df09 Docu: enhanced the docu of "kwarchive"
Franz Glasner <hg@dom66.de>
parents: 126
diff changeset
44
51a4f1f5df09 Docu: enhanced the docu of "kwarchive"
Franz Glasner <hg@dom66.de>
parents: 126
diff changeset
45 Example::
51a4f1f5df09 Docu: enhanced the docu of "kwarchive"
Franz Glasner <hg@dom66.de>
parents: 126
diff changeset
46
120
9ed197b60e99 Prepare a [keywords] section with a whitelist of considered keywords and/or aliases
Franz Glasner <hg@dom66.de>
parents: 119
diff changeset
47 #
9ed197b60e99 Prepare a [keywords] section with a whitelist of considered keywords and/or aliases
Franz Glasner <hg@dom66.de>
parents: 119
diff changeset
48 # Determine which keywords are expanded.
9ed197b60e99 Prepare a [keywords] section with a whitelist of considered keywords and/or aliases
Franz Glasner <hg@dom66.de>
parents: 119
diff changeset
49 # A missing and/or empty section means that all predefined keywords
9ed197b60e99 Prepare a [keywords] section with a whitelist of considered keywords and/or aliases
Franz Glasner <hg@dom66.de>
parents: 119
diff changeset
50 # are expanded.
9ed197b60e99 Prepare a [keywords] section with a whitelist of considered keywords and/or aliases
Franz Glasner <hg@dom66.de>
parents: 119
diff changeset
51 #
124
46b7d34ef0b2 Enhanced the module documentation of "kwarchive"
Franz Glasner <hg@dom66.de>
parents: 122
diff changeset
52 # Consisting of key-value pairs with of the form
46b7d34ef0b2 Enhanced the module documentation of "kwarchive"
Franz Glasner <hg@dom66.de>
parents: 122
diff changeset
53 #
46b7d34ef0b2 Enhanced the module documentation of "kwarchive"
Franz Glasner <hg@dom66.de>
parents: 122
diff changeset
54 # Alias = PreDefinedKeyword
46b7d34ef0b2 Enhanced the module documentation of "kwarchive"
Franz Glasner <hg@dom66.de>
parents: 122
diff changeset
55 #
46b7d34ef0b2 Enhanced the module documentation of "kwarchive"
Franz Glasner <hg@dom66.de>
parents: 122
diff changeset
56 # An empty `PreDefinedKeyword' means the identity.
46b7d34ef0b2 Enhanced the module documentation of "kwarchive"
Franz Glasner <hg@dom66.de>
parents: 122
diff changeset
57 #
120
9ed197b60e99 Prepare a [keywords] section with a whitelist of considered keywords and/or aliases
Franz Glasner <hg@dom66.de>
parents: 119
diff changeset
58 [keywords]
122
e6037655967b Implemented a keyword white-list including aliases.
Franz Glasner <hg@dom66.de>
parents: 120
diff changeset
59 # `Revision' and possibly the `VCSRevision' keyword is expanded
120
9ed197b60e99 Prepare a [keywords] section with a whitelist of considered keywords and/or aliases
Franz Glasner <hg@dom66.de>
parents: 119
diff changeset
60 Revision =
124
46b7d34ef0b2 Enhanced the module documentation of "kwarchive"
Franz Glasner <hg@dom66.de>
parents: 122
diff changeset
61 #
46b7d34ef0b2 Enhanced the module documentation of "kwarchive"
Franz Glasner <hg@dom66.de>
parents: 122
diff changeset
62 # Additionally: `MyKeyword' is expanded with the contents of the
321
103df4b7a0c8 A new more flexible syntax for custom keyword expansion: with Python template format syntax now
Franz Glasner <fzglas.hg@dom66.de>
parents: 315
diff changeset
63 # pre-defined `JustDate' (this is in Python's format syntax).
124
46b7d34ef0b2 Enhanced the module documentation of "kwarchive"
Franz Glasner <hg@dom66.de>
parents: 122
diff changeset
64 #
321
103df4b7a0c8 A new more flexible syntax for custom keyword expansion: with Python template format syntax now
Franz Glasner <fzglas.hg@dom66.de>
parents: 315
diff changeset
65 MyKeyword = {JustDate}
133
8d16138e00af Implemented substitution type keyword expansion
Franz Glasner <hg@dom66.de>
parents: 131
diff changeset
66 #
321
103df4b7a0c8 A new more flexible syntax for custom keyword expansion: with Python template format syntax now
Franz Glasner <fzglas.hg@dom66.de>
parents: 315
diff changeset
67 # `MyCustomSubstKeyword' is a substitution keyword.
133
8d16138e00af Implemented substitution type keyword expansion
Franz Glasner <hg@dom66.de>
parents: 131
diff changeset
68 #
321
103df4b7a0c8 A new more flexible syntax for custom keyword expansion: with Python template format syntax now
Franz Glasner <fzglas.hg@dom66.de>
parents: 315
diff changeset
69 MyCustomSubstKeyword = This is my replacement content
120
9ed197b60e99 Prepare a [keywords] section with a whitelist of considered keywords and/or aliases
Franz Glasner <hg@dom66.de>
parents: 119
diff changeset
70
33
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
71 A non-existing ``.hgkwarchive`` file deactivates keyword expansion as does
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
72 an empty ``[patterns]`` section.
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
73
130
c3397e670063 Docu: drop a note why templates are not supported in keyword definitions
Franz Glasner <hg@dom66.de>
parents: 129
diff changeset
74 .. note:: Because the keyword expansion is defined in a *versioned* file
c3397e670063 Docu: drop a note why templates are not supported in keyword definitions
Franz Glasner <hg@dom66.de>
parents: 129
diff changeset
75 no templating is supported here. This could lead to remote
c3397e670063 Docu: drop a note why templates are not supported in keyword definitions
Franz Glasner <hg@dom66.de>
parents: 129
diff changeset
76 code execution secnarios because Mercurial templates can execute
c3397e670063 Docu: drop a note why templates are not supported in keyword definitions
Franz Glasner <hg@dom66.de>
parents: 129
diff changeset
77 a big bunch of Python functions.
c3397e670063 Docu: drop a note why templates are not supported in keyword definitions
Franz Glasner <hg@dom66.de>
parents: 129
diff changeset
78
137
5e502e9dd5e5 As an example: put the |VCSRevision| into the extensions also and print it with the help output
Franz Glasner <hg@dom66.de>
parents: 136
diff changeset
79 (rev |VCSRevision|)
5e502e9dd5e5 As an example: put the |VCSRevision| into the extensions also and print it with the help output
Franz Glasner <hg@dom66.de>
parents: 136
diff changeset
80
28
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
81 """
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
82
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
83 from __future__ import absolute_import
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
84
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
85
336
eb1e0f129963 More compliance with the private style guide for Mercurial extensions for the metadata of the extensions
Franz Glasner <fzglas.hg@dom66.de>
parents: 332
diff changeset
86 __revision__ = "|VCSRevision|"
eb1e0f129963 More compliance with the private style guide for Mercurial extensions for the metadata of the extensions
Franz Glasner <fzglas.hg@dom66.de>
parents: 332
diff changeset
87 __date__ = "|VCSJustDate|"
28
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
88 __author__ = "Franz Glasner"
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
89
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
90
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
91 import os
332
04deddddc6e5 Sort imports properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 331
diff changeset
92 import inspect
33
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
93 import itertools
28
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
94
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
95 from mercurial.i18n import _
288
0080dab59fac Begin tests with subrepos and some preparations for nested subrepos
Franz Glasner <hg@dom66.de>
parents: 287
diff changeset
96 from mercurial import (archival, config, cmdutil, error, match, subrepo,
300
56df37d7878e Keywords HGlatesttags, HGlatesttagdistance, HGlatesttagdate and HGlatesttagjustdate
Franz Glasner <hg@dom66.de>
parents: 299
diff changeset
97 pycompat, scmutil, templatefilters, templatekw,
307
f8aa592b344e FIX: Mercurial's "demandimport" defeats the "try: import ...; except ImportError" idiom; temporarily disable demandimport before doing such imports in kwarchive
Franz Glasner <hg@dom66.de>
parents: 304
diff changeset
98 util, node, demandimport)
326
26e617693ae8 FIX: kwarchive and revinfo do not run on versions prior to Mercurial 4.3 after testing this with unit-tests
Franz Glasner <fzglas.hg@dom66.de>
parents: 322
diff changeset
99 with demandimport.deactivated():
307
f8aa592b344e FIX: Mercurial's "demandimport" defeats the "try: import ...; except ImportError" idiom; temporarily disable demandimport before doing such imports in kwarchive
Franz Glasner <hg@dom66.de>
parents: 304
diff changeset
100 try:
f8aa592b344e FIX: Mercurial's "demandimport" defeats the "try: import ...; except ImportError" idiom; temporarily disable demandimport before doing such imports in kwarchive
Franz Glasner <hg@dom66.de>
parents: 304
diff changeset
101 from mercurial import registrar
f8aa592b344e FIX: Mercurial's "demandimport" defeats the "try: import ...; except ImportError" idiom; temporarily disable demandimport before doing such imports in kwarchive
Franz Glasner <hg@dom66.de>
parents: 304
diff changeset
102 except ImportError:
f8aa592b344e FIX: Mercurial's "demandimport" defeats the "try: import ...; except ImportError" idiom; temporarily disable demandimport before doing such imports in kwarchive
Franz Glasner <hg@dom66.de>
parents: 304
diff changeset
103 registrar = None
f8aa592b344e FIX: Mercurial's "demandimport" defeats the "try: import ...; except ImportError" idiom; temporarily disable demandimport before doing such imports in kwarchive
Franz Glasner <hg@dom66.de>
parents: 304
diff changeset
104 # check for new template function API with `(context, mapping)`
f8aa592b344e FIX: Mercurial's "demandimport" defeats the "try: import ...; except ImportError" idiom; temporarily disable demandimport before doing such imports in kwarchive
Franz Glasner <hg@dom66.de>
parents: 304
diff changeset
105 try:
f8aa592b344e FIX: Mercurial's "demandimport" defeats the "try: import ...; except ImportError" idiom; temporarily disable demandimport before doing such imports in kwarchive
Franz Glasner <hg@dom66.de>
parents: 304
diff changeset
106 from mercurial import templatefuncs
f8aa592b344e FIX: Mercurial's "demandimport" defeats the "try: import ...; except ImportError" idiom; temporarily disable demandimport before doing such imports in kwarchive
Franz Glasner <hg@dom66.de>
parents: 304
diff changeset
107 except ImportError:
f8aa592b344e FIX: Mercurial's "demandimport" defeats the "try: import ...; except ImportError" idiom; temporarily disable demandimport before doing such imports in kwarchive
Franz Glasner <hg@dom66.de>
parents: 304
diff changeset
108 context_mapping_api = False
f8aa592b344e FIX: Mercurial's "demandimport" defeats the "try: import ...; except ImportError" idiom; temporarily disable demandimport before doing such imports in kwarchive
Franz Glasner <hg@dom66.de>
parents: 304
diff changeset
109 else:
f8aa592b344e FIX: Mercurial's "demandimport" defeats the "try: import ...; except ImportError" idiom; temporarily disable demandimport before doing such imports in kwarchive
Franz Glasner <hg@dom66.de>
parents: 304
diff changeset
110 # >= 4.6
f8aa592b344e FIX: Mercurial's "demandimport" defeats the "try: import ...; except ImportError" idiom; temporarily disable demandimport before doing such imports in kwarchive
Franz Glasner <hg@dom66.de>
parents: 304
diff changeset
111 context_mapping_api = True
f8aa592b344e FIX: Mercurial's "demandimport" defeats the "try: import ...; except ImportError" idiom; temporarily disable demandimport before doing such imports in kwarchive
Franz Glasner <hg@dom66.de>
parents: 304
diff changeset
112 # some date specific util functions moved to new mercurial.utils.dateutil
f8aa592b344e FIX: Mercurial's "demandimport" defeats the "try: import ...; except ImportError" idiom; temporarily disable demandimport before doing such imports in kwarchive
Franz Glasner <hg@dom66.de>
parents: 304
diff changeset
113 try:
f8aa592b344e FIX: Mercurial's "demandimport" defeats the "try: import ...; except ImportError" idiom; temporarily disable demandimport before doing such imports in kwarchive
Franz Glasner <hg@dom66.de>
parents: 304
diff changeset
114 from mercurial.utils import dateutil as _dateutil
f8aa592b344e FIX: Mercurial's "demandimport" defeats the "try: import ...; except ImportError" idiom; temporarily disable demandimport before doing such imports in kwarchive
Franz Glasner <hg@dom66.de>
parents: 304
diff changeset
115 except ImportError:
f8aa592b344e FIX: Mercurial's "demandimport" defeats the "try: import ...; except ImportError" idiom; temporarily disable demandimport before doing such imports in kwarchive
Franz Glasner <hg@dom66.de>
parents: 304
diff changeset
116 _dateutil = util
28
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
117
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
118
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
119 testedwith = b"4.3.1 4.3.2 4.4.1 4.4.2 4.5.2 4.6.1 4.8.1 4.9 5.0.1"
28
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
120
51
3807a60ee0dd Shorten path urls by default when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 47
diff changeset
121 SHORTENED_HG_SCHEMES = {
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
122 b"ssh": b"hg+ssh",
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
123 b"http": b"hg+http",
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
124 b"https": b"hg+https",
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
125 b"file": b"file",
51
3807a60ee0dd Shorten path urls by default when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 47
diff changeset
126 }
3807a60ee0dd Shorten path urls by default when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 47
diff changeset
127
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
128 KWARCHIVE_CONFIG = b".hgkwarchive"
156
d92850f876a4 Use a constant to define the ".hgkwarchive" name
Franz Glasner <hg@dom66.de>
parents: 155
diff changeset
129
28
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
130 cmdtable = {}
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
131
326
26e617693ae8 FIX: kwarchive and revinfo do not run on versions prior to Mercurial 4.3 after testing this with unit-tests
Franz Glasner <fzglas.hg@dom66.de>
parents: 322
diff changeset
132 if registrar and hasattr(registrar, "command"):
248
436b2db75a34 cmdutil.command is deprecated: use registrar.command instead; also need always a repository for the commands: inferrepo=True
Franz Glasner <hg@dom66.de>
parents: 246
diff changeset
133 command = registrar.command(cmdtable)
436b2db75a34 cmdutil.command is deprecated: use registrar.command instead; also need always a repository for the commands: inferrepo=True
Franz Glasner <hg@dom66.de>
parents: 246
diff changeset
134 else:
436b2db75a34 cmdutil.command is deprecated: use registrar.command instead; also need always a repository for the commands: inferrepo=True
Franz Glasner <hg@dom66.de>
parents: 246
diff changeset
135 command = cmdutil.command(cmdtable)
28
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
136
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
137
150
f195b4704726 For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents: 147
diff changeset
138 def getversion():
f195b4704726 For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents: 147
diff changeset
139 """Provide the version information for verbose :hg:`version` output.
f195b4704726 For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents: 147
diff changeset
140
f195b4704726 For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents: 147
diff changeset
141 Read the :file:`VERSION` from the parent of the :file:`extensions`
f195b4704726 For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents: 147
diff changeset
142 directory.
f195b4704726 For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents: 147
diff changeset
143
f195b4704726 For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents: 147
diff changeset
144 """
f195b4704726 For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents: 147
diff changeset
145 import re
f195b4704726 For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents: 147
diff changeset
146 import os
f195b4704726 For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents: 147
diff changeset
147 try:
f195b4704726 For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents: 147
diff changeset
148 fn = __file__
f195b4704726 For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents: 147
diff changeset
149 except NameError:
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
150 return b"<unknown>"
150
f195b4704726 For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents: 147
diff changeset
151 else:
f195b4704726 For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents: 147
diff changeset
152 try:
157
e12025e46375 Use util.posixfile when reading a custom given .hgkwarchive file for Mercurial portability reasons
Franz Glasner <hg@dom66.de>
parents: 156
diff changeset
153 # this is pure Python standard functionality: no util.posixfile
150
f195b4704726 For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents: 147
diff changeset
154 verdata = open(os.path.join(os.path.dirname(fn),
f195b4704726 For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents: 147
diff changeset
155 "../VERSION"),
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
156 "rb").read()
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
157 return re.search(b"^(.*)", verdata,).group(1)
150
f195b4704726 For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents: 147
diff changeset
158 except OSError:
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
159 return b"<not found>"
150
f195b4704726 For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents: 147
diff changeset
160
f195b4704726 For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents: 147
diff changeset
161
114
a51822141ccf Style: handled some more flake8 warnings: consistent command declaration list formatting
Franz Glasner <hg@dom66.de>
parents: 112
diff changeset
162 @command(
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
163 b"kwarchive",
114
a51822141ccf Style: handled some more flake8 warnings: consistent command declaration list formatting
Franz Glasner <hg@dom66.de>
parents: 112
diff changeset
164 [
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
165 (b'', b"no-decode", None, _(b"do not pass files through decoders")),
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
166 (b'p', b"prefix", b'', _(b"directory prefix for files in archive"), _(b"PREFIX")),
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
167 (b'r', b"rev", b'', _(b"revision to distribute"), _(b"REV")),
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
168 (b't', b"type", b'', _(b"type of distribution to create"), _(b"TYPE")),
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
169 (b'', b"path", b"default", _(b"the canonical repository to use"), _(b"PATH")),
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
170 (b'', b"kwconfig", b'', _(b"an alternate pattern configuration configuration file (possibly used for subrepos also)"), _(b"PATTERNCONFIG")),
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
171 (b'', b"no-shorten-path", None, _(b"don't shorten the path urls")),
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
172 (b'', b"path-filter", b"short", _(b"determine how the path will be printed")),
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
173 (b'', b"user-filter", b"user", _(b"the part of the user to be printed"), _(b"USERFILTER"))
28
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
174 ] + cmdutil.subrepoopts + cmdutil.walkopts,
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
175 _(b"[OPTION]... DEST"),
248
436b2db75a34 cmdutil.command is deprecated: use registrar.command instead; also need always a repository for the commands: inferrepo=True
Franz Glasner <hg@dom66.de>
parents: 246
diff changeset
176 inferrepo=True)
28
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
177 def kwarchive(ui, repo, dest, **opts):
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
178 '''create an unversioned archive of a repository revision with some keywords expanded
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
179
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
180 By default, the revision used is the parent of the working
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
181 directory; use -r/--rev to specify a different revision.
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
182
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
183 The archive type is automatically detected based on file
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
184 extension (to override, use -t/--type).
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
185
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
186 .. container:: verbose
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
187
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
188 Examples:
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
189
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
190 - create a zip file containing the 1.0 release::
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
191
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
192 hg archive -r 1.0 project-1.0.zip
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
193
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
194 - create a tarball excluding .hg files::
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
195
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
196 hg archive project.tar.gz -X ".hg*"
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
197
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
198 Valid types are:
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
199
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
200 :``files``: a directory full of files (default)
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
201 :``tar``: tar archive, uncompressed
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
202 :``tbz2``: tar archive, compressed using bzip2
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
203 :``tgz``: tar archive, compressed using gzip
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
204 :``uzip``: zip archive, uncompressed
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
205 :``zip``: zip archive, compressed using deflate
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
206
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
207 The exact name of the destination archive or directory is given
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
208 using a format string; see :hg:`help export` for details.
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
209
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
210 Each member added to an archive file has a directory prefix
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
211 prepended. Use -p/--prefix to specify a format string for the
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
212 prefix. The default is the basename of the archive, with suffixes
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
213 removed.
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
214
41
c05d8dcb4bb0 Doku: Enhance
Franz Glasner <hg@dom66.de>
parents: 36
diff changeset
215 Use --path to specify named path information from :hg:`paths` as
c05d8dcb4bb0 Doku: Enhance
Franz Glasner <hg@dom66.de>
parents: 36
diff changeset
216 the canonical repository location. Use ``.`` for the current
c05d8dcb4bb0 Doku: Enhance
Franz Glasner <hg@dom66.de>
parents: 36
diff changeset
217 repository root root. If no path is given then ``default`` is
c05d8dcb4bb0 Doku: Enhance
Franz Glasner <hg@dom66.de>
parents: 36
diff changeset
218 assumed.
35
f29c98e54f50 Implement a "--path" option for kwarchive to select a repository to use as canonical one
Franz Glasner <hg@dom66.de>
parents: 34
diff changeset
219
51
3807a60ee0dd Shorten path urls by default when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 47
diff changeset
220 Full path URLs are printed somewhat shortened by default. To use
3807a60ee0dd Shorten path urls by default when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 47
diff changeset
221 them as-is use the --no-shorten-path option.
3807a60ee0dd Shorten path urls by default when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 47
diff changeset
222
65
bdb549d71148 Allow customization of the $Author$ output when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 64
diff changeset
223 Allowed --user-filter values are:
bdb549d71148 Allow customization of the $Author$ output when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 64
diff changeset
224
bdb549d71148 Allow customization of the $Author$ output when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 64
diff changeset
225 :``user``: the short representation of a user name or email address
bdb549d71148 Allow customization of the $Author$ output when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 64
diff changeset
226 :``person``: the name before an email address as per RFC 5322
bdb549d71148 Allow customization of the $Author$ output when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 64
diff changeset
227 :``email``: the email address
81
e02aceb91a9b Make "full" a user filter and "none" an alias to "full"
Franz Glasner <hg@dom66.de>
parents: 80
diff changeset
228 :``full``: the complete user information w/o filtering
e02aceb91a9b Make "full" a user filter and "none" an alias to "full"
Franz Glasner <hg@dom66.de>
parents: 80
diff changeset
229 :``none``: an alias for ``full``
65
bdb549d71148 Allow customization of the $Author$ output when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 64
diff changeset
230
93
fa84debfb50e Replace "no-shorten-url" by "path-filter"
Franz Glasner <hg@dom66.de>
parents: 92
diff changeset
231 The --path-filter values detemine how the path will be printed:
fa84debfb50e Replace "no-shorten-url" by "path-filter"
Franz Glasner <hg@dom66.de>
parents: 92
diff changeset
232
fa84debfb50e Replace "no-shorten-url" by "path-filter"
Franz Glasner <hg@dom66.de>
parents: 92
diff changeset
233 :``full``: the path will be printed as is (including passwords et al.)
fa84debfb50e Replace "no-shorten-url" by "path-filter"
Franz Glasner <hg@dom66.de>
parents: 92
diff changeset
234 :``nopwd``: like ``full`` but without passwords
249
e97f6f6ed7c5 Implement a "nouser" option for the path-filter: like no-pwd but without user information also
Franz Glasner <hg@dom66.de>
parents: 248
diff changeset
235 :``nouser``: like ``full`` but without user and password information
101
ec4392ae8c92 FIX: Wording in help
Franz Glasner <hg@dom66.de>
parents: 100
diff changeset
236 :``short``: shorten the path somehow: no user/password information and
93
fa84debfb50e Replace "no-shorten-url" by "path-filter"
Franz Glasner <hg@dom66.de>
parents: 92
diff changeset
237 only a short server name
100
eed73af1ab79 Implemented a "last" option for the "--path-filter": shorten to the last path component.
Franz Glasner <hg@dom66.de>
parents: 99
diff changeset
238 :``last``: shorten the path to the last component
93
fa84debfb50e Replace "no-shorten-url" by "path-filter"
Franz Glasner <hg@dom66.de>
parents: 92
diff changeset
239
28
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
240 Returns 0 on success.
41
c05d8dcb4bb0 Doku: Enhance
Franz Glasner <hg@dom66.de>
parents: 36
diff changeset
241
28
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
242 '''
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
243
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
244 opts = pycompat.byteskwargs(opts)
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
245 ctx = scmutil.revsingle(repo, opts.get(b"rev"))
28
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
246 if not ctx:
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
247 raise error.Abort(_(b"no Mercurial revision found: please specify a revision"))
28
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
248 node = ctx.node()
103
d6e594644778 Make kwarchive work on Mercurial 4.6+ also: the signature of cmdutil.makefileXXX() have changed
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
249 dest = makefilename_compat(ctx, dest)
28
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
250 if os.path.realpath(dest) == repo.root:
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
251 raise error.Abort(_(b"repository root cannot be destination"))
28
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
252
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
253 kind = opts.get(b"type") or archival.guesskind(dest) or b"files"
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
254 prefix = opts.get(b"prefix")
28
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
255
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
256 if dest == b'-':
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
257 if kind == "files":
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
258 raise error.Abort(_(b"cannot archive plain files to stdout"))
103
d6e594644778 Make kwarchive work on Mercurial 4.6+ also: the signature of cmdutil.makefileXXX() have changed
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
259 dest = makefileobj_compat(ctx, dest)
28
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
260 if not prefix:
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
261 prefix = os.path.basename(repo.root) + b'-%h'
28
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
262
103
d6e594644778 Make kwarchive work on Mercurial 4.6+ also: the signature of cmdutil.makefileXXX() have changed
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
263 prefix = makefilename_compat(ctx, prefix)
28
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
264 matchfn = scmutil.match(ctx, [], opts)
29
58f47399691c New successful PoC: monkey-patch all relevant archiver's "addfile()" method
Franz Glasner <hg@dom66.de>
parents: 28
diff changeset
265
58f47399691c New successful PoC: monkey-patch all relevant archiver's "addfile()" method
Franz Glasner <hg@dom66.de>
parents: 28
diff changeset
266 #
31
0597395e2d18 Comment: better explanation of what is monkey-patched
Franz Glasner <hg@dom66.de>
parents: 30
diff changeset
267 # Monkey patch archival's archivers classes so that an archiver's "addfile()"
29
58f47399691c New successful PoC: monkey-patch all relevant archiver's "addfile()" method
Franz Glasner <hg@dom66.de>
parents: 28
diff changeset
268 # expands keywords
58f47399691c New successful PoC: monkey-patch all relevant archiver's "addfile()" method
Franz Glasner <hg@dom66.de>
parents: 28
diff changeset
269 #
32
cfa53f8a6607 Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents: 31
diff changeset
270 for ac in ("fileit", "tarit", "zipit",):
33
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
271 patch_archiver_class(
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
272 ac,
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
273 make_keyword_filter(
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
274 ui,
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
275 ctx,
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
276 ac,
35
f29c98e54f50 Implement a "--path" option for kwarchive to select a repository to use as canonical one
Franz Glasner <hg@dom66.de>
parents: 34
diff changeset
277 archival.tidyprefix(dest, kind, prefix),
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
278 hgpath=opts.get(b"path"),
136
f470702886b4 Renamed some internal functions to provide a more descriptive name
Franz Glasner <hg@dom66.de>
parents: 134
diff changeset
279 path_filter=get_checked_path_filter_option(opts),
f470702886b4 Renamed some internal functions to provide a more descriptive name
Franz Glasner <hg@dom66.de>
parents: 134
diff changeset
280 user_filter=get_checked_user_filter_option(opts),
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
281 subrepos=opts.get(b"subrepos"),
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
282 kwconfig=opts.get(b"kwconfig")))
30
1670760f695f Monkey-patch all current archivers in mercurial.archival: fileit, tarit and ziptit
Franz Glasner <hg@dom66.de>
parents: 29
diff changeset
283
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
284 archival.archive(repo, dest, node, kind, not opts.get(b"no_decode"),
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
285 matchfn, prefix, subrepos=opts.get(b"subrepos"))
28
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
286
32
cfa53f8a6607 Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents: 31
diff changeset
287 # XXX FIXME: Should the original methods be restored here?
cfa53f8a6607 Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents: 31
diff changeset
288
46
4a0c26dfef3c Comment about automatically amending .hg_archival.txt with "path" items.
Franz Glasner <hg@dom66.de>
parents: 45
diff changeset
289 # XXX FIXME: Should we automatically amend ".hg_archival.txt" with a
4a0c26dfef3c Comment about automatically amending .hg_archival.txt with "path" items.
Franz Glasner <hg@dom66.de>
parents: 45
diff changeset
290 # path item? But this means shat we should know the complete
4a0c26dfef3c Comment about automatically amending .hg_archival.txt with "path" items.
Franz Glasner <hg@dom66.de>
parents: 45
diff changeset
291 # configuration ("ui.archivemeta") and it's name and some
4a0c26dfef3c Comment about automatically amending .hg_archival.txt with "path" items.
Franz Glasner <hg@dom66.de>
parents: 45
diff changeset
292 # output match filters (see archival.archive()).
4a0c26dfef3c Comment about automatically amending .hg_archival.txt with "path" items.
Franz Glasner <hg@dom66.de>
parents: 45
diff changeset
293
32
cfa53f8a6607 Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents: 31
diff changeset
294
114
a51822141ccf Style: handled some more flake8 warnings: consistent command declaration list formatting
Franz Glasner <hg@dom66.de>
parents: 112
diff changeset
295 @command(
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
296 b"kwprint",
114
a51822141ccf Style: handled some more flake8 warnings: consistent command declaration list formatting
Franz Glasner <hg@dom66.de>
parents: 112
diff changeset
297 [
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
298 (b'r', b"rev", b'', _(b"revision to distribute"), _(b"REV")),
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
299 (b'', b"path", b"default", _(b"the canonical repository to use"), _(b"PATH")),
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
300 (b'', b"no-shorten-path", None, _(b"don't shorten the path urls")),
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
301 (b'', b"path-filter", b"short", _(b"determine how the path will be printed")),
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
302 (b'', b"user-filter", b"user", _(b"the part of the user to be printed"), _(b"USERFILTER")),
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
303 (b'', b"reST", None, _(b"output in reST substitution definition syntax")),
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
304 (b'', b"no-file", None, _(b"don't show file-dependent keywords")),
45
c077d30da0ee Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents: 44
diff changeset
305 ] + cmdutil.subrepoopts + cmdutil.walkopts,
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
306 _(b"[OPTION]..."),
248
436b2db75a34 cmdutil.command is deprecated: use registrar.command instead; also need always a repository for the commands: inferrepo=True
Franz Glasner <hg@dom66.de>
parents: 246
diff changeset
307 inferrepo=True)
45
c077d30da0ee Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents: 44
diff changeset
308 def kwprint(ui, repo, **opts):
109
be4811239acf kwprint: print example file-dependent keywords also.
Franz Glasner <hg@dom66.de>
parents: 108
diff changeset
309 '''print the file-independent keywords and for an example file-dependent
be4811239acf kwprint: print example file-dependent keywords also.
Franz Glasner <hg@dom66.de>
parents: 108
diff changeset
310 keywords
45
c077d30da0ee Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents: 44
diff changeset
311
c077d30da0ee Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents: 44
diff changeset
312 By default, the revision used is the parent of the working
c077d30da0ee Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents: 44
diff changeset
313 directory; use -r/--rev to specify a different revision.
c077d30da0ee Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents: 44
diff changeset
314
c077d30da0ee Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents: 44
diff changeset
315 Use --path to specify named path information from :hg:`paths` as
c077d30da0ee Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents: 44
diff changeset
316 the canonical repository location. Use ``.`` for the current
c077d30da0ee Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents: 44
diff changeset
317 repository root root. If no path is given then ``default`` is
c077d30da0ee Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents: 44
diff changeset
318 assumed.
c077d30da0ee Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents: 44
diff changeset
319
51
3807a60ee0dd Shorten path urls by default when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 47
diff changeset
320 Full path URLs are printed somewhat shortened by default. To use
3807a60ee0dd Shorten path urls by default when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 47
diff changeset
321 them as-is use the --no-shorten-path option.
3807a60ee0dd Shorten path urls by default when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 47
diff changeset
322
65
bdb549d71148 Allow customization of the $Author$ output when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 64
diff changeset
323 Allowed --user-filter values are:
bdb549d71148 Allow customization of the $Author$ output when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 64
diff changeset
324
bdb549d71148 Allow customization of the $Author$ output when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 64
diff changeset
325 :``user``: the short representation of a user name or email address
bdb549d71148 Allow customization of the $Author$ output when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 64
diff changeset
326 :``person``: the name before an email address as per RFC 5322
bdb549d71148 Allow customization of the $Author$ output when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 64
diff changeset
327 :``email``: the email address
81
e02aceb91a9b Make "full" a user filter and "none" an alias to "full"
Franz Glasner <hg@dom66.de>
parents: 80
diff changeset
328 :``full``: the complete user information w/o filtering
85
01ca9e1601a7 All extensions work with Mercurial 4.4.1 also
Franz Glasner <hg@dom66.de>
parents: 84
diff changeset
329 :``none``: an alias for ``full``
65
bdb549d71148 Allow customization of the $Author$ output when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 64
diff changeset
330
93
fa84debfb50e Replace "no-shorten-url" by "path-filter"
Franz Glasner <hg@dom66.de>
parents: 92
diff changeset
331 The --path-filter values detemine how the path will be printed:
fa84debfb50e Replace "no-shorten-url" by "path-filter"
Franz Glasner <hg@dom66.de>
parents: 92
diff changeset
332
fa84debfb50e Replace "no-shorten-url" by "path-filter"
Franz Glasner <hg@dom66.de>
parents: 92
diff changeset
333 :``full``: the path will be printed as is (including passwords et al.)
fa84debfb50e Replace "no-shorten-url" by "path-filter"
Franz Glasner <hg@dom66.de>
parents: 92
diff changeset
334 :``nopwd``: like ``full`` but without passwords
249
e97f6f6ed7c5 Implement a "nouser" option for the path-filter: like no-pwd but without user information also
Franz Glasner <hg@dom66.de>
parents: 248
diff changeset
335 :``nouser``: like ``full`` but without user and password information
108
aaf84b607154 FIX: Typo in doc string
Franz Glasner <hg@dom66.de>
parents: 105
diff changeset
336 :``short``: shorten the path somehow: no user/password information and
93
fa84debfb50e Replace "no-shorten-url" by "path-filter"
Franz Glasner <hg@dom66.de>
parents: 92
diff changeset
337 only a short server name
100
eed73af1ab79 Implemented a "last" option for the "--path-filter": shorten to the last path component.
Franz Glasner <hg@dom66.de>
parents: 99
diff changeset
338 :``last``: shorten the path to the last component
93
fa84debfb50e Replace "no-shorten-url" by "path-filter"
Franz Glasner <hg@dom66.de>
parents: 92
diff changeset
339
78
743dd4a77b4a Implemented a "--reST" option for printing reST substitution definitions from keywords
Franz Glasner <hg@dom66.de>
parents: 76
diff changeset
340 Use --reST to output the keyword in a format suitable for including
743dd4a77b4a Implemented a "--reST" option for printing reST substitution definitions from keywords
Franz Glasner <hg@dom66.de>
parents: 76
diff changeset
341 in reStructuredText (reST) documents by using it's substitution feature.
743dd4a77b4a Implemented a "--reST" option for printing reST substitution definitions from keywords
Franz Glasner <hg@dom66.de>
parents: 76
diff changeset
342 All revision keyword names have a ``VCS`` prefix.
743dd4a77b4a Implemented a "--reST" option for printing reST substitution definitions from keywords
Franz Glasner <hg@dom66.de>
parents: 76
diff changeset
343
109
be4811239acf kwprint: print example file-dependent keywords also.
Franz Glasner <hg@dom66.de>
parents: 108
diff changeset
344 Use --no-file to suppress the output of file-dependent keywords with an
be4811239acf kwprint: print example file-dependent keywords also.
Franz Glasner <hg@dom66.de>
parents: 108
diff changeset
345 example file.
be4811239acf kwprint: print example file-dependent keywords also.
Franz Glasner <hg@dom66.de>
parents: 108
diff changeset
346
45
c077d30da0ee Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents: 44
diff changeset
347 Returns 0 on success.
c077d30da0ee Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents: 44
diff changeset
348
c077d30da0ee Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents: 44
diff changeset
349 '''
c077d30da0ee Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents: 44
diff changeset
350
c077d30da0ee Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents: 44
diff changeset
351 opts = pycompat.byteskwargs(opts)
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
352 ctx = scmutil.revsingle(repo, opts.get(b"rev"))
45
c077d30da0ee Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents: 44
diff changeset
353 if not ctx:
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
354 raise error.Abort(_(b"no Mercurial revision found: please specify a revision"))
45
c077d30da0ee Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents: 44
diff changeset
355 node = ctx.node()
c077d30da0ee Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents: 44
diff changeset
356
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
357 prefix = makefilename_compat(ctx, b'')
45
c077d30da0ee Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents: 44
diff changeset
358
c077d30da0ee Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents: 44
diff changeset
359 keywords = make_node_keywords(
293
75070825d111 - make_node_keywords() and make_keyword_filter() do not need a "repo" argument.
Franz Glasner <hg@dom66.de>
parents: 292
diff changeset
360 ui, ctx,
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
361 hgpath=opts.get(b"path"),
136
f470702886b4 Renamed some internal functions to provide a more descriptive name
Franz Glasner <hg@dom66.de>
parents: 134
diff changeset
362 path_filter=get_checked_path_filter_option(opts),
f470702886b4 Renamed some internal functions to provide a more descriptive name
Franz Glasner <hg@dom66.de>
parents: 134
diff changeset
363 user_filter=get_checked_user_filter_option(opts))
109
be4811239acf kwprint: print example file-dependent keywords also.
Franz Glasner <hg@dom66.de>
parents: 108
diff changeset
364 # make file-dependent keywords for an example file
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
365 if not opts.get(b"no_file"):
294
2eb443e77cff Refactor: put the real keyword printing into a separate function.
Franz Glasner <hg@dom66.de>
parents: 293
diff changeset
366 file_keywords = make_file_keywords(
2eb443e77cff Refactor: put the real keyword printing into a separate function.
Franz Glasner <hg@dom66.de>
parents: 293
diff changeset
367 keywords,
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
368 b"dir1/dir2/test.file",
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
369 b"a4dd6f4b22e11fec41158eec187630c24a43120a")
294
2eb443e77cff Refactor: put the real keyword printing into a separate function.
Franz Glasner <hg@dom66.de>
parents: 293
diff changeset
370 else:
2eb443e77cff Refactor: put the real keyword printing into a separate function.
Franz Glasner <hg@dom66.de>
parents: 293
diff changeset
371 file_keywords = None
2eb443e77cff Refactor: put the real keyword printing into a separate function.
Franz Glasner <hg@dom66.de>
parents: 293
diff changeset
372 _kwprint_keywords(ui, keywords, file_keywords,
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
373 opts.get(b"reST"),
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
374 opts.get(b"no_file"))
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
375 if opts.get(b"subrepos"):
294
2eb443e77cff Refactor: put the real keyword printing into a separate function.
Franz Glasner <hg@dom66.de>
parents: 293
diff changeset
376 _kwprint_subrepos(ctx, ui,
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
377 opts.get(b"reST"),
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
378 opts.get(b"no_file"),
294
2eb443e77cff Refactor: put the real keyword printing into a separate function.
Franz Glasner <hg@dom66.de>
parents: 293
diff changeset
379 path_filter=get_checked_path_filter_option(opts),
2eb443e77cff Refactor: put the real keyword printing into a separate function.
Franz Glasner <hg@dom66.de>
parents: 293
diff changeset
380 user_filter=get_checked_user_filter_option(opts))
2eb443e77cff Refactor: put the real keyword printing into a separate function.
Franz Glasner <hg@dom66.de>
parents: 293
diff changeset
381
2eb443e77cff Refactor: put the real keyword printing into a separate function.
Franz Glasner <hg@dom66.de>
parents: 293
diff changeset
382
2eb443e77cff Refactor: put the real keyword printing into a separate function.
Franz Glasner <hg@dom66.de>
parents: 293
diff changeset
383 def _kwprint_keywords(ui, keywords, file_keywords, rest, no_file):
2eb443e77cff Refactor: put the real keyword printing into a separate function.
Franz Glasner <hg@dom66.de>
parents: 293
diff changeset
384 """Print all the prepared keywords into the output"""
45
c077d30da0ee Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents: 44
diff changeset
385 for key in sorted(keywords.keys()):
294
2eb443e77cff Refactor: put the real keyword printing into a separate function.
Franz Glasner <hg@dom66.de>
parents: 293
diff changeset
386 if rest:
140
02126a3ad162 FIX: for empty keyword values: write a non-breaking space in reST mode instead of a bogus empty "replace::" value
Franz Glasner <hg@dom66.de>
parents: 137
diff changeset
387 if keywords[key]:
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
388 ui.write(b".. |VCS%s| replace:: %s\n" % (key, keywords[key]))
140
02126a3ad162 FIX: for empty keyword values: write a non-breaking space in reST mode instead of a bogus empty "replace::" value
Franz Glasner <hg@dom66.de>
parents: 137
diff changeset
389 else:
02126a3ad162 FIX: for empty keyword values: write a non-breaking space in reST mode instead of a bogus empty "replace::" value
Franz Glasner <hg@dom66.de>
parents: 137
diff changeset
390 #
02126a3ad162 FIX: for empty keyword values: write a non-breaking space in reST mode instead of a bogus empty "replace::" value
Franz Glasner <hg@dom66.de>
parents: 137
diff changeset
391 # empty replacements are not allowed:
02126a3ad162 FIX: for empty keyword values: write a non-breaking space in reST mode instead of a bogus empty "replace::" value
Franz Glasner <hg@dom66.de>
parents: 137
diff changeset
392 # write a non-breaking space instead
02126a3ad162 FIX: for empty keyword values: write a non-breaking space in reST mode instead of a bogus empty "replace::" value
Franz Glasner <hg@dom66.de>
parents: 137
diff changeset
393 #
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
394 ui.write(b".. |VCS%s| unicode:: 0xA0\n" % key)
78
743dd4a77b4a Implemented a "--reST" option for printing reST substitution definitions from keywords
Franz Glasner <hg@dom66.de>
parents: 76
diff changeset
395 else:
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
396 ui.write(b"$%s: %s $\n" % (key, keywords[key]))
294
2eb443e77cff Refactor: put the real keyword printing into a separate function.
Franz Glasner <hg@dom66.de>
parents: 293
diff changeset
397 if not no_file:
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
398 ui.write(b"\n")
109
be4811239acf kwprint: print example file-dependent keywords also.
Franz Glasner <hg@dom66.de>
parents: 108
diff changeset
399 for key in sorted(file_keywords.keys()):
294
2eb443e77cff Refactor: put the real keyword printing into a separate function.
Franz Glasner <hg@dom66.de>
parents: 293
diff changeset
400 if rest:
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
401 ui.write(b".. |VCS%s| replace:: %s\n" % (key, file_keywords[key]))
109
be4811239acf kwprint: print example file-dependent keywords also.
Franz Glasner <hg@dom66.de>
parents: 108
diff changeset
402 else:
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
403 ui.write(b"$%s: %s $\n" % (key, file_keywords[key]))
291
31d5d77c297d Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents: 290
diff changeset
404
31d5d77c297d Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents: 290
diff changeset
405
294
2eb443e77cff Refactor: put the real keyword printing into a separate function.
Franz Glasner <hg@dom66.de>
parents: 293
diff changeset
406 def _kwprint_subrepos(ctx, ui, rest, no_file, path_filter, user_filter):
293
75070825d111 - make_node_keywords() and make_keyword_filter() do not need a "repo" argument.
Franz Glasner <hg@dom66.de>
parents: 292
diff changeset
407 """For all subrepos in `ctx` do keyword expansion resursively"""
291
31d5d77c297d Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents: 290
diff changeset
408 for subpath in sorted(ctx.substate):
295
eeb8c52d8802 The "hg kwprint" command now is fully aware of subrepos if used with the "-S" flag
Franz Glasner <hg@dom66.de>
parents: 294
diff changeset
409 substate = ctx.substate[subpath]
eeb8c52d8802 The "hg kwprint" command now is fully aware of subrepos if used with the "-S" flag
Franz Glasner <hg@dom66.de>
parents: 294
diff changeset
410 # skip on non-Mercurial subrepos
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
411 if substate[2] != b"hg":
295
eeb8c52d8802 The "hg kwprint" command now is fully aware of subrepos if used with the "-S" flag
Franz Glasner <hg@dom66.de>
parents: 294
diff changeset
412 continue
291
31d5d77c297d Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents: 290
diff changeset
413 subrep = ctx.workingsub(subpath)
31d5d77c297d Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents: 290
diff changeset
414 subctx = subrep._getctx()
293
75070825d111 - make_node_keywords() and make_keyword_filter() do not need a "repo" argument.
Franz Glasner <hg@dom66.de>
parents: 292
diff changeset
415 assert subctx.repo() == subrep._repo
295
eeb8c52d8802 The "hg kwprint" command now is fully aware of subrepos if used with the "-S" flag
Franz Glasner <hg@dom66.de>
parents: 294
diff changeset
416 keywords = make_node_keywords(ui, subctx,
eeb8c52d8802 The "hg kwprint" command now is fully aware of subrepos if used with the "-S" flag
Franz Glasner <hg@dom66.de>
parents: 294
diff changeset
417 hgpath=None,
eeb8c52d8802 The "hg kwprint" command now is fully aware of subrepos if used with the "-S" flag
Franz Glasner <hg@dom66.de>
parents: 294
diff changeset
418 path_filter=path_filter,
eeb8c52d8802 The "hg kwprint" command now is fully aware of subrepos if used with the "-S" flag
Franz Glasner <hg@dom66.de>
parents: 294
diff changeset
419 user_filter=user_filter,
eeb8c52d8802 The "hg kwprint" command now is fully aware of subrepos if used with the "-S" flag
Franz Glasner <hg@dom66.de>
parents: 294
diff changeset
420 hglocation=substate[0])
eeb8c52d8802 The "hg kwprint" command now is fully aware of subrepos if used with the "-S" flag
Franz Glasner <hg@dom66.de>
parents: 294
diff changeset
421 if not no_file:
330
793161e48af2 FIX: Remove duplicate assignment to file_keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 328
diff changeset
422 file_keywords = make_file_keywords(
295
eeb8c52d8802 The "hg kwprint" command now is fully aware of subrepos if used with the "-S" flag
Franz Glasner <hg@dom66.de>
parents: 294
diff changeset
423 keywords,
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
424 b"dir3/dir4/test-s.file",
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
425 b"ffffffff22e11fec41158eec187630c24a43120a")
295
eeb8c52d8802 The "hg kwprint" command now is fully aware of subrepos if used with the "-S" flag
Franz Glasner <hg@dom66.de>
parents: 294
diff changeset
426 else:
eeb8c52d8802 The "hg kwprint" command now is fully aware of subrepos if used with the "-S" flag
Franz Glasner <hg@dom66.de>
parents: 294
diff changeset
427 file_keywords = None
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
428 ui.write(b"\n\n")
295
eeb8c52d8802 The "hg kwprint" command now is fully aware of subrepos if used with the "-S" flag
Franz Glasner <hg@dom66.de>
parents: 294
diff changeset
429 _kwprint_keywords(ui, keywords, file_keywords, rest, no_file)
291
31d5d77c297d Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents: 290
diff changeset
430 # Recursively check for other subrepos
294
2eb443e77cff Refactor: put the real keyword printing into a separate function.
Franz Glasner <hg@dom66.de>
parents: 293
diff changeset
431 _kwprint_subrepos(subctx, ui, rest, no_file, path_filter, user_filter)
291
31d5d77c297d Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents: 290
diff changeset
432
31d5d77c297d Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents: 290
diff changeset
433
31d5d77c297d Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents: 290
diff changeset
434 def _test_subrepos(ctx, ui):
293
75070825d111 - make_node_keywords() and make_keyword_filter() do not need a "repo" argument.
Franz Glasner <hg@dom66.de>
parents: 292
diff changeset
435 ui.write("STATE: " + repr(subrepo.state(ctx, ui)) + "\n")
291
31d5d77c297d Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents: 290
diff changeset
436 for subpath in sorted(ctx.substate):
31d5d77c297d Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents: 290
diff changeset
437 ui.write("SUBPATH: " + subpath + "\n");
31d5d77c297d Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents: 290
diff changeset
438 subrep = ctx.workingsub(subpath)
31d5d77c297d Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents: 290
diff changeset
439 ui.write(repr(subrep) + ": subrelpath=" + subrepo.subrelpath(subrep)
31d5d77c297d Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents: 290
diff changeset
440 + " reporelpath=" + subrepo.reporelpath(subrep._repo)
31d5d77c297d Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents: 290
diff changeset
441 + '\n')
31d5d77c297d Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents: 290
diff changeset
442 # Yes(!)
31d5d77c297d Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents: 290
diff changeset
443 assert subrepo.subrelpath(subrep) == subrepo.reporelpath(subrep._repo)
31d5d77c297d Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents: 290
diff changeset
444 assert subrepo.subrelpath(subrep).endswith(subpath)
31d5d77c297d Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents: 290
diff changeset
445 ui.write(" " + repr(subrep._getctx()) + '\n')
31d5d77c297d Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents: 290
diff changeset
446 _test_subrepos(subrep._getctx(), ui)
45
c077d30da0ee Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents: 44
diff changeset
447
c077d30da0ee Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents: 44
diff changeset
448
33
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
449 def patch_archiver_class(archivername, filter):
32
cfa53f8a6607 Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents: 31
diff changeset
450 """Patch an archiver class and return the original unbound method"""
cfa53f8a6607 Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents: 31
diff changeset
451
cfa53f8a6607 Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents: 31
diff changeset
452 archiver_class = getattr(archival, archivername)
cfa53f8a6607 Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents: 31
diff changeset
453 orig_addfile = getattr(archiver_class, "addfile")
cfa53f8a6607 Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents: 31
diff changeset
454
287
95c207d21bbf FIX: Typo in argument: "isline" -> "islink"
Franz Glasner <hg@dom66.de>
parents: 255
diff changeset
455 def new_addfile(self, name, mode, islink, data):
95c207d21bbf FIX: Typo in argument: "isline" -> "islink"
Franz Glasner <hg@dom66.de>
parents: 255
diff changeset
456 return orig_addfile(self, name, mode, islink, filter(name, data))
32
cfa53f8a6607 Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents: 31
diff changeset
457
cfa53f8a6607 Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents: 31
diff changeset
458 setattr(archiver_class, "addfile", new_addfile)
cfa53f8a6607 Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents: 31
diff changeset
459 return orig_addfile
29
58f47399691c New successful PoC: monkey-patch all relevant archiver's "addfile()" method
Franz Glasner <hg@dom66.de>
parents: 28
diff changeset
460
28
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
461
293
75070825d111 - make_node_keywords() and make_keyword_filter() do not need a "repo" argument.
Franz Glasner <hg@dom66.de>
parents: 292
diff changeset
462 def make_keyword_filter(ui, ctx, archive_class, prefix,
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
463 hgpath=b"default",
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
464 path_filter=b"short",
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
465 user_filter=b"user",
296
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
466 subrepos=False,
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
467 kwconfig=b""):
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
468 assert isinstance(archive_class, str), "must be a native string"
296
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
469 filterdata_by_subrepos = {
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
470 b'': _make_repo_filterdata(ui, ctx, hgpath, None, kwconfig,
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
471 path_filter, user_filter),
296
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
472 }
298
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
473 if subrepos:
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
474 _amend_filterdata_by_subrepos(filterdata_by_subrepos,
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
475 ui, ctx,
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
476 kwconfig,
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
477 path_filter,
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
478 user_filter)
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
479 subrepo_paths = list(filterdata_by_subrepos.keys())
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
480 subrepo_paths.sort(key=len, reverse=True)
296
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
481
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
482 def _filter(name, data):
298
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
483 real_name = rel_name_in_subrepo = name
296
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
484 if archive_class != "fileit":
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
485 if prefix:
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
486 assert name.startswith(prefix)
298
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
487 real_name = rel_name_in_subrepo = name[len(prefix):]
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
488 # find the filterdata configuration corresponding to current subrepo
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
489 for s in subrepo_paths:
296
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
490 if real_name.startswith(s):
298
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
491 filterdata = filterdata_by_subrepos[s]
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
492 rel_name_in_subrepo = real_name[len(s):]
296
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
493 break
298
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
494 else:
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
495 raise ValueError("invalid subrepo filter data")
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
496 if filterdata is None:
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
497 return data
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
498 matcher, matcher_rcs, matcher_rst, manifest, \
321
103df4b7a0c8 A new more flexible syntax for custom keyword expansion: with Python template format syntax now
Franz Glasner <fzglas.hg@dom66.de>
parents: 315
diff changeset
499 keyword_substitutions, keywords = filterdata
298
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
500
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
501 if not matcher(rel_name_in_subrepo):
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
502 #ui.write("NOT MATCHER for " + real_name + " (name: " + name + ") \n")
296
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
503 return data
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
504 try:
298
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
505 nodeid = node.hex(manifest[rel_name_in_subrepo])
296
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
506 except LookupError:
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
507 nodeid = None
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
508 # file specific keywords
298
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
509 file_keywords = make_file_keywords(
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
510 keywords, rel_name_in_subrepo, nodeid)
321
103df4b7a0c8 A new more flexible syntax for custom keyword expansion: with Python template format syntax now
Franz Glasner <fzglas.hg@dom66.de>
parents: 315
diff changeset
511 _predef_keywords = keywords.copy()
103df4b7a0c8 A new more flexible syntax for custom keyword expansion: with Python template format syntax now
Franz Glasner <fzglas.hg@dom66.de>
parents: 315
diff changeset
512 _predef_keywords.update(file_keywords)
296
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
513 # This prevents unwanted keyword expansion here
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
514 _MARKER_RCS = b'$'
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
515 _MARKER_RST = b'|'
296
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
516 for kw, value in itertools.chain(keyword_substitutions.items(), keywords.items(), file_keywords.items()):
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
517 #
321
103df4b7a0c8 A new more flexible syntax for custom keyword expansion: with Python template format syntax now
Franz Glasner <fzglas.hg@dom66.de>
parents: 315
diff changeset
518 # Non-empty keyword_substitutions are an implicit whitelist and
103df4b7a0c8 A new more flexible syntax for custom keyword expansion: with Python template format syntax now
Franz Glasner <fzglas.hg@dom66.de>
parents: 315
diff changeset
519 # the value are Python format templates when expanding.
296
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
520 #
321
103df4b7a0c8 A new more flexible syntax for custom keyword expansion: with Python template format syntax now
Franz Glasner <fzglas.hg@dom66.de>
parents: 315
diff changeset
521 if keyword_substitutions:
103df4b7a0c8 A new more flexible syntax for custom keyword expansion: with Python template format syntax now
Franz Glasner <fzglas.hg@dom66.de>
parents: 315
diff changeset
522 if kw in keyword_substitutions:
103df4b7a0c8 A new more flexible syntax for custom keyword expansion: with Python template format syntax now
Franz Glasner <fzglas.hg@dom66.de>
parents: 315
diff changeset
523 kwds = [kw]
103df4b7a0c8 A new more flexible syntax for custom keyword expansion: with Python template format syntax now
Franz Glasner <fzglas.hg@dom66.de>
parents: 315
diff changeset
524 if value:
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
525 if not pycompat.ispy3:
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
526 value = value.format(**_predef_keywords)
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
527 else:
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
528 # Assume UTF-8 strings in config files
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
529 _predef_keywords_u = dict((k.decode("utf-8"), v.decode("utf-8")) for k, v in _predef_keywords.items())
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
530 value = value.decode("utf-8").format(**_predef_keywords_u).encode("utf-8")
321
103df4b7a0c8 A new more flexible syntax for custom keyword expansion: with Python template format syntax now
Franz Glasner <fzglas.hg@dom66.de>
parents: 315
diff changeset
531 else:
103df4b7a0c8 A new more flexible syntax for custom keyword expansion: with Python template format syntax now
Franz Glasner <fzglas.hg@dom66.de>
parents: 315
diff changeset
532 value = _predef_keywords[kw]
103df4b7a0c8 A new more flexible syntax for custom keyword expansion: with Python template format syntax now
Franz Glasner <fzglas.hg@dom66.de>
parents: 315
diff changeset
533 else:
103df4b7a0c8 A new more flexible syntax for custom keyword expansion: with Python template format syntax now
Franz Glasner <fzglas.hg@dom66.de>
parents: 315
diff changeset
534 # not whitelisted -> ignore
103df4b7a0c8 A new more flexible syntax for custom keyword expansion: with Python template format syntax now
Franz Glasner <fzglas.hg@dom66.de>
parents: 315
diff changeset
535 kwds = []
296
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
536 else:
322
950a9bd55d7e Expand "HGrepoid" as Mercurial's repository id (id of the first commit)
Franz Glasner <fzglas.hg@dom66.de>
parents: 321
diff changeset
537 # Empty keyword_substitutions mean: expand built-in keywords
296
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
538 kwds = [kw]
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
539 for kw in kwds:
298
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
540 if matcher_rcs(rel_name_in_subrepo):
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
541 filekw = b"%s%s%s" % (_MARKER_RCS, kw, _MARKER_RCS)
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
542 filevalue = b"%s%s: %s %s" \
296
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
543 % (_MARKER_RCS, kw, value, _MARKER_RCS)
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
544 data = data.replace(filekw, filevalue)
298
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
545 if matcher_rst(rel_name_in_subrepo):
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
546 filekw = b"%sVCS%s%s" % (_MARKER_RST, kw, _MARKER_RST)
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
547 filevalue = b"%s" % value # always convert to a string
296
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
548 data = data.replace(filekw, filevalue)
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
549 return data
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
550
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
551 return _filter
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
552
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
553
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
554 def _make_repo_filterdata(ui, ctx, hgpath, hglocation, kwconfig,
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
555 path_filter, user_filter):
293
75070825d111 - make_node_keywords() and make_keyword_filter() do not need a "repo" argument.
Franz Glasner <hg@dom66.de>
parents: 292
diff changeset
556 keywords = make_node_keywords(ui, ctx,
51
3807a60ee0dd Shorten path urls by default when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 47
diff changeset
557 hgpath=hgpath,
93
fa84debfb50e Replace "no-shorten-url" by "path-filter"
Franz Glasner <hg@dom66.de>
parents: 92
diff changeset
558 path_filter=path_filter,
298
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
559 user_filter=user_filter,
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
560 hglocation=hglocation)
47
94ae433383a2 Allow an alternate patterns file (instead of .hgkwarchive) with the --kwconfig option.
Franz Glasner <hg@dom66.de>
parents: 46
diff changeset
561 kwconfigdata = kwconfigname = None
94ae433383a2 Allow an alternate patterns file (instead of .hgkwarchive) with the --kwconfig option.
Franz Glasner <hg@dom66.de>
parents: 46
diff changeset
562 if kwconfig:
157
e12025e46375 Use util.posixfile when reading a custom given .hgkwarchive file for Mercurial portability reasons
Franz Glasner <hg@dom66.de>
parents: 156
diff changeset
563 kwconfigdata = util.posixfile(kwconfig, "rb").read()
47
94ae433383a2 Allow an alternate patterns file (instead of .hgkwarchive) with the --kwconfig option.
Franz Glasner <hg@dom66.de>
parents: 46
diff changeset
564 kwconfigname = kwconfig
33
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
565 try:
47
94ae433383a2 Allow an alternate patterns file (instead of .hgkwarchive) with the --kwconfig option.
Franz Glasner <hg@dom66.de>
parents: 46
diff changeset
566 if kwconfigdata is None:
156
d92850f876a4 Use a constant to define the ".hgkwarchive" name
Franz Glasner <hg@dom66.de>
parents: 155
diff changeset
567 # use versioned .hgkwarchive
d92850f876a4 Use a constant to define the ".hgkwarchive" name
Franz Glasner <hg@dom66.de>
parents: 155
diff changeset
568 kwconfigdata = ctx[KWARCHIVE_CONFIG].data()
d92850f876a4 Use a constant to define the ".hgkwarchive" name
Franz Glasner <hg@dom66.de>
parents: 155
diff changeset
569 kwconfigname = KWARCHIVE_CONFIG
33
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
570 except (IOError, LookupError):
296
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
571 # sigil for no keyword expansion configured -> filter is pass-through
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
572 return None
33
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
573 else:
44
71b321436cc1 Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents: 42
diff changeset
574 #
71b321436cc1 Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents: 42
diff changeset
575 # Parse the data in ".hgkwarchive" and generate a
71b321436cc1 Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents: 42
diff changeset
576 # Mercurial matcher
71b321436cc1 Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents: 42
diff changeset
577 #
33
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
578 cfg = config.config()
47
94ae433383a2 Allow an alternate patterns file (instead of .hgkwarchive) with the --kwconfig option.
Franz Glasner <hg@dom66.de>
parents: 46
diff changeset
579 cfg.parse(kwconfigname, kwconfigdata)
33
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
580 include = []
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
581 exclude = []
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
582 patterns = []
118
e9c78a0bfe6a Allow multiple style keyword expansion in one file.
Franz Glasner <hg@dom66.de>
parents: 116
diff changeset
583 patterns_rcs = []
79
53c9f2f6a13e Work in reST style keywords in kwarchive
Franz Glasner <hg@dom66.de>
parents: 78
diff changeset
584 patterns_rst = []
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
585 if cfg.items(b"patterns"):
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
586 for pattern, styles in cfg.items(b"patterns"):
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
587 styles = [s.strip() for s in styles.upper().split(b',')]
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
588 if b"YES" in styles or b"INCLUDE" in styles:
33
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
589 include.append(pattern)
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
590 elif b"NO" in styles or b"EXCLUDE" in styles:
33
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
591 exclude.append(pattern)
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
592 else:
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
593 patterns.append(pattern)
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
594 if b"REST" in styles or b"RST" in styles \
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
595 or b"RCS" in styles:
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
596 if b"RCS" in styles:
118
e9c78a0bfe6a Allow multiple style keyword expansion in one file.
Franz Glasner <hg@dom66.de>
parents: 116
diff changeset
597 patterns_rcs.append(pattern)
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
598 if b"REST" in styles or b"RST" in styles:
118
e9c78a0bfe6a Allow multiple style keyword expansion in one file.
Franz Glasner <hg@dom66.de>
parents: 116
diff changeset
599 patterns_rst.append(pattern)
e9c78a0bfe6a Allow multiple style keyword expansion in one file.
Franz Glasner <hg@dom66.de>
parents: 116
diff changeset
600 else:
e9c78a0bfe6a Allow multiple style keyword expansion in one file.
Franz Glasner <hg@dom66.de>
parents: 116
diff changeset
601 # default to RCS if no keyword style is given
e9c78a0bfe6a Allow multiple style keyword expansion in one file.
Franz Glasner <hg@dom66.de>
parents: 116
diff changeset
602 patterns_rcs.append(pattern)
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
603 matcher = match.match(ctx.repo().root, b'', patterns=patterns,
33
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
604 include=include, exclude=exclude)
91
36369940d31b FIX: An empty pattern list for RST style keywords does **not** mean that matching it is always true
Franz Glasner <hg@dom66.de>
parents: 88
diff changeset
605 else:
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
606 matcher = match.never(ctx.repo().root, b'')
118
e9c78a0bfe6a Allow multiple style keyword expansion in one file.
Franz Glasner <hg@dom66.de>
parents: 116
diff changeset
607
e9c78a0bfe6a Allow multiple style keyword expansion in one file.
Franz Glasner <hg@dom66.de>
parents: 116
diff changeset
608 #
e9c78a0bfe6a Allow multiple style keyword expansion in one file.
Franz Glasner <hg@dom66.de>
parents: 116
diff changeset
609 # An empty patterns_rcs does not mean that match_rcs is always
e9c78a0bfe6a Allow multiple style keyword expansion in one file.
Franz Glasner <hg@dom66.de>
parents: 116
diff changeset
610 # true.
e9c78a0bfe6a Allow multiple style keyword expansion in one file.
Franz Glasner <hg@dom66.de>
parents: 116
diff changeset
611 #
e9c78a0bfe6a Allow multiple style keyword expansion in one file.
Franz Glasner <hg@dom66.de>
parents: 116
diff changeset
612 if not patterns_rcs:
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
613 matcher_rcs = match.never(ctx.repo().root, b'')
118
e9c78a0bfe6a Allow multiple style keyword expansion in one file.
Franz Glasner <hg@dom66.de>
parents: 116
diff changeset
614 else:
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
615 matcher_rcs = match.match(ctx.repo().root, b'',
293
75070825d111 - make_node_keywords() and make_keyword_filter() do not need a "repo" argument.
Franz Glasner <hg@dom66.de>
parents: 292
diff changeset
616 patterns=patterns_rcs,
118
e9c78a0bfe6a Allow multiple style keyword expansion in one file.
Franz Glasner <hg@dom66.de>
parents: 116
diff changeset
617 include=[], exclude=[])
91
36369940d31b FIX: An empty pattern list for RST style keywords does **not** mean that matching it is always true
Franz Glasner <hg@dom66.de>
parents: 88
diff changeset
618 #
36369940d31b FIX: An empty pattern list for RST style keywords does **not** mean that matching it is always true
Franz Glasner <hg@dom66.de>
parents: 88
diff changeset
619 # An empty patterns_rst does not mean that match_rst is always
36369940d31b FIX: An empty pattern list for RST style keywords does **not** mean that matching it is always true
Franz Glasner <hg@dom66.de>
parents: 88
diff changeset
620 # true.
36369940d31b FIX: An empty pattern list for RST style keywords does **not** mean that matching it is always true
Franz Glasner <hg@dom66.de>
parents: 88
diff changeset
621 #
36369940d31b FIX: An empty pattern list for RST style keywords does **not** mean that matching it is always true
Franz Glasner <hg@dom66.de>
parents: 88
diff changeset
622 if not patterns_rst:
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
623 matcher_rst = match.never(ctx.repo().root, b'')
91
36369940d31b FIX: An empty pattern list for RST style keywords does **not** mean that matching it is always true
Franz Glasner <hg@dom66.de>
parents: 88
diff changeset
624 else:
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
625 matcher_rst = match.match(ctx.repo().root, b'',
293
75070825d111 - make_node_keywords() and make_keyword_filter() do not need a "repo" argument.
Franz Glasner <hg@dom66.de>
parents: 292
diff changeset
626 patterns=patterns_rst,
79
53c9f2f6a13e Work in reST style keywords in kwarchive
Franz Glasner <hg@dom66.de>
parents: 78
diff changeset
627 include=[], exclude=[])
33
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
628
104
65789e3e8e3d Provide a "HGnodeid" per file keyword that expands to the NodeID of the artifact.
Franz Glasner <hg@dom66.de>
parents: 103
diff changeset
629 #
321
103df4b7a0c8 A new more flexible syntax for custom keyword expansion: with Python template format syntax now
Franz Glasner <fzglas.hg@dom66.de>
parents: 315
diff changeset
630 # This are the settings of the [keywords] section in .hgkwarchive.
103df4b7a0c8 A new more flexible syntax for custom keyword expansion: with Python template format syntax now
Franz Glasner <fzglas.hg@dom66.de>
parents: 315
diff changeset
631 # An empty section means: all default keywords are enabled.
103df4b7a0c8 A new more flexible syntax for custom keyword expansion: with Python template format syntax now
Franz Glasner <fzglas.hg@dom66.de>
parents: 315
diff changeset
632 # Otherwise only the given keywords are enabled with their expanded
103df4b7a0c8 A new more flexible syntax for custom keyword expansion: with Python template format syntax now
Franz Glasner <fzglas.hg@dom66.de>
parents: 315
diff changeset
633 # values on the right side. An empty right side means: use the default
103df4b7a0c8 A new more flexible syntax for custom keyword expansion: with Python template format syntax now
Franz Glasner <fzglas.hg@dom66.de>
parents: 315
diff changeset
634 # expansion.
133
8d16138e00af Implemented substitution type keyword expansion
Franz Glasner <hg@dom66.de>
parents: 131
diff changeset
635 #
8d16138e00af Implemented substitution type keyword expansion
Franz Glasner <hg@dom66.de>
parents: 131
diff changeset
636 keyword_substitutions = {}
8d16138e00af Implemented substitution type keyword expansion
Franz Glasner <hg@dom66.de>
parents: 131
diff changeset
637
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
638 for alias, value in cfg.items(b"keywords"):
321
103df4b7a0c8 A new more flexible syntax for custom keyword expansion: with Python template format syntax now
Franz Glasner <fzglas.hg@dom66.de>
parents: 315
diff changeset
639 keyword_substitutions[alias] = value
122
e6037655967b Implemented a keyword white-list including aliases.
Franz Glasner <hg@dom66.de>
parents: 120
diff changeset
640
e6037655967b Implemented a keyword white-list including aliases.
Franz Glasner <hg@dom66.de>
parents: 120
diff changeset
641 #
104
65789e3e8e3d Provide a "HGnodeid" per file keyword that expands to the NodeID of the artifact.
Franz Glasner <hg@dom66.de>
parents: 103
diff changeset
642 # Get the manifest to be able to determine a file's NodeId
65789e3e8e3d Provide a "HGnodeid" per file keyword that expands to the NodeID of the artifact.
Franz Glasner <hg@dom66.de>
parents: 103
diff changeset
643 #
65789e3e8e3d Provide a "HGnodeid" per file keyword that expands to the NodeID of the artifact.
Franz Glasner <hg@dom66.de>
parents: 103
diff changeset
644 manifest = ctx.manifest()
65789e3e8e3d Provide a "HGnodeid" per file keyword that expands to the NodeID of the artifact.
Franz Glasner <hg@dom66.de>
parents: 103
diff changeset
645
296
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
646 return (matcher, matcher_rcs, matcher_rst,
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
647 manifest,
321
103df4b7a0c8 A new more flexible syntax for custom keyword expansion: with Python template format syntax now
Franz Glasner <fzglas.hg@dom66.de>
parents: 315
diff changeset
648 keyword_substitutions, keywords,)
44
71b321436cc1 Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents: 42
diff changeset
649
71b321436cc1 Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents: 42
diff changeset
650
298
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
651 def _amend_filterdata_by_subrepos(filterdata_by_subrepos,
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
652 ui,
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
653 ctx,
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
654 kwconfig,
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
655 path_filter, user_filter):
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
656
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
657 for subpath in sorted(ctx.substate):
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
658 substate = ctx.substate[subpath]
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
659 # skip on non-Mercurial subrepos
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
660 if substate[2] != b"hg":
298
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
661 continue
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
662 subrep = ctx.workingsub(subpath)
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
663 subctx = subrep._getctx()
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
664
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
665 # Really amend
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
666 filterdata_by_subrepos[subrepo.subrelpath(subrep) + b'/'] = \
298
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
667 _make_repo_filterdata(ui, subctx, None, substate[0], kwconfig,
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
668 path_filter, user_filter)
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
669
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
670 # Recursively check for other subrepos
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
671 _amend_filterdata_by_subrepos(filterdata_by_subrepos,
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
672 ui, subctx,
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
673 kwconfig,
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
674 path_filter, user_filter)
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
675
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
676
293
75070825d111 - make_node_keywords() and make_keyword_filter() do not need a "repo" argument.
Franz Glasner <hg@dom66.de>
parents: 292
diff changeset
677 def make_node_keywords(ui, ctx,
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
678 hgpath=b"default",
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
679 path_filter=b"short",
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
680 user_filter=b"user",
295
eeb8c52d8802 The "hg kwprint" command now is fully aware of subrepos if used with the "-S" flag
Franz Glasner <hg@dom66.de>
parents: 294
diff changeset
681 hglocation=None):
44
71b321436cc1 Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents: 42
diff changeset
682 """Make all the node-specific (i.e. file-path independent) keywords
71b321436cc1 Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents: 42
diff changeset
683
71b321436cc1 Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents: 42
diff changeset
684 """
295
eeb8c52d8802 The "hg kwprint" command now is fully aware of subrepos if used with the "-S" flag
Franz Glasner <hg@dom66.de>
parents: 294
diff changeset
685 if (hglocation is not None) and hgpath:
eeb8c52d8802 The "hg kwprint" command now is fully aware of subrepos if used with the "-S" flag
Franz Glasner <hg@dom66.de>
parents: 294
diff changeset
686 raise ValueError("either `hgpath' or `hglocation` can be set")
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
687 if (hglocation is not None) or (hgpath and hgpath != b"."):
295
eeb8c52d8802 The "hg kwprint" command now is fully aware of subrepos if used with the "-S" flag
Franz Glasner <hg@dom66.de>
parents: 294
diff changeset
688 if hglocation is None:
eeb8c52d8802 The "hg kwprint" command now is fully aware of subrepos if used with the "-S" flag
Franz Glasner <hg@dom66.de>
parents: 294
diff changeset
689 hglocation = ui.paths[hgpath].loc
158
07e323b8d27d Refactor: make_node_keywords: path handling
Franz Glasner <hg@dom66.de>
parents: 157
diff changeset
690 try:
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
691 if path_filter == b"full":
295
eeb8c52d8802 The "hg kwprint" command now is fully aware of subrepos if used with the "-S" flag
Franz Glasner <hg@dom66.de>
parents: 294
diff changeset
692 path_uri = bytes(util.url(hglocation))
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
693 elif path_filter == b"nopwd":
295
eeb8c52d8802 The "hg kwprint" command now is fully aware of subrepos if used with the "-S" flag
Franz Glasner <hg@dom66.de>
parents: 294
diff changeset
694 path_uri = util.hidepassword(hglocation)
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
695 elif path_filter == b"nouser":
295
eeb8c52d8802 The "hg kwprint" command now is fully aware of subrepos if used with the "-S" flag
Franz Glasner <hg@dom66.de>
parents: 294
diff changeset
696 path_url = util.url(hglocation)
249
e97f6f6ed7c5 Implement a "nouser" option for the path-filter: like no-pwd but without user information also
Franz Glasner <hg@dom66.de>
parents: 248
diff changeset
697 path_url.user = None
e97f6f6ed7c5 Implement a "nouser" option for the path-filter: like no-pwd but without user information also
Franz Glasner <hg@dom66.de>
parents: 248
diff changeset
698 path_url.passwd = None
e97f6f6ed7c5 Implement a "nouser" option for the path-filter: like no-pwd but without user information also
Franz Glasner <hg@dom66.de>
parents: 248
diff changeset
699 path_uri = bytes(path_url)
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
700 elif path_filter == b"short":
295
eeb8c52d8802 The "hg kwprint" command now is fully aware of subrepos if used with the "-S" flag
Franz Glasner <hg@dom66.de>
parents: 294
diff changeset
701 path_url = util.url(hglocation)
158
07e323b8d27d Refactor: make_node_keywords: path handling
Franz Glasner <hg@dom66.de>
parents: 157
diff changeset
702 path_url.scheme = SHORTENED_HG_SCHEMES.get(path_url.scheme,
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
703 b"hg")
158
07e323b8d27d Refactor: make_node_keywords: path handling
Franz Glasner <hg@dom66.de>
parents: 157
diff changeset
704 path_url.user = None
07e323b8d27d Refactor: make_node_keywords: path handling
Franz Glasner <hg@dom66.de>
parents: 157
diff changeset
705 path_url.passwd = None
07e323b8d27d Refactor: make_node_keywords: path handling
Franz Glasner <hg@dom66.de>
parents: 157
diff changeset
706 path_url.host = stripped_hostname(path_url.host)
07e323b8d27d Refactor: make_node_keywords: path handling
Franz Glasner <hg@dom66.de>
parents: 157
diff changeset
707 path_url.port = None
07e323b8d27d Refactor: make_node_keywords: path handling
Franz Glasner <hg@dom66.de>
parents: 157
diff changeset
708 path_uri = bytes(path_url)
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
709 elif path_filter == b"last":
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
710 path_url = str(util.url(hglocation)).split('/')
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
711 path_uri = pycompat.sysbytes(".../"+path_url[-1])
158
07e323b8d27d Refactor: make_node_keywords: path handling
Franz Glasner <hg@dom66.de>
parents: 157
diff changeset
712 else:
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
713 raise error.Abort(b"path-filter `%s' not implemented"
158
07e323b8d27d Refactor: make_node_keywords: path handling
Franz Glasner <hg@dom66.de>
parents: 157
diff changeset
714 % path_filter)
07e323b8d27d Refactor: make_node_keywords: path handling
Franz Glasner <hg@dom66.de>
parents: 157
diff changeset
715 except LookupError:
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
716 raise error.Abort(_(b"remote repository named `%s' not found") % hgpath)
44
71b321436cc1 Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents: 42
diff changeset
717 else:
293
75070825d111 - make_node_keywords() and make_keyword_filter() do not need a "repo" argument.
Franz Glasner <hg@dom66.de>
parents: 292
diff changeset
718 path_uri = ctx.repo().root
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
719 if path_filter == b"last":
159
d313b33c9c06 Implement the "last" path-filter for the local repo "." also
Franz Glasner <hg@dom66.de>
parents: 158
diff changeset
720 m = max(path_uri.rfind(b"/"), path_uri.rfind(b"\\"))
d313b33c9c06 Implement the "last" path-filter for the local repo "." also
Franz Glasner <hg@dom66.de>
parents: 158
diff changeset
721 if m >= 0:
d313b33c9c06 Implement the "last" path-filter for the local repo "." also
Franz Glasner <hg@dom66.de>
parents: 158
diff changeset
722 path_uri = b".../" + path_uri[m+1:]
80
f772a6cc2f67 Make a plain Windows UNC path into a file: URL for HGpath and friends.
Franz Glasner <hg@dom66.de>
parents: 79
diff changeset
723 if path_uri.startswith(b"\\\\"):
92
e1dc7aa60cd4 Check whether the path is a path with Windows drive letters also
Franz Glasner <hg@dom66.de>
parents: 91
diff changeset
724 # Make an URL from a Windows UNC path
e1dc7aa60cd4 Check whether the path is a path with Windows drive letters also
Franz Glasner <hg@dom66.de>
parents: 91
diff changeset
725 path_uri = b"file:///" + path_uri.replace(b'\\', b'/')
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
726 elif len(path_uri) >= 2 \
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
727 and ((pycompat.ispy3 and ((b'A' <= pycompat.bytechr(path_uri[0]) <= b'Z') or (b'a' <= pycompat.bytechr(path_uri[0]) <= b'z'))) or ((not pycompat.ispy3 and (b'A' <= path_uri[0].upper() <= b'Z')))) \
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
728 and path_uri[1] == b':':
92
e1dc7aa60cd4 Check whether the path is a path with Windows drive letters also
Franz Glasner <hg@dom66.de>
parents: 91
diff changeset
729 # make an URL from a Windows path with drive letter
80
f772a6cc2f67 Make a plain Windows UNC path into a file: URL for HGpath and friends.
Franz Glasner <hg@dom66.de>
parents: 79
diff changeset
730 path_uri = b"file:///" + path_uri.replace(b'\\', b'/')
96
6ecb3909f95e Make absolute POSIX paths always start with "file://" -- a path should always have the form of an URI
Franz Glasner <hg@dom66.de>
parents: 93
diff changeset
731 elif path_uri.startswith(b'/'):
6ecb3909f95e Make absolute POSIX paths always start with "file://" -- a path should always have the form of an URI
Franz Glasner <hg@dom66.de>
parents: 93
diff changeset
732 # an absolute POSIX path
6ecb3909f95e Make absolute POSIX paths always start with "file://" -- a path should always have the form of an URI
Franz Glasner <hg@dom66.de>
parents: 93
diff changeset
733 path_uri = b"file://" + path_uri
304
71288cb43ba9 kwarchive: Make it work with Mercurial 4.6+ (really tested on 4.8.1).
Franz Glasner <hg@dom66.de>
parents: 300
diff changeset
734 if context_mapping_api:
71288cb43ba9 kwarchive: Make it work with Mercurial 4.6+ (really tested on 4.8.1).
Franz Glasner <hg@dom66.de>
parents: 300
diff changeset
735 mapping = {
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
736 b'repo': ctx.repo(),
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
737 b'ctx': ctx,
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
738 b'cache': {}
304
71288cb43ba9 kwarchive: Make it work with Mercurial 4.6+ (really tested on 4.8.1).
Franz Glasner <hg@dom66.de>
parents: 300
diff changeset
739 }
71288cb43ba9 kwarchive: Make it work with Mercurial 4.6+ (really tested on 4.8.1).
Franz Glasner <hg@dom66.de>
parents: 300
diff changeset
740 latesttags = templatekw.getlatesttags(_FakeRenderContext(), mapping)
71288cb43ba9 kwarchive: Make it work with Mercurial 4.6+ (really tested on 4.8.1).
Franz Glasner <hg@dom66.de>
parents: 300
diff changeset
741 else:
71288cb43ba9 kwarchive: Make it work with Mercurial 4.6+ (really tested on 4.8.1).
Franz Glasner <hg@dom66.de>
parents: 300
diff changeset
742 latesttags = templatekw.getlatesttags(ctx.repo(), ctx, {})
44
71b321436cc1 Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents: 42
diff changeset
743 keywords = {
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
744 b"HGrepoid": ctx.repo()[ctx.repo().lookup(b'0')].hex(), # repo id
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
745 b"HGpath": path_uri, # XXX FIXME: Should Archive an alias of this
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
746 b"HGbranch": ctx.branch(),
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
747 b"HGtags": b' '.join([tag for tag in ctx.tags() if tag != b"tip"]),
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
748 b"HGlatesttags": b" ".join(latesttags[2]),
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
749 b"HGlatesttagdistance": pycompat.sysbytes(str(latesttags[1])),
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
750 b"HGlatesttagdate": templatefilters.isodatesec(_dateutil.makedate(latesttags[0])),
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
751 b"HGlatesttagjustdate": templatefilters.shortdate(_dateutil.makedate(latesttags[0])),
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
752 b"HGbookmarks": b' '.join([bm if not bm.startswith(b'*') else bm[1:]
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
753 for bm in ctx.bookmarks() if bm != b"@"]),
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
754 b"State": ctx.phasestr(),
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
755 b"HGrevision": ctx.hex(),
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
756 b"Revision": templatefilters.short(ctx.hex()),
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
757 b"Date": templatefilters.isodatesec(ctx.date()),
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
758 b"JustDate": templatefilters.shortdate(ctx.date()),
115
06a60e2a9887 Added "JustDate" (from Visual Source Safe and Surround SCM) as date only keyword
Franz Glasner <hg@dom66.de>
parents: 114
diff changeset
759 # compatibility alias for `JustDate'
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
760 b"HGshortdate": templatefilters.shortdate(ctx.date()),
44
71b321436cc1 Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents: 42
diff changeset
761 }
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
762 if user_filter == b"user":
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
763 keywords[b"Author"] = templatefilters.emailuser(ctx.user())
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
764 elif user_filter == b"person":
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
765 keywords[b"Author"] = templatefilters.utf8(
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
766 templatefilters.person(ctx.user()).replace(b' ', b'+'))
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
767 elif user_filter == b"email":
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
768 keywords[b"Author"] = templatefilters.email(ctx.user())
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
769 elif user_filter in (b"full", b"none",):
81
e02aceb91a9b Make "full" a user filter and "none" an alias to "full"
Franz Glasner <hg@dom66.de>
parents: 80
diff changeset
770 #
e02aceb91a9b Make "full" a user filter and "none" an alias to "full"
Franz Glasner <hg@dom66.de>
parents: 80
diff changeset
771 # "none" is retained for compatibility reasons and now an
e02aceb91a9b Make "full" a user filter and "none" an alias to "full"
Franz Glasner <hg@dom66.de>
parents: 80
diff changeset
772 # alias for "full".
e02aceb91a9b Make "full" a user filter and "none" an alias to "full"
Franz Glasner <hg@dom66.de>
parents: 80
diff changeset
773 # But make it **one** word because that is meant in the RCS spec.
e02aceb91a9b Make "full" a user filter and "none" an alias to "full"
Franz Glasner <hg@dom66.de>
parents: 80
diff changeset
774 #
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
775 keywords[b"Author"] = templatefilters.utf8(ctx.user().replace(b' ', b'+'))
81
e02aceb91a9b Make "full" a user filter and "none" an alias to "full"
Franz Glasner <hg@dom66.de>
parents: 80
diff changeset
776 else:
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
777 raise error.Abort(_(b"unknown user filter"))
65
bdb549d71148 Allow customization of the $Author$ output when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 64
diff changeset
778
44
71b321436cc1 Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents: 42
diff changeset
779 return keywords
51
3807a60ee0dd Shorten path urls by default when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 47
diff changeset
780
3807a60ee0dd Shorten path urls by default when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 47
diff changeset
781
298
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
782 def make_file_keywords(keywords, rel_name, nodeid):
109
be4811239acf kwprint: print example file-dependent keywords also.
Franz Glasner <hg@dom66.de>
parents: 108
diff changeset
783 return {
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
784 b"HGsource": keywords[b"HGpath"] + b'/' + rel_name,
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
785 b"Source": rel_name,
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
786 b"File": templatefilters.basename(rel_name),
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
787 b"Header": b"%s %s %s %s %s" % (rel_name, keywords[b"Revision"], keywords[b"Date"], keywords[b"Author"], keywords[b"State"]),
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
788 b"HGid": b"%s %s %s %s %s" % (keywords[b"HGpath"] + b'/' + rel_name, keywords[b"Revision"], keywords[b"Date"], keywords[b"Author"], keywords[b"State"]),
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
789 b"HGheader": b"%s %s %s %s %s" % (keywords[b"HGpath"] + b'/' + rel_name, keywords[b"HGrevision"], keywords[b"Date"], keywords[b"Author"], keywords[b"State"]),
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
790 b"Id": b"%s %s %s %s %s" % (templatefilters.basename(rel_name), keywords[b"Revision"], keywords[b"Date"], keywords[b"Author"], keywords[b"State"]),
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
791 b"HGnodeid": nodeid or b'',
109
be4811239acf kwprint: print example file-dependent keywords also.
Franz Glasner <hg@dom66.de>
parents: 108
diff changeset
792 }
be4811239acf kwprint: print example file-dependent keywords also.
Franz Glasner <hg@dom66.de>
parents: 108
diff changeset
793
be4811239acf kwprint: print example file-dependent keywords also.
Franz Glasner <hg@dom66.de>
parents: 108
diff changeset
794
51
3807a60ee0dd Shorten path urls by default when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 47
diff changeset
795 def stripped_hostname(hostname):
56
333f98d045ab FIX: Remove the port information from a cleaned path url also
Franz Glasner <hg@dom66.de>
parents: 52
diff changeset
796 """Return `hostname` without any domain port information"""
51
3807a60ee0dd Shorten path urls by default when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 47
diff changeset
797 if not hostname:
3807a60ee0dd Shorten path urls by default when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 47
diff changeset
798 return hostname
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
799 idx = hostname.find(b'.')
51
3807a60ee0dd Shorten path urls by default when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 47
diff changeset
800 if idx < 0:
3807a60ee0dd Shorten path urls by default when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 47
diff changeset
801 return hostname
3807a60ee0dd Shorten path urls by default when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 47
diff changeset
802 return hostname[:idx]
65
bdb549d71148 Allow customization of the $Author$ output when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 64
diff changeset
803
bdb549d71148 Allow customization of the $Author$ output when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 64
diff changeset
804
136
f470702886b4 Renamed some internal functions to provide a more descriptive name
Franz Glasner <hg@dom66.de>
parents: 134
diff changeset
805 def get_checked_user_filter_option(opts):
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
806 uf = opts.get(b"user_filter")
81
e02aceb91a9b Make "full" a user filter and "none" an alias to "full"
Franz Glasner <hg@dom66.de>
parents: 80
diff changeset
807 # "none" is retained for compatibility reasons and now an alias for "full"
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
808 if uf not in (b"person", b"user", b"email", b"full", b"none"):
114
a51822141ccf Style: handled some more flake8 warnings: consistent command declaration list formatting
Franz Glasner <hg@dom66.de>
parents: 112
diff changeset
809 raise error.Abort(
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
810 _(b"user filter must be any of `user', `person', `email' or `none'"))
65
bdb549d71148 Allow customization of the $Author$ output when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 64
diff changeset
811 return uf
93
fa84debfb50e Replace "no-shorten-url" by "path-filter"
Franz Glasner <hg@dom66.de>
parents: 92
diff changeset
812
fa84debfb50e Replace "no-shorten-url" by "path-filter"
Franz Glasner <hg@dom66.de>
parents: 92
diff changeset
813
136
f470702886b4 Renamed some internal functions to provide a more descriptive name
Franz Glasner <hg@dom66.de>
parents: 134
diff changeset
814 def get_checked_path_filter_option(opts):
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
815 pf = opts.get(b"path_filter")
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
816 if pf not in (b"full", b"nopwd", b"nouser", b"short", b"last"):
114
a51822141ccf Style: handled some more flake8 warnings: consistent command declaration list formatting
Franz Glasner <hg@dom66.de>
parents: 112
diff changeset
817 raise error.Abort(
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
818 _(b"path filter must be any of `full', `nopwd', `nouser`, `short' or `last'"))
93
fa84debfb50e Replace "no-shorten-url" by "path-filter"
Franz Glasner <hg@dom66.de>
parents: 92
diff changeset
819 return pf
103
d6e594644778 Make kwarchive work on Mercurial 4.6+ also: the signature of cmdutil.makefileXXX() have changed
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
820
d6e594644778 Make kwarchive work on Mercurial 4.6+ also: the signature of cmdutil.makefileXXX() have changed
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
821
331
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
822 if hasattr(inspect, "getfullargspec"):
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
823 # PY3
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
824 _has_makefilename_ctx = "ctx" in inspect.getfullargspec(cmdutil.makefilename).args
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
825 else:
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
826 _has_makefilename_ctx = "ctx" in inspect.getargspec(cmdutil.makefilename).args
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
827
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
828 if _has_makefilename_ctx:
103
d6e594644778 Make kwarchive work on Mercurial 4.6+ also: the signature of cmdutil.makefileXXX() have changed
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
829
d6e594644778 Make kwarchive work on Mercurial 4.6+ also: the signature of cmdutil.makefileXXX() have changed
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
830 # Mercurial >= 4.6
d6e594644778 Make kwarchive work on Mercurial 4.6+ also: the signature of cmdutil.makefileXXX() have changed
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
831
d6e594644778 Make kwarchive work on Mercurial 4.6+ also: the signature of cmdutil.makefileXXX() have changed
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
832 makefilename_compat = cmdutil.makefilename
d6e594644778 Make kwarchive work on Mercurial 4.6+ also: the signature of cmdutil.makefileXXX() have changed
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
833 makefileobj_compat = cmdutil.makefileobj
d6e594644778 Make kwarchive work on Mercurial 4.6+ also: the signature of cmdutil.makefileXXX() have changed
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
834
d6e594644778 Make kwarchive work on Mercurial 4.6+ also: the signature of cmdutil.makefileXXX() have changed
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
835 else:
d6e594644778 Make kwarchive work on Mercurial 4.6+ also: the signature of cmdutil.makefileXXX() have changed
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
836
d6e594644778 Make kwarchive work on Mercurial 4.6+ also: the signature of cmdutil.makefileXXX() have changed
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
837 # Mercurial < 4.6
d6e594644778 Make kwarchive work on Mercurial 4.6+ also: the signature of cmdutil.makefileXXX() have changed
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
838
d6e594644778 Make kwarchive work on Mercurial 4.6+ also: the signature of cmdutil.makefileXXX() have changed
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
839 def makefilename_compat(ctx, pat, **props):
d6e594644778 Make kwarchive work on Mercurial 4.6+ also: the signature of cmdutil.makefileXXX() have changed
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
840 return cmdutil.makefilename(ctx.repo(), pat, ctx.node(), **props)
d6e594644778 Make kwarchive work on Mercurial 4.6+ also: the signature of cmdutil.makefileXXX() have changed
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
841
d6e594644778 Make kwarchive work on Mercurial 4.6+ also: the signature of cmdutil.makefileXXX() have changed
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
842 def makefileobj_compat(ctx, pat, **props):
d6e594644778 Make kwarchive work on Mercurial 4.6+ also: the signature of cmdutil.makefileXXX() have changed
Franz Glasner <hg@dom66.de>
parents: 101
diff changeset
843 return cmdutil.makefileobj(ctx.repo(), pat, ctx.node(), **props)
304
71288cb43ba9 kwarchive: Make it work with Mercurial 4.6+ (really tested on 4.8.1).
Franz Glasner <hg@dom66.de>
parents: 300
diff changeset
844
71288cb43ba9 kwarchive: Make it work with Mercurial 4.6+ (really tested on 4.8.1).
Franz Glasner <hg@dom66.de>
parents: 300
diff changeset
845
71288cb43ba9 kwarchive: Make it work with Mercurial 4.6+ (really tested on 4.8.1).
Franz Glasner <hg@dom66.de>
parents: 300
diff changeset
846 if context_mapping_api:
71288cb43ba9 kwarchive: Make it work with Mercurial 4.6+ (really tested on 4.8.1).
Franz Glasner <hg@dom66.de>
parents: 300
diff changeset
847
71288cb43ba9 kwarchive: Make it work with Mercurial 4.6+ (really tested on 4.8.1).
Franz Glasner <hg@dom66.de>
parents: 300
diff changeset
848 class _FakeRenderContext(object):
71288cb43ba9 kwarchive: Make it work with Mercurial 4.6+ (really tested on 4.8.1).
Franz Glasner <hg@dom66.de>
parents: 300
diff changeset
849
71288cb43ba9 kwarchive: Make it work with Mercurial 4.6+ (really tested on 4.8.1).
Franz Glasner <hg@dom66.de>
parents: 300
diff changeset
850 @staticmethod
71288cb43ba9 kwarchive: Make it work with Mercurial 4.6+ (really tested on 4.8.1).
Franz Glasner <hg@dom66.de>
parents: 300
diff changeset
851 def resource(mapping, name):
71288cb43ba9 kwarchive: Make it work with Mercurial 4.6+ (really tested on 4.8.1).
Franz Glasner <hg@dom66.de>
parents: 300
diff changeset
852 return mapping[name]