annotate extensions/kwarchive.py @ 332:04deddddc6e5

Sort imports properly
author Franz Glasner <fzglas.hg@dom66.de>
date Sun, 14 Jul 2019 16:05:56 +0200
parents 99b44c866f4f
children eb1e0f129963
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$
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
4 #
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.
34
7c4addd60935 Put keyword into the extensions itself
Franz Glasner <hg@dom66.de>
parents: 33
diff changeset
10 #
60
eebebd7acc69 Wording of docu
Franz Glasner <hg@dom66.de>
parents: 57
diff changeset
11 """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
12
129
51a4f1f5df09 Docu: enhanced the docu of "kwarchive"
Franz Glasner <hg@dom66.de>
parents: 126
diff changeset
13 Configuration is done in a versioned ``.hgkwarchive`` configuration
51a4f1f5df09 Docu: enhanced the docu of "kwarchive"
Franz Glasner <hg@dom66.de>
parents: 126
diff changeset
14 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
15 configuration files.
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
16
129
51a4f1f5df09 Docu: enhanced the docu of "kwarchive"
Franz Glasner <hg@dom66.de>
parents: 126
diff changeset
17 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
18 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
19 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
20
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
21 Example::
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
22
120
9ed197b60e99 Prepare a [keywords] section with a whitelist of considered keywords and/or aliases
Franz Glasner <hg@dom66.de>
parents: 119
diff changeset
23 #
299
bbbb23202d6e - FIX: Typo in docu
Franz Glasner <hg@dom66.de>
parents: 298
diff changeset
24 # 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
25 # 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
26 #
33
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
27 [patterns]
299
bbbb23202d6e - FIX: Typo in docu
Franz Glasner <hg@dom66.de>
parents: 298
diff changeset
28 #
bbbb23202d6e - FIX: Typo in docu
Franz Glasner <hg@dom66.de>
parents: 298
diff changeset
29 # Expand keywords in every python file except those matching "x*"
bbbb23202d6e - FIX: Typo in docu
Franz Glasner <hg@dom66.de>
parents: 298
diff changeset
30 # using the default RCS style expansion format
bbbb23202d6e - FIX: Typo in docu
Franz Glasner <hg@dom66.de>
parents: 298
diff changeset
31 #
bbbb23202d6e - FIX: Typo in docu
Franz Glasner <hg@dom66.de>
parents: 298
diff changeset
32 **.py =
bbbb23202d6e - FIX: Typo in docu
Franz Glasner <hg@dom66.de>
parents: 298
diff changeset
33 x* = NO
bbbb23202d6e - FIX: Typo in docu
Franz Glasner <hg@dom66.de>
parents: 298
diff changeset
34 # This file has reStructuredText style keyword expansion "|VCS<kw>|" only
bbbb23202d6e - FIX: Typo in docu
Franz Glasner <hg@dom66.de>
parents: 298
diff changeset
35 path:VERSION = reST
bbbb23202d6e - FIX: Typo in docu
Franz Glasner <hg@dom66.de>
parents: 298
diff changeset
36 # This file has reStructuredText style and RCS style keyword expansion
bbbb23202d6e - FIX: Typo in docu
Franz Glasner <hg@dom66.de>
parents: 298
diff changeset
37 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
38
246
d23d3d97c106 FIX: Typo in docu: [keyword] -> [keywords]
Franz Glasner <hg@dom66.de>
parents: 160
diff changeset
39 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
40 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
41 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
42 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
43
51a4f1f5df09 Docu: enhanced the docu of "kwarchive"
Franz Glasner <hg@dom66.de>
parents: 126
diff changeset
44 Example::
51a4f1f5df09 Docu: enhanced the docu of "kwarchive"
Franz Glasner <hg@dom66.de>
parents: 126
diff changeset
45
120
9ed197b60e99 Prepare a [keywords] section with a whitelist of considered keywords and/or aliases
Franz Glasner <hg@dom66.de>
parents: 119
diff changeset
46 #
9ed197b60e99 Prepare a [keywords] section with a whitelist of considered keywords and/or aliases
Franz Glasner <hg@dom66.de>
parents: 119
diff changeset
47 # 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
48 # 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
49 # 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
50 #
124
46b7d34ef0b2 Enhanced the module documentation of "kwarchive"
Franz Glasner <hg@dom66.de>
parents: 122
diff changeset
51 # 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
52 #
46b7d34ef0b2 Enhanced the module documentation of "kwarchive"
Franz Glasner <hg@dom66.de>
parents: 122
diff changeset
53 # Alias = PreDefinedKeyword
46b7d34ef0b2 Enhanced the module documentation of "kwarchive"
Franz Glasner <hg@dom66.de>
parents: 122
diff changeset
54 #
46b7d34ef0b2 Enhanced the module documentation of "kwarchive"
Franz Glasner <hg@dom66.de>
parents: 122
diff changeset
55 # An empty `PreDefinedKeyword' means the identity.
46b7d34ef0b2 Enhanced the module documentation of "kwarchive"
Franz Glasner <hg@dom66.de>
parents: 122
diff changeset
56 #
120
9ed197b60e99 Prepare a [keywords] section with a whitelist of considered keywords and/or aliases
Franz Glasner <hg@dom66.de>
parents: 119
diff changeset
57 [keywords]
122
e6037655967b Implemented a keyword white-list including aliases.
Franz Glasner <hg@dom66.de>
parents: 120
diff changeset
58 # `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
59 Revision =
124
46b7d34ef0b2 Enhanced the module documentation of "kwarchive"
Franz Glasner <hg@dom66.de>
parents: 122
diff changeset
60 #
46b7d34ef0b2 Enhanced the module documentation of "kwarchive"
Franz Glasner <hg@dom66.de>
parents: 122
diff changeset
61 # 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
62 # 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
63 #
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
64 MyKeyword = {JustDate}
133
8d16138e00af Implemented substitution type keyword expansion
Franz Glasner <hg@dom66.de>
parents: 131
diff changeset
65 #
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
66 # `MyCustomSubstKeyword' is a substitution keyword.
133
8d16138e00af Implemented substitution type keyword expansion
Franz Glasner <hg@dom66.de>
parents: 131
diff changeset
67 #
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
68 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
69
33
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
70 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
71 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
72
130
c3397e670063 Docu: drop a note why templates are not supported in keyword definitions
Franz Glasner <hg@dom66.de>
parents: 129
diff changeset
73 .. 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
74 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
75 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
76 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
77
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
78 (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
79
28
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
80 """
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 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
83
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
84
42
b46ab29aefd8 Remove the "__version__" variable: use "__revision__" only instead
Franz Glasner <hg@dom66.de>
parents: 41
diff changeset
85 __revision__ = "$Revision$"
28
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
86
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
87 __author__ = "Franz Glasner"
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
88
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 import os
332
04deddddc6e5 Sort imports properly
Franz Glasner <fzglas.hg@dom66.de>
parents: 331
diff changeset
91 import inspect
33
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
92 import itertools
28
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
93
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
94 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
95 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
96 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
97 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
98 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
99 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
100 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
101 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
102 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
103 # 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
104 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
105 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
106 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
107 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
108 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
109 # >= 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
110 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
111 # 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
112 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
113 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
114 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
115 _dateutil = util
28
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
116
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
117
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
118 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
119
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
3807a60ee0dd Shorten path urls by default when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 47
diff changeset
128
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
129 KWARCHIVE_CONFIG = b".hgkwarchive"
156
d92850f876a4 Use a constant to define the ".hgkwarchive" name
Franz Glasner <hg@dom66.de>
parents: 155
diff changeset
130
d92850f876a4 Use a constant to define the ".hgkwarchive" name
Franz Glasner <hg@dom66.de>
parents: 155
diff changeset
131
28
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
132 cmdtable = {}
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
133
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
134 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
135 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
136 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
137 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
138
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
139
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
140 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
141 """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
142
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 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
144 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
145
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 """
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 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
148 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
149 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
150 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
151 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
152 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
153 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
154 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
155 # 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
156 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
157 "../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
158 "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
159 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
160 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
161 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
162
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
163
114
a51822141ccf Style: handled some more flake8 warnings: consistent command declaration list formatting
Franz Glasner <hg@dom66.de>
parents: 112
diff changeset
164 @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
165 b"kwarchive",
114
a51822141ccf Style: handled some more flake8 warnings: consistent command declaration list formatting
Franz Glasner <hg@dom66.de>
parents: 112
diff changeset
166 [
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
167 (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
168 (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
169 (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
170 (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
171 (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
172 (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
173 (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
174 (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
175 (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
176 ] + 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
177 _(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
178 inferrepo=True)
28
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
179 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
180 '''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
181
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
182 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
183 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
184
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
185 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
186 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
187
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
188 .. container:: verbose
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 Examples:
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 - 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
193
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
194 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
195
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
196 - 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
197
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
198 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
199
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
200 Valid types are:
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
201
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
202 :``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
203 :``tar``: tar archive, uncompressed
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
204 :``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
205 :``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
206 :``uzip``: zip archive, uncompressed
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
207 :``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
208
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
209 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
210 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
211
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
212 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
213 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
214 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
215 removed.
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
216
41
c05d8dcb4bb0 Doku: Enhance
Franz Glasner <hg@dom66.de>
parents: 36
diff changeset
217 Use --path to specify named path information from :hg:`paths` as
c05d8dcb4bb0 Doku: Enhance
Franz Glasner <hg@dom66.de>
parents: 36
diff changeset
218 the canonical repository location. Use ``.`` for the current
c05d8dcb4bb0 Doku: Enhance
Franz Glasner <hg@dom66.de>
parents: 36
diff changeset
219 repository root root. If no path is given then ``default`` is
c05d8dcb4bb0 Doku: Enhance
Franz Glasner <hg@dom66.de>
parents: 36
diff changeset
220 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
221
51
3807a60ee0dd Shorten path urls by default when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 47
diff changeset
222 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
223 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
224
65
bdb549d71148 Allow customization of the $Author$ output when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 64
diff changeset
225 Allowed --user-filter values are:
bdb549d71148 Allow customization of the $Author$ output when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 64
diff changeset
226
bdb549d71148 Allow customization of the $Author$ output when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 64
diff changeset
227 :``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
228 :``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
229 :``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
230 :``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
231 :``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
232
93
fa84debfb50e Replace "no-shorten-url" by "path-filter"
Franz Glasner <hg@dom66.de>
parents: 92
diff changeset
233 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
234
fa84debfb50e Replace "no-shorten-url" by "path-filter"
Franz Glasner <hg@dom66.de>
parents: 92
diff changeset
235 :``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
236 :``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
237 :``nouser``: like ``full`` but without user and password information
101
ec4392ae8c92 FIX: Wording in help
Franz Glasner <hg@dom66.de>
parents: 100
diff changeset
238 :``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
239 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
240 :``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
241
28
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
242 Returns 0 on success.
41
c05d8dcb4bb0 Doku: Enhance
Franz Glasner <hg@dom66.de>
parents: 36
diff changeset
243
28
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
244 '''
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
245
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
246 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
247 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
248 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
249 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
250 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
251 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
252 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
253 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
254
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
255 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
256 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
257
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
258 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
259 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
260 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
261 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
262 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
263 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
264
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
265 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
266 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
267
58f47399691c New successful PoC: monkey-patch all relevant archiver's "addfile()" method
Franz Glasner <hg@dom66.de>
parents: 28
diff changeset
268 #
31
0597395e2d18 Comment: better explanation of what is monkey-patched
Franz Glasner <hg@dom66.de>
parents: 30
diff changeset
269 # 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
270 # expands keywords
58f47399691c New successful PoC: monkey-patch all relevant archiver's "addfile()" method
Franz Glasner <hg@dom66.de>
parents: 28
diff changeset
271 #
32
cfa53f8a6607 Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents: 31
diff changeset
272 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
273 patch_archiver_class(
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
274 ac,
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
275 make_keyword_filter(
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
276 ui,
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
277 ctx,
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
278 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
279 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
280 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
281 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
282 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
283 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
284 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
285
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
286 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
287 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
288
32
cfa53f8a6607 Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents: 31
diff changeset
289 # XXX FIXME: Should the original methods be restored here?
cfa53f8a6607 Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents: 31
diff changeset
290
46
4a0c26dfef3c Comment about automatically amending .hg_archival.txt with "path" items.
Franz Glasner <hg@dom66.de>
parents: 45
diff changeset
291 # 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
292 # 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
293 # 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
294 # 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
295
32
cfa53f8a6607 Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents: 31
diff changeset
296
114
a51822141ccf Style: handled some more flake8 warnings: consistent command declaration list formatting
Franz Glasner <hg@dom66.de>
parents: 112
diff changeset
297 @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
298 b"kwprint",
114
a51822141ccf Style: handled some more flake8 warnings: consistent command declaration list formatting
Franz Glasner <hg@dom66.de>
parents: 112
diff changeset
299 [
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
300 (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
301 (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
302 (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
303 (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
304 (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
305 (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
306 (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
307 ] + 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
308 _(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
309 inferrepo=True)
45
c077d30da0ee Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents: 44
diff changeset
310 def kwprint(ui, repo, **opts):
109
be4811239acf kwprint: print example file-dependent keywords also.
Franz Glasner <hg@dom66.de>
parents: 108
diff changeset
311 '''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
312 keywords
45
c077d30da0ee Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents: 44
diff changeset
313
c077d30da0ee Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents: 44
diff changeset
314 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
315 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
316
c077d30da0ee Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents: 44
diff changeset
317 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
318 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
319 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
320 assumed.
c077d30da0ee Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents: 44
diff changeset
321
51
3807a60ee0dd Shorten path urls by default when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 47
diff changeset
322 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
323 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
324
65
bdb549d71148 Allow customization of the $Author$ output when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 64
diff changeset
325 Allowed --user-filter values are:
bdb549d71148 Allow customization of the $Author$ output when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 64
diff changeset
326
bdb549d71148 Allow customization of the $Author$ output when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 64
diff changeset
327 :``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
328 :``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
329 :``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
330 :``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
331 :``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
332
93
fa84debfb50e Replace "no-shorten-url" by "path-filter"
Franz Glasner <hg@dom66.de>
parents: 92
diff changeset
333 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
334
fa84debfb50e Replace "no-shorten-url" by "path-filter"
Franz Glasner <hg@dom66.de>
parents: 92
diff changeset
335 :``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
336 :``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
337 :``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
338 :``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
339 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
340 :``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
341
78
743dd4a77b4a Implemented a "--reST" option for printing reST substitution definitions from keywords
Franz Glasner <hg@dom66.de>
parents: 76
diff changeset
342 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
343 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
344 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
345
109
be4811239acf kwprint: print example file-dependent keywords also.
Franz Glasner <hg@dom66.de>
parents: 108
diff changeset
346 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
347 example file.
be4811239acf kwprint: print example file-dependent keywords also.
Franz Glasner <hg@dom66.de>
parents: 108
diff changeset
348
45
c077d30da0ee Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents: 44
diff changeset
349 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
350
c077d30da0ee Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents: 44
diff changeset
351 '''
c077d30da0ee Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents: 44
diff changeset
352
c077d30da0ee Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents: 44
diff changeset
353 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
354 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
355 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
356 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
357 node = ctx.node()
c077d30da0ee Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents: 44
diff changeset
358
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
359 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
360
c077d30da0ee Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents: 44
diff changeset
361 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
362 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
363 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
364 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
365 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
366 # 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
367 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
368 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
369 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
370 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
371 b"a4dd6f4b22e11fec41158eec187630c24a43120a")
294
2eb443e77cff Refactor: put the real keyword printing into a separate function.
Franz Glasner <hg@dom66.de>
parents: 293
diff changeset
372 else:
2eb443e77cff Refactor: put the real keyword printing into a separate function.
Franz Glasner <hg@dom66.de>
parents: 293
diff changeset
373 file_keywords = None
2eb443e77cff Refactor: put the real keyword printing into a separate function.
Franz Glasner <hg@dom66.de>
parents: 293
diff changeset
374 _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
375 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
376 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
377 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
378 _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
379 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
380 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
381 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
382 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
383
2eb443e77cff Refactor: put the real keyword printing into a separate function.
Franz Glasner <hg@dom66.de>
parents: 293
diff changeset
384
2eb443e77cff Refactor: put the real keyword printing into a separate function.
Franz Glasner <hg@dom66.de>
parents: 293
diff changeset
385 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
386 """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
387 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
388 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
389 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
390 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
391 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
392 #
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 # 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
394 # 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
395 #
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".. |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
397 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
398 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
399 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
400 ui.write(b"\n")
109
be4811239acf kwprint: print example file-dependent keywords also.
Franz Glasner <hg@dom66.de>
parents: 108
diff changeset
401 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
402 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
403 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
404 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
405 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
406
31d5d77c297d Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents: 290
diff changeset
407
294
2eb443e77cff Refactor: put the real keyword printing into a separate function.
Franz Glasner <hg@dom66.de>
parents: 293
diff changeset
408 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
409 """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
410 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
411 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
412 # 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
413 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
414 continue
291
31d5d77c297d Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents: 290
diff changeset
415 subrep = ctx.workingsub(subpath)
31d5d77c297d Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents: 290
diff changeset
416 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
417 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
418 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
419 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
420 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
421 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
422 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
423 if not no_file:
330
793161e48af2 FIX: Remove duplicate assignment to file_keywords
Franz Glasner <fzglas.hg@dom66.de>
parents: 328
diff changeset
424 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
425 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
426 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
427 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
428 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
429 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
430 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
431 _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
432 # 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
433 _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
434
31d5d77c297d Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents: 290
diff changeset
435
31d5d77c297d Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents: 290
diff changeset
436 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
437 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
438 for subpath in sorted(ctx.substate):
31d5d77c297d Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents: 290
diff changeset
439 ui.write("SUBPATH: " + subpath + "\n");
31d5d77c297d Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents: 290
diff changeset
440 subrep = ctx.workingsub(subpath)
31d5d77c297d Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents: 290
diff changeset
441 ui.write(repr(subrep) + ": subrelpath=" + subrepo.subrelpath(subrep)
31d5d77c297d Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents: 290
diff changeset
442 + " reporelpath=" + subrepo.reporelpath(subrep._repo)
31d5d77c297d Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents: 290
diff changeset
443 + '\n')
31d5d77c297d Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents: 290
diff changeset
444 # Yes(!)
31d5d77c297d Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents: 290
diff changeset
445 assert subrepo.subrelpath(subrep) == subrepo.reporelpath(subrep._repo)
31d5d77c297d Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents: 290
diff changeset
446 assert subrepo.subrelpath(subrep).endswith(subpath)
31d5d77c297d Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents: 290
diff changeset
447 ui.write(" " + repr(subrep._getctx()) + '\n')
31d5d77c297d Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents: 290
diff changeset
448 _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
449
c077d30da0ee Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents: 44
diff changeset
450
33
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
451 def patch_archiver_class(archivername, filter):
32
cfa53f8a6607 Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents: 31
diff changeset
452 """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
453
cfa53f8a6607 Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents: 31
diff changeset
454 archiver_class = getattr(archival, archivername)
cfa53f8a6607 Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents: 31
diff changeset
455 orig_addfile = getattr(archiver_class, "addfile")
cfa53f8a6607 Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents: 31
diff changeset
456
287
95c207d21bbf FIX: Typo in argument: "isline" -> "islink"
Franz Glasner <hg@dom66.de>
parents: 255
diff changeset
457 def new_addfile(self, name, mode, islink, data):
95c207d21bbf FIX: Typo in argument: "isline" -> "islink"
Franz Glasner <hg@dom66.de>
parents: 255
diff changeset
458 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
459
cfa53f8a6607 Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents: 31
diff changeset
460 setattr(archiver_class, "addfile", new_addfile)
cfa53f8a6607 Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents: 31
diff changeset
461 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
462
28
c8b7d0635656 PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff changeset
463
293
75070825d111 - make_node_keywords() and make_keyword_filter() do not need a "repo" argument.
Franz Glasner <hg@dom66.de>
parents: 292
diff changeset
464 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
465 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
466 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
467 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
468 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
469 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
470 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
471 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
472 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
473 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
474 }
298
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
475 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
476 _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
477 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
478 kwconfig,
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
479 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
480 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
481 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
482 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
483
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
484 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
485 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
486 if archive_class != "fileit":
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
487 if prefix:
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
488 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
489 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
490 # 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
491 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
492 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
493 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
494 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
495 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
496 else:
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
497 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
498 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
499 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
500 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
501 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
502
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
503 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
504 #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
505 return data
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
506 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
507 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
508 except LookupError:
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
509 nodeid = None
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
510 # 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
511 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
512 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
513 _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
514 _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
515 # 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
516 _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
517 _MARKER_RST = b'|'
296
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
518 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
519 #
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
520 # 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
521 # 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
522 #
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
523 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
524 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
525 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
526 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
527 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
528 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
529 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
530 # 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
531 _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
532 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
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 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
535 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
536 # 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
537 kwds = []
296
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
538 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
539 # 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
540 kwds = [kw]
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
541 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
542 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
543 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
544 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
545 % (_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
546 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
547 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
548 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
549 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
550 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
551 return data
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 return _filter
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
554
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
555
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
556 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
557 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
558 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
559 hgpath=hgpath,
93
fa84debfb50e Replace "no-shorten-url" by "path-filter"
Franz Glasner <hg@dom66.de>
parents: 92
diff changeset
560 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
561 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
562 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
563 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
564 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
565 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
566 kwconfigname = kwconfig
33
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
567 try:
47
94ae433383a2 Allow an alternate patterns file (instead of .hgkwarchive) with the --kwconfig option.
Franz Glasner <hg@dom66.de>
parents: 46
diff changeset
568 if kwconfigdata is None:
156
d92850f876a4 Use a constant to define the ".hgkwarchive" name
Franz Glasner <hg@dom66.de>
parents: 155
diff changeset
569 # use versioned .hgkwarchive
d92850f876a4 Use a constant to define the ".hgkwarchive" name
Franz Glasner <hg@dom66.de>
parents: 155
diff changeset
570 kwconfigdata = ctx[KWARCHIVE_CONFIG].data()
d92850f876a4 Use a constant to define the ".hgkwarchive" name
Franz Glasner <hg@dom66.de>
parents: 155
diff changeset
571 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
572 except (IOError, LookupError):
296
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
573 # 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
574 return None
33
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
575 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
576 #
71b321436cc1 Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents: 42
diff changeset
577 # 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
578 # 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
579 #
33
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
580 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
581 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
582 include = []
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
583 exclude = []
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
584 patterns = []
118
e9c78a0bfe6a Allow multiple style keyword expansion in one file.
Franz Glasner <hg@dom66.de>
parents: 116
diff changeset
585 patterns_rcs = []
79
53c9f2f6a13e Work in reST style keywords in kwarchive
Franz Glasner <hg@dom66.de>
parents: 78
diff changeset
586 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
587 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
588 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
589 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
590 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
591 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
592 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
593 exclude.append(pattern)
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
594 else:
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
595 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
596 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
597 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
598 if b"RCS" in styles:
118
e9c78a0bfe6a Allow multiple style keyword expansion in one file.
Franz Glasner <hg@dom66.de>
parents: 116
diff changeset
599 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
600 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
601 patterns_rst.append(pattern)
e9c78a0bfe6a Allow multiple style keyword expansion in one file.
Franz Glasner <hg@dom66.de>
parents: 116
diff changeset
602 else:
e9c78a0bfe6a Allow multiple style keyword expansion in one file.
Franz Glasner <hg@dom66.de>
parents: 116
diff changeset
603 # 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
604 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
605 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
606 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
607 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
608 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
609
e9c78a0bfe6a Allow multiple style keyword expansion in one file.
Franz Glasner <hg@dom66.de>
parents: 116
diff changeset
610 #
e9c78a0bfe6a Allow multiple style keyword expansion in one file.
Franz Glasner <hg@dom66.de>
parents: 116
diff changeset
611 # 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
612 # true.
e9c78a0bfe6a Allow multiple style keyword expansion in one file.
Franz Glasner <hg@dom66.de>
parents: 116
diff changeset
613 #
e9c78a0bfe6a Allow multiple style keyword expansion in one file.
Franz Glasner <hg@dom66.de>
parents: 116
diff changeset
614 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
615 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
616 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
617 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
618 patterns=patterns_rcs,
118
e9c78a0bfe6a Allow multiple style keyword expansion in one file.
Franz Glasner <hg@dom66.de>
parents: 116
diff changeset
619 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
620 #
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 # 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
622 # 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
623 #
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 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
625 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
626 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
627 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
628 patterns=patterns_rst,
79
53c9f2f6a13e Work in reST style keywords in kwarchive
Franz Glasner <hg@dom66.de>
parents: 78
diff changeset
629 include=[], exclude=[])
33
dc8db9693262 kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents: 32
diff changeset
630
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
631 #
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
632 # 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
633 # 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
634 # 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
635 # 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
636 # expansion.
133
8d16138e00af Implemented substitution type keyword expansion
Franz Glasner <hg@dom66.de>
parents: 131
diff changeset
637 #
8d16138e00af Implemented substitution type keyword expansion
Franz Glasner <hg@dom66.de>
parents: 131
diff changeset
638 keyword_substitutions = {}
8d16138e00af Implemented substitution type keyword expansion
Franz Glasner <hg@dom66.de>
parents: 131
diff changeset
639
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
640 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
641 keyword_substitutions[alias] = value
122
e6037655967b Implemented a keyword white-list including aliases.
Franz Glasner <hg@dom66.de>
parents: 120
diff changeset
642
e6037655967b Implemented a keyword white-list including aliases.
Franz Glasner <hg@dom66.de>
parents: 120
diff changeset
643 #
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
644 # 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
645 #
65789e3e8e3d Provide a "HGnodeid" per file keyword that expands to the NodeID of the artifact.
Franz Glasner <hg@dom66.de>
parents: 103
diff changeset
646 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
647
296
15d23729d176 Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents: 295
diff changeset
648 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
649 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
650 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
651
71b321436cc1 Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents: 42
diff changeset
652
298
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
653 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
654 ui,
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
655 ctx,
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
656 kwconfig,
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
657 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
658
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
659 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
660 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
661 # 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
662 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
663 continue
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
664 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
665 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
666
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
667 # 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
668 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
669 _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
670 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
671
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
672 # 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
673 _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
674 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
675 kwconfig,
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
676 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
677
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
678
293
75070825d111 - make_node_keywords() and make_keyword_filter() do not need a "repo" argument.
Franz Glasner <hg@dom66.de>
parents: 292
diff changeset
679 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
680 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
681 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
682 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
683 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
684 """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
685
71b321436cc1 Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents: 42
diff changeset
686 """
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
687 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
688 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
689 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
690 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
691 hglocation = ui.paths[hgpath].loc
158
07e323b8d27d Refactor: make_node_keywords: path handling
Franz Glasner <hg@dom66.de>
parents: 157
diff changeset
692 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
693 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
694 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
695 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
696 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
697 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
698 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
699 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
700 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
701 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
702 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
703 path_url = util.url(hglocation)
158
07e323b8d27d Refactor: make_node_keywords: path handling
Franz Glasner <hg@dom66.de>
parents: 157
diff changeset
704 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
705 b"hg")
158
07e323b8d27d Refactor: make_node_keywords: path handling
Franz Glasner <hg@dom66.de>
parents: 157
diff changeset
706 path_url.user = None
07e323b8d27d Refactor: make_node_keywords: path handling
Franz Glasner <hg@dom66.de>
parents: 157
diff changeset
707 path_url.passwd = None
07e323b8d27d Refactor: make_node_keywords: path handling
Franz Glasner <hg@dom66.de>
parents: 157
diff changeset
708 path_url.host = stripped_hostname(path_url.host)
07e323b8d27d Refactor: make_node_keywords: path handling
Franz Glasner <hg@dom66.de>
parents: 157
diff changeset
709 path_url.port = None
07e323b8d27d Refactor: make_node_keywords: path handling
Franz Glasner <hg@dom66.de>
parents: 157
diff changeset
710 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
711 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
712 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
713 path_uri = pycompat.sysbytes(".../"+path_url[-1])
158
07e323b8d27d Refactor: make_node_keywords: path handling
Franz Glasner <hg@dom66.de>
parents: 157
diff changeset
714 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
715 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
716 % path_filter)
07e323b8d27d Refactor: make_node_keywords: path handling
Franz Glasner <hg@dom66.de>
parents: 157
diff changeset
717 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
718 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
719 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
720 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
721 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
722 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
723 if m >= 0:
d313b33c9c06 Implement the "last" path-filter for the local repo "." also
Franz Glasner <hg@dom66.de>
parents: 158
diff changeset
724 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
725 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
726 # 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
727 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
728 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
729 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
730 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
731 # 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
732 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
733 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
734 # 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
735 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
736 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
737 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
738 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
739 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
740 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
741 }
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(_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
743 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
744 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
745 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
746 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
747 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
748 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
749 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
750 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
751 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
752 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
753 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
754 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
755 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
756 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
757 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
758 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
759 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
760 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
761 # 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
762 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
763 }
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
764 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
765 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
766 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
767 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
768 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
769 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
770 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
771 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
772 #
e02aceb91a9b Make "full" a user filter and "none" an alias to "full"
Franz Glasner <hg@dom66.de>
parents: 80
diff changeset
773 # "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
774 # alias for "full".
e02aceb91a9b Make "full" a user filter and "none" an alias to "full"
Franz Glasner <hg@dom66.de>
parents: 80
diff changeset
775 # 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
776 #
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 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
778 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
779 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
780
44
71b321436cc1 Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents: 42
diff changeset
781 return keywords
51
3807a60ee0dd Shorten path urls by default when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 47
diff changeset
782
3807a60ee0dd Shorten path urls by default when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 47
diff changeset
783
298
aa945541d2ca kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents: 296
diff changeset
784 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
785 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
786 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
787 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
788 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
789 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
790 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
791 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
792 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
793 b"HGnodeid": nodeid or b'',
109
be4811239acf kwprint: print example file-dependent keywords also.
Franz Glasner <hg@dom66.de>
parents: 108
diff changeset
794 }
be4811239acf kwprint: print example file-dependent keywords also.
Franz Glasner <hg@dom66.de>
parents: 108
diff changeset
795
be4811239acf kwprint: print example file-dependent keywords also.
Franz Glasner <hg@dom66.de>
parents: 108
diff changeset
796
51
3807a60ee0dd Shorten path urls by default when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 47
diff changeset
797 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
798 """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
799 if not hostname:
3807a60ee0dd Shorten path urls by default when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 47
diff changeset
800 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
801 idx = hostname.find(b'.')
51
3807a60ee0dd Shorten path urls by default when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 47
diff changeset
802 if idx < 0:
3807a60ee0dd Shorten path urls by default when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 47
diff changeset
803 return hostname
3807a60ee0dd Shorten path urls by default when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 47
diff changeset
804 return hostname[:idx]
65
bdb549d71148 Allow customization of the $Author$ output when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 64
diff changeset
805
bdb549d71148 Allow customization of the $Author$ output when expanding keywords.
Franz Glasner <hg@dom66.de>
parents: 64
diff changeset
806
136
f470702886b4 Renamed some internal functions to provide a more descriptive name
Franz Glasner <hg@dom66.de>
parents: 134
diff changeset
807 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
808 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
809 # "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
810 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
811 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
812 _(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
813 return uf
93
fa84debfb50e Replace "no-shorten-url" by "path-filter"
Franz Glasner <hg@dom66.de>
parents: 92
diff changeset
814
fa84debfb50e Replace "no-shorten-url" by "path-filter"
Franz Glasner <hg@dom66.de>
parents: 92
diff changeset
815
136
f470702886b4 Renamed some internal functions to provide a more descriptive name
Franz Glasner <hg@dom66.de>
parents: 134
diff changeset
816 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
817 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
818 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
819 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
820 _(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
821 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
822
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
823
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
824 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
825 # 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
826 _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
827 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
828 _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
829
99b44c866f4f Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents: 330
diff changeset
830 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
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 # 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
833
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 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
835 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
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 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
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 # 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
840
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 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
842 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
843
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
844 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
845 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
846
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 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
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 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
851
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 @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
853 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
854 return mapping[name]