Mercurial > hgrepos > DevTools > mercurial-extensions
annotate extensions/kwarchive.py @ 348:41a8e3db181c
Adjust copyright year to 2020
| author | Franz Glasner <fzglas.hg@dom66.de> |
|---|---|
| date | Mon, 06 Jan 2020 18:55:06 +0100 |
| parents | a69c89c18546 |
| children | 0d889720613d |
| rev | line source |
|---|---|
|
28
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
1 # -*- coding: utf-8 -*- |
|
125
fb7e1e4e4d2c
Provide some SCCS markers also to be able to search with "what(1)" also
Franz Glasner <hg@dom66.de>
parents:
124
diff
changeset
|
2 # @(#) $HGheader$ |
|
315
e9ded6c1db41
Add a copyright and license note to the revinfo and kwarchive modules and to the README also.
Franz Glasner <fzglas.hg@dom66.de>
parents:
314
diff
changeset
|
3 # $HGnodeid$ |
|
336
eb1e0f129963
More compliance with the private style guide for Mercurial extensions for the metadata of the extensions
Franz Glasner <fzglas.hg@dom66.de>
parents:
332
diff
changeset
|
4 # :- |
|
348
41a8e3db181c
Adjust copyright year to 2020
Franz Glasner <fzglas.hg@dom66.de>
parents:
342
diff
changeset
|
5 # :Copyright: (C) 2017-2020 Franz Glasner <fzglas.hg@dom66.de> |
|
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
|
6 # :License: This software may be used and distributed according to the |
|
e9ded6c1db41
Add a copyright and license note to the revinfo and kwarchive modules and to the README also.
Franz Glasner <fzglas.hg@dom66.de>
parents:
314
diff
changeset
|
7 # terms of the GNU General Public License version 2 or any |
|
e9ded6c1db41
Add a copyright and license note to the revinfo and kwarchive modules and to the README also.
Franz Glasner <fzglas.hg@dom66.de>
parents:
314
diff
changeset
|
8 # later version. |
|
e9ded6c1db41
Add a copyright and license note to the revinfo and kwarchive modules and to the README also.
Franz Glasner <fzglas.hg@dom66.de>
parents:
314
diff
changeset
|
9 # The license is incorporated herein by reference. |
|
336
eb1e0f129963
More compliance with the private style guide for Mercurial extensions for the metadata of the extensions
Franz Glasner <fzglas.hg@dom66.de>
parents:
332
diff
changeset
|
10 # :- |
|
34
7c4addd60935
Put keyword into the extensions itself
Franz Glasner <hg@dom66.de>
parents:
33
diff
changeset
|
11 # |
| 60 | 12 """like :hg:`archive` but with keyword expansion within selected files |
|
33
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
13 |
|
129
51a4f1f5df09
Docu: enhanced the docu of "kwarchive"
Franz Glasner <hg@dom66.de>
parents:
126
diff
changeset
|
14 Configuration is done in a versioned ``.hgkwarchive`` configuration |
|
51a4f1f5df09
Docu: enhanced the docu of "kwarchive"
Franz Glasner <hg@dom66.de>
parents:
126
diff
changeset
|
15 file. This file uses the same syntax as all other Mercurial |
|
33
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
16 configuration files. |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
17 |
|
129
51a4f1f5df09
Docu: enhanced the docu of "kwarchive"
Franz Glasner <hg@dom66.de>
parents:
126
diff
changeset
|
18 The ``[patterns]`` section specifies which files should have the |
|
51a4f1f5df09
Docu: enhanced the docu of "kwarchive"
Franz Glasner <hg@dom66.de>
parents:
126
diff
changeset
|
19 keywords expanded and possibly the style of expansion. The keys are |
|
51a4f1f5df09
Docu: enhanced the docu of "kwarchive"
Franz Glasner <hg@dom66.de>
parents:
126
diff
changeset
|
20 Mercurial file name patterns as described in :hg:`patterns`. |
|
33
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
21 |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
22 Example:: |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
23 |
|
120
9ed197b60e99
Prepare a [keywords] section with a whitelist of considered keywords and/or aliases
Franz Glasner <hg@dom66.de>
parents:
119
diff
changeset
|
24 # |
| 299 | 25 # Determine which files are considered for keyword expansion in |
|
120
9ed197b60e99
Prepare a [keywords] section with a whitelist of considered keywords and/or aliases
Franz Glasner <hg@dom66.de>
parents:
119
diff
changeset
|
26 # which style |
|
9ed197b60e99
Prepare a [keywords] section with a whitelist of considered keywords and/or aliases
Franz Glasner <hg@dom66.de>
parents:
119
diff
changeset
|
27 # |
|
33
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
28 [patterns] |
| 299 | 29 # |
| 30 # Expand keywords in every python file except those matching "x*" | |
| 31 # using the default RCS style expansion format | |
| 32 # | |
| 33 **.py = | |
| 34 x* = NO | |
| 35 # This file has reStructuredText style keyword expansion "|VCS<kw>|" only | |
| 36 path:VERSION = reST | |
| 37 # This file has reStructuredText style and RCS style keyword expansion | |
| 38 path:README = reST, RCS | |
|
33
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
39 |
|
246
d23d3d97c106
FIX: Typo in docu: [keyword] -> [keywords]
Franz Glasner <hg@dom66.de>
parents:
160
diff
changeset
|
40 The ``[keywords]`` section specifies which keywords are expanded. Aliases |
|
129
51a4f1f5df09
Docu: enhanced the docu of "kwarchive"
Franz Glasner <hg@dom66.de>
parents:
126
diff
changeset
|
41 can be defined also. By default the pre-defined set of RCC/CVS/SVN-like |
|
51a4f1f5df09
Docu: enhanced the docu of "kwarchive"
Franz Glasner <hg@dom66.de>
parents:
126
diff
changeset
|
42 keywords is expanded. A non-empty ``[keyword]`` section defines an |
|
51a4f1f5df09
Docu: enhanced the docu of "kwarchive"
Franz Glasner <hg@dom66.de>
parents:
126
diff
changeset
|
43 explicit white-list of expanded keywords and/or aliases. |
|
51a4f1f5df09
Docu: enhanced the docu of "kwarchive"
Franz Glasner <hg@dom66.de>
parents:
126
diff
changeset
|
44 |
|
51a4f1f5df09
Docu: enhanced the docu of "kwarchive"
Franz Glasner <hg@dom66.de>
parents:
126
diff
changeset
|
45 Example:: |
|
51a4f1f5df09
Docu: enhanced the docu of "kwarchive"
Franz Glasner <hg@dom66.de>
parents:
126
diff
changeset
|
46 |
|
120
9ed197b60e99
Prepare a [keywords] section with a whitelist of considered keywords and/or aliases
Franz Glasner <hg@dom66.de>
parents:
119
diff
changeset
|
47 # |
|
9ed197b60e99
Prepare a [keywords] section with a whitelist of considered keywords and/or aliases
Franz Glasner <hg@dom66.de>
parents:
119
diff
changeset
|
48 # Determine which keywords are expanded. |
|
9ed197b60e99
Prepare a [keywords] section with a whitelist of considered keywords and/or aliases
Franz Glasner <hg@dom66.de>
parents:
119
diff
changeset
|
49 # A missing and/or empty section means that all predefined keywords |
|
9ed197b60e99
Prepare a [keywords] section with a whitelist of considered keywords and/or aliases
Franz Glasner <hg@dom66.de>
parents:
119
diff
changeset
|
50 # are expanded. |
|
9ed197b60e99
Prepare a [keywords] section with a whitelist of considered keywords and/or aliases
Franz Glasner <hg@dom66.de>
parents:
119
diff
changeset
|
51 # |
|
124
46b7d34ef0b2
Enhanced the module documentation of "kwarchive"
Franz Glasner <hg@dom66.de>
parents:
122
diff
changeset
|
52 # Consisting of key-value pairs with of the form |
|
46b7d34ef0b2
Enhanced the module documentation of "kwarchive"
Franz Glasner <hg@dom66.de>
parents:
122
diff
changeset
|
53 # |
|
46b7d34ef0b2
Enhanced the module documentation of "kwarchive"
Franz Glasner <hg@dom66.de>
parents:
122
diff
changeset
|
54 # Alias = PreDefinedKeyword |
|
46b7d34ef0b2
Enhanced the module documentation of "kwarchive"
Franz Glasner <hg@dom66.de>
parents:
122
diff
changeset
|
55 # |
|
46b7d34ef0b2
Enhanced the module documentation of "kwarchive"
Franz Glasner <hg@dom66.de>
parents:
122
diff
changeset
|
56 # An empty `PreDefinedKeyword' means the identity. |
|
46b7d34ef0b2
Enhanced the module documentation of "kwarchive"
Franz Glasner <hg@dom66.de>
parents:
122
diff
changeset
|
57 # |
|
120
9ed197b60e99
Prepare a [keywords] section with a whitelist of considered keywords and/or aliases
Franz Glasner <hg@dom66.de>
parents:
119
diff
changeset
|
58 [keywords] |
|
122
e6037655967b
Implemented a keyword white-list including aliases.
Franz Glasner <hg@dom66.de>
parents:
120
diff
changeset
|
59 # `Revision' and possibly the `VCSRevision' keyword is expanded |
|
120
9ed197b60e99
Prepare a [keywords] section with a whitelist of considered keywords and/or aliases
Franz Glasner <hg@dom66.de>
parents:
119
diff
changeset
|
60 Revision = |
|
124
46b7d34ef0b2
Enhanced the module documentation of "kwarchive"
Franz Glasner <hg@dom66.de>
parents:
122
diff
changeset
|
61 # |
|
46b7d34ef0b2
Enhanced the module documentation of "kwarchive"
Franz Glasner <hg@dom66.de>
parents:
122
diff
changeset
|
62 # Additionally: `MyKeyword' is expanded with the contents of the |
|
321
103df4b7a0c8
A new more flexible syntax for custom keyword expansion: with Python template format syntax now
Franz Glasner <fzglas.hg@dom66.de>
parents:
315
diff
changeset
|
63 # pre-defined `JustDate' (this is in Python's format syntax). |
|
124
46b7d34ef0b2
Enhanced the module documentation of "kwarchive"
Franz Glasner <hg@dom66.de>
parents:
122
diff
changeset
|
64 # |
|
321
103df4b7a0c8
A new more flexible syntax for custom keyword expansion: with Python template format syntax now
Franz Glasner <fzglas.hg@dom66.de>
parents:
315
diff
changeset
|
65 MyKeyword = {JustDate} |
|
133
8d16138e00af
Implemented substitution type keyword expansion
Franz Glasner <hg@dom66.de>
parents:
131
diff
changeset
|
66 # |
|
321
103df4b7a0c8
A new more flexible syntax for custom keyword expansion: with Python template format syntax now
Franz Glasner <fzglas.hg@dom66.de>
parents:
315
diff
changeset
|
67 # `MyCustomSubstKeyword' is a substitution keyword. |
|
133
8d16138e00af
Implemented substitution type keyword expansion
Franz Glasner <hg@dom66.de>
parents:
131
diff
changeset
|
68 # |
|
321
103df4b7a0c8
A new more flexible syntax for custom keyword expansion: with Python template format syntax now
Franz Glasner <fzglas.hg@dom66.de>
parents:
315
diff
changeset
|
69 MyCustomSubstKeyword = This is my replacement content |
|
120
9ed197b60e99
Prepare a [keywords] section with a whitelist of considered keywords and/or aliases
Franz Glasner <hg@dom66.de>
parents:
119
diff
changeset
|
70 |
|
33
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
71 A non-existing ``.hgkwarchive`` file deactivates keyword expansion as does |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
72 an empty ``[patterns]`` section. |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
73 |
|
130
c3397e670063
Docu: drop a note why templates are not supported in keyword definitions
Franz Glasner <hg@dom66.de>
parents:
129
diff
changeset
|
74 .. note:: Because the keyword expansion is defined in a *versioned* file |
|
c3397e670063
Docu: drop a note why templates are not supported in keyword definitions
Franz Glasner <hg@dom66.de>
parents:
129
diff
changeset
|
75 no templating is supported here. This could lead to remote |
|
c3397e670063
Docu: drop a note why templates are not supported in keyword definitions
Franz Glasner <hg@dom66.de>
parents:
129
diff
changeset
|
76 code execution secnarios because Mercurial templates can execute |
|
c3397e670063
Docu: drop a note why templates are not supported in keyword definitions
Franz Glasner <hg@dom66.de>
parents:
129
diff
changeset
|
77 a big bunch of Python functions. |
|
c3397e670063
Docu: drop a note why templates are not supported in keyword definitions
Franz Glasner <hg@dom66.de>
parents:
129
diff
changeset
|
78 |
|
137
5e502e9dd5e5
As an example: put the |VCSRevision| into the extensions also and print it with the help output
Franz Glasner <hg@dom66.de>
parents:
136
diff
changeset
|
79 (rev |VCSRevision|) |
|
5e502e9dd5e5
As an example: put the |VCSRevision| into the extensions also and print it with the help output
Franz Glasner <hg@dom66.de>
parents:
136
diff
changeset
|
80 |
|
28
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
81 """ |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
82 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
83 from __future__ import absolute_import |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
84 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
85 |
|
336
eb1e0f129963
More compliance with the private style guide for Mercurial extensions for the metadata of the extensions
Franz Glasner <fzglas.hg@dom66.de>
parents:
332
diff
changeset
|
86 __revision__ = "|VCSRevision|" |
|
eb1e0f129963
More compliance with the private style guide for Mercurial extensions for the metadata of the extensions
Franz Glasner <fzglas.hg@dom66.de>
parents:
332
diff
changeset
|
87 __date__ = "|VCSJustDate|" |
|
28
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
88 __author__ = "Franz Glasner" |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
89 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
90 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
91 import os |
| 332 | 92 import inspect |
|
33
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
93 import itertools |
|
28
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
94 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
95 from mercurial.i18n import _ |
|
288
0080dab59fac
Begin tests with subrepos and some preparations for nested subrepos
Franz Glasner <hg@dom66.de>
parents:
287
diff
changeset
|
96 from mercurial import (archival, config, cmdutil, error, match, subrepo, |
|
300
56df37d7878e
Keywords HGlatesttags, HGlatesttagdistance, HGlatesttagdate and HGlatesttagjustdate
Franz Glasner <hg@dom66.de>
parents:
299
diff
changeset
|
97 pycompat, scmutil, templatefilters, templatekw, |
|
307
f8aa592b344e
FIX: Mercurial's "demandimport" defeats the "try: import ...; except ImportError" idiom; temporarily disable demandimport before doing such imports in kwarchive
Franz Glasner <hg@dom66.de>
parents:
304
diff
changeset
|
98 util, node, demandimport) |
|
326
26e617693ae8
FIX: kwarchive and revinfo do not run on versions prior to Mercurial 4.3 after testing this with unit-tests
Franz Glasner <fzglas.hg@dom66.de>
parents:
322
diff
changeset
|
99 with demandimport.deactivated(): |
|
307
f8aa592b344e
FIX: Mercurial's "demandimport" defeats the "try: import ...; except ImportError" idiom; temporarily disable demandimport before doing such imports in kwarchive
Franz Glasner <hg@dom66.de>
parents:
304
diff
changeset
|
100 try: |
|
f8aa592b344e
FIX: Mercurial's "demandimport" defeats the "try: import ...; except ImportError" idiom; temporarily disable demandimport before doing such imports in kwarchive
Franz Glasner <hg@dom66.de>
parents:
304
diff
changeset
|
101 from mercurial import registrar |
|
f8aa592b344e
FIX: Mercurial's "demandimport" defeats the "try: import ...; except ImportError" idiom; temporarily disable demandimport before doing such imports in kwarchive
Franz Glasner <hg@dom66.de>
parents:
304
diff
changeset
|
102 except ImportError: |
|
f8aa592b344e
FIX: Mercurial's "demandimport" defeats the "try: import ...; except ImportError" idiom; temporarily disable demandimport before doing such imports in kwarchive
Franz Glasner <hg@dom66.de>
parents:
304
diff
changeset
|
103 registrar = None |
|
f8aa592b344e
FIX: Mercurial's "demandimport" defeats the "try: import ...; except ImportError" idiom; temporarily disable demandimport before doing such imports in kwarchive
Franz Glasner <hg@dom66.de>
parents:
304
diff
changeset
|
104 # check for new template function API with `(context, mapping)` |
|
f8aa592b344e
FIX: Mercurial's "demandimport" defeats the "try: import ...; except ImportError" idiom; temporarily disable demandimport before doing such imports in kwarchive
Franz Glasner <hg@dom66.de>
parents:
304
diff
changeset
|
105 try: |
|
f8aa592b344e
FIX: Mercurial's "demandimport" defeats the "try: import ...; except ImportError" idiom; temporarily disable demandimport before doing such imports in kwarchive
Franz Glasner <hg@dom66.de>
parents:
304
diff
changeset
|
106 from mercurial import templatefuncs |
|
f8aa592b344e
FIX: Mercurial's "demandimport" defeats the "try: import ...; except ImportError" idiom; temporarily disable demandimport before doing such imports in kwarchive
Franz Glasner <hg@dom66.de>
parents:
304
diff
changeset
|
107 except ImportError: |
|
f8aa592b344e
FIX: Mercurial's "demandimport" defeats the "try: import ...; except ImportError" idiom; temporarily disable demandimport before doing such imports in kwarchive
Franz Glasner <hg@dom66.de>
parents:
304
diff
changeset
|
108 context_mapping_api = False |
|
f8aa592b344e
FIX: Mercurial's "demandimport" defeats the "try: import ...; except ImportError" idiom; temporarily disable demandimport before doing such imports in kwarchive
Franz Glasner <hg@dom66.de>
parents:
304
diff
changeset
|
109 else: |
|
f8aa592b344e
FIX: Mercurial's "demandimport" defeats the "try: import ...; except ImportError" idiom; temporarily disable demandimport before doing such imports in kwarchive
Franz Glasner <hg@dom66.de>
parents:
304
diff
changeset
|
110 # >= 4.6 |
|
f8aa592b344e
FIX: Mercurial's "demandimport" defeats the "try: import ...; except ImportError" idiom; temporarily disable demandimport before doing such imports in kwarchive
Franz Glasner <hg@dom66.de>
parents:
304
diff
changeset
|
111 context_mapping_api = True |
|
f8aa592b344e
FIX: Mercurial's "demandimport" defeats the "try: import ...; except ImportError" idiom; temporarily disable demandimport before doing such imports in kwarchive
Franz Glasner <hg@dom66.de>
parents:
304
diff
changeset
|
112 # some date specific util functions moved to new mercurial.utils.dateutil |
|
f8aa592b344e
FIX: Mercurial's "demandimport" defeats the "try: import ...; except ImportError" idiom; temporarily disable demandimport before doing such imports in kwarchive
Franz Glasner <hg@dom66.de>
parents:
304
diff
changeset
|
113 try: |
|
f8aa592b344e
FIX: Mercurial's "demandimport" defeats the "try: import ...; except ImportError" idiom; temporarily disable demandimport before doing such imports in kwarchive
Franz Glasner <hg@dom66.de>
parents:
304
diff
changeset
|
114 from mercurial.utils import dateutil as _dateutil |
|
f8aa592b344e
FIX: Mercurial's "demandimport" defeats the "try: import ...; except ImportError" idiom; temporarily disable demandimport before doing such imports in kwarchive
Franz Glasner <hg@dom66.de>
parents:
304
diff
changeset
|
115 except ImportError: |
|
f8aa592b344e
FIX: Mercurial's "demandimport" defeats the "try: import ...; except ImportError" idiom; temporarily disable demandimport before doing such imports in kwarchive
Franz Glasner <hg@dom66.de>
parents:
304
diff
changeset
|
116 _dateutil = util |
|
28
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
117 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
118 |
|
331
99b44c866f4f
Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
330
diff
changeset
|
119 testedwith = b"4.3.1 4.3.2 4.4.1 4.4.2 4.5.2 4.6.1 4.8.1 4.9 5.0.1" |
|
28
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
120 |
|
51
3807a60ee0dd
Shorten path urls by default when expanding keywords.
Franz Glasner <hg@dom66.de>
parents:
47
diff
changeset
|
121 SHORTENED_HG_SCHEMES = { |
|
331
99b44c866f4f
Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
330
diff
changeset
|
122 b"ssh": b"hg+ssh", |
|
99b44c866f4f
Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
330
diff
changeset
|
123 b"http": b"hg+http", |
|
99b44c866f4f
Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
330
diff
changeset
|
124 b"https": b"hg+https", |
|
99b44c866f4f
Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
330
diff
changeset
|
125 b"file": b"file", |
|
51
3807a60ee0dd
Shorten path urls by default when expanding keywords.
Franz Glasner <hg@dom66.de>
parents:
47
diff
changeset
|
126 } |
|
3807a60ee0dd
Shorten path urls by default when expanding keywords.
Franz Glasner <hg@dom66.de>
parents:
47
diff
changeset
|
127 |
|
331
99b44c866f4f
Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
330
diff
changeset
|
128 KWARCHIVE_CONFIG = b".hgkwarchive" |
|
156
d92850f876a4
Use a constant to define the ".hgkwarchive" name
Franz Glasner <hg@dom66.de>
parents:
155
diff
changeset
|
129 |
|
28
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
130 cmdtable = {} |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
131 |
|
326
26e617693ae8
FIX: kwarchive and revinfo do not run on versions prior to Mercurial 4.3 after testing this with unit-tests
Franz Glasner <fzglas.hg@dom66.de>
parents:
322
diff
changeset
|
132 if registrar and hasattr(registrar, "command"): |
|
248
436b2db75a34
cmdutil.command is deprecated: use registrar.command instead; also need always a repository for the commands: inferrepo=True
Franz Glasner <hg@dom66.de>
parents:
246
diff
changeset
|
133 command = registrar.command(cmdtable) |
|
436b2db75a34
cmdutil.command is deprecated: use registrar.command instead; also need always a repository for the commands: inferrepo=True
Franz Glasner <hg@dom66.de>
parents:
246
diff
changeset
|
134 else: |
|
436b2db75a34
cmdutil.command is deprecated: use registrar.command instead; also need always a repository for the commands: inferrepo=True
Franz Glasner <hg@dom66.de>
parents:
246
diff
changeset
|
135 command = cmdutil.command(cmdtable) |
|
28
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
136 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
137 |
|
150
f195b4704726
For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents:
147
diff
changeset
|
138 def getversion(): |
|
f195b4704726
For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents:
147
diff
changeset
|
139 """Provide the version information for verbose :hg:`version` output. |
|
f195b4704726
For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents:
147
diff
changeset
|
140 |
|
f195b4704726
For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents:
147
diff
changeset
|
141 Read the :file:`VERSION` from the parent of the :file:`extensions` |
|
f195b4704726
For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents:
147
diff
changeset
|
142 directory. |
|
f195b4704726
For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents:
147
diff
changeset
|
143 |
|
f195b4704726
For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents:
147
diff
changeset
|
144 """ |
|
f195b4704726
For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents:
147
diff
changeset
|
145 import re |
|
f195b4704726
For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents:
147
diff
changeset
|
146 import os |
|
f195b4704726
For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents:
147
diff
changeset
|
147 try: |
|
f195b4704726
For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents:
147
diff
changeset
|
148 fn = __file__ |
|
f195b4704726
For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents:
147
diff
changeset
|
149 except NameError: |
|
331
99b44c866f4f
Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
330
diff
changeset
|
150 return b"<unknown>" |
|
150
f195b4704726
For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents:
147
diff
changeset
|
151 else: |
|
f195b4704726
For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents:
147
diff
changeset
|
152 try: |
|
157
e12025e46375
Use util.posixfile when reading a custom given .hgkwarchive file for Mercurial portability reasons
Franz Glasner <hg@dom66.de>
parents:
156
diff
changeset
|
153 # this is pure Python standard functionality: no util.posixfile |
|
150
f195b4704726
For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents:
147
diff
changeset
|
154 verdata = open(os.path.join(os.path.dirname(fn), |
|
f195b4704726
For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents:
147
diff
changeset
|
155 "../VERSION"), |
|
331
99b44c866f4f
Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
330
diff
changeset
|
156 "rb").read() |
|
99b44c866f4f
Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
330
diff
changeset
|
157 return re.search(b"^(.*)", verdata,).group(1) |
|
150
f195b4704726
For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents:
147
diff
changeset
|
158 except OSError: |
|
331
99b44c866f4f
Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
330
diff
changeset
|
159 return b"<not found>" |
|
150
f195b4704726
For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents:
147
diff
changeset
|
160 |
|
f195b4704726
For each extension: provide a "getversion()" function that will be called by Mercurial to get the module version.
Franz Glasner <hg@dom66.de>
parents:
147
diff
changeset
|
161 |
|
114
a51822141ccf
Style: handled some more flake8 warnings: consistent command declaration list formatting
Franz Glasner <hg@dom66.de>
parents:
112
diff
changeset
|
162 @command( |
|
331
99b44c866f4f
Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
330
diff
changeset
|
163 b"kwarchive", |
|
114
a51822141ccf
Style: handled some more flake8 warnings: consistent command declaration list formatting
Franz Glasner <hg@dom66.de>
parents:
112
diff
changeset
|
164 [ |
|
331
99b44c866f4f
Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
330
diff
changeset
|
165 (b'', b"no-decode", None, _(b"do not pass files through decoders")), |
|
99b44c866f4f
Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
330
diff
changeset
|
166 (b'p', b"prefix", b'', _(b"directory prefix for files in archive"), _(b"PREFIX")), |
|
99b44c866f4f
Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
330
diff
changeset
|
167 (b'r', b"rev", b'', _(b"revision to distribute"), _(b"REV")), |
|
99b44c866f4f
Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
330
diff
changeset
|
168 (b't', b"type", b'', _(b"type of distribution to create"), _(b"TYPE")), |
|
99b44c866f4f
Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
330
diff
changeset
|
169 (b'', b"path", b"default", _(b"the canonical repository to use"), _(b"PATH")), |
|
99b44c866f4f
Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
330
diff
changeset
|
170 (b'', b"kwconfig", b'', _(b"an alternate pattern configuration configuration file (possibly used for subrepos also)"), _(b"PATTERNCONFIG")), |
|
99b44c866f4f
Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
330
diff
changeset
|
171 (b'', b"no-shorten-path", None, _(b"don't shorten the path urls")), |
|
99b44c866f4f
Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
330
diff
changeset
|
172 (b'', b"path-filter", b"short", _(b"determine how the path will be printed")), |
|
99b44c866f4f
Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
330
diff
changeset
|
173 (b'', b"user-filter", b"user", _(b"the part of the user to be printed"), _(b"USERFILTER")) |
|
28
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
174 ] + cmdutil.subrepoopts + cmdutil.walkopts, |
|
331
99b44c866f4f
Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
330
diff
changeset
|
175 _(b"[OPTION]... DEST"), |
|
248
436b2db75a34
cmdutil.command is deprecated: use registrar.command instead; also need always a repository for the commands: inferrepo=True
Franz Glasner <hg@dom66.de>
parents:
246
diff
changeset
|
176 inferrepo=True) |
|
28
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
177 def kwarchive(ui, repo, dest, **opts): |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
178 '''create an unversioned archive of a repository revision with some keywords expanded |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
179 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
180 By default, the revision used is the parent of the working |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
181 directory; use -r/--rev to specify a different revision. |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
182 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
183 The archive type is automatically detected based on file |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
184 extension (to override, use -t/--type). |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
185 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
186 .. container:: verbose |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
187 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
188 Examples: |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
189 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
190 - create a zip file containing the 1.0 release:: |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
191 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
192 hg archive -r 1.0 project-1.0.zip |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
193 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
194 - create a tarball excluding .hg files:: |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
195 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
196 hg archive project.tar.gz -X ".hg*" |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
197 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
198 Valid types are: |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
199 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
200 :``files``: a directory full of files (default) |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
201 :``tar``: tar archive, uncompressed |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
202 :``tbz2``: tar archive, compressed using bzip2 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
203 :``tgz``: tar archive, compressed using gzip |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
204 :``uzip``: zip archive, uncompressed |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
205 :``zip``: zip archive, compressed using deflate |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
206 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
207 The exact name of the destination archive or directory is given |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
208 using a format string; see :hg:`help export` for details. |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
209 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
210 Each member added to an archive file has a directory prefix |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
211 prepended. Use -p/--prefix to specify a format string for the |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
212 prefix. The default is the basename of the archive, with suffixes |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
213 removed. |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
214 |
| 41 | 215 Use --path to specify named path information from :hg:`paths` as |
| 216 the canonical repository location. Use ``.`` for the current | |
| 217 repository root root. If no path is given then ``default`` is | |
| 218 assumed. | |
|
35
f29c98e54f50
Implement a "--path" option for kwarchive to select a repository to use as canonical one
Franz Glasner <hg@dom66.de>
parents:
34
diff
changeset
|
219 |
|
51
3807a60ee0dd
Shorten path urls by default when expanding keywords.
Franz Glasner <hg@dom66.de>
parents:
47
diff
changeset
|
220 Full path URLs are printed somewhat shortened by default. To use |
|
3807a60ee0dd
Shorten path urls by default when expanding keywords.
Franz Glasner <hg@dom66.de>
parents:
47
diff
changeset
|
221 them as-is use the --no-shorten-path option. |
|
3807a60ee0dd
Shorten path urls by default when expanding keywords.
Franz Glasner <hg@dom66.de>
parents:
47
diff
changeset
|
222 |
|
65
bdb549d71148
Allow customization of the $Author$ output when expanding keywords.
Franz Glasner <hg@dom66.de>
parents:
64
diff
changeset
|
223 Allowed --user-filter values are: |
|
bdb549d71148
Allow customization of the $Author$ output when expanding keywords.
Franz Glasner <hg@dom66.de>
parents:
64
diff
changeset
|
224 |
|
bdb549d71148
Allow customization of the $Author$ output when expanding keywords.
Franz Glasner <hg@dom66.de>
parents:
64
diff
changeset
|
225 :``user``: the short representation of a user name or email address |
|
bdb549d71148
Allow customization of the $Author$ output when expanding keywords.
Franz Glasner <hg@dom66.de>
parents:
64
diff
changeset
|
226 :``person``: the name before an email address as per RFC 5322 |
|
bdb549d71148
Allow customization of the $Author$ output when expanding keywords.
Franz Glasner <hg@dom66.de>
parents:
64
diff
changeset
|
227 :``email``: the email address |
|
81
e02aceb91a9b
Make "full" a user filter and "none" an alias to "full"
Franz Glasner <hg@dom66.de>
parents:
80
diff
changeset
|
228 :``full``: the complete user information w/o filtering |
|
e02aceb91a9b
Make "full" a user filter and "none" an alias to "full"
Franz Glasner <hg@dom66.de>
parents:
80
diff
changeset
|
229 :``none``: an alias for ``full`` |
|
65
bdb549d71148
Allow customization of the $Author$ output when expanding keywords.
Franz Glasner <hg@dom66.de>
parents:
64
diff
changeset
|
230 |
|
93
fa84debfb50e
Replace "no-shorten-url" by "path-filter"
Franz Glasner <hg@dom66.de>
parents:
92
diff
changeset
|
231 The --path-filter values detemine how the path will be printed: |
|
fa84debfb50e
Replace "no-shorten-url" by "path-filter"
Franz Glasner <hg@dom66.de>
parents:
92
diff
changeset
|
232 |
|
fa84debfb50e
Replace "no-shorten-url" by "path-filter"
Franz Glasner <hg@dom66.de>
parents:
92
diff
changeset
|
233 :``full``: the path will be printed as is (including passwords et al.) |
|
fa84debfb50e
Replace "no-shorten-url" by "path-filter"
Franz Glasner <hg@dom66.de>
parents:
92
diff
changeset
|
234 :``nopwd``: like ``full`` but without passwords |
|
249
e97f6f6ed7c5
Implement a "nouser" option for the path-filter: like no-pwd but without user information also
Franz Glasner <hg@dom66.de>
parents:
248
diff
changeset
|
235 :``nouser``: like ``full`` but without user and password information |
| 101 | 236 :``short``: shorten the path somehow: no user/password information and |
|
93
fa84debfb50e
Replace "no-shorten-url" by "path-filter"
Franz Glasner <hg@dom66.de>
parents:
92
diff
changeset
|
237 only a short server name |
|
100
eed73af1ab79
Implemented a "last" option for the "--path-filter": shorten to the last path component.
Franz Glasner <hg@dom66.de>
parents:
99
diff
changeset
|
238 :``last``: shorten the path to the last component |
|
342
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
239 :``repo``: the repository id will be used as path |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
240 :``reposhort``: the shortened repository id will be used as path |
|
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 | 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 | 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 |
|
342
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
341 :``repo``: the repository id will be used as path |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
342 :``reposhort``: the shortened repository id will be used as path |
|
93
fa84debfb50e
Replace "no-shorten-url" by "path-filter"
Franz Glasner <hg@dom66.de>
parents:
92
diff
changeset
|
343 |
|
78
743dd4a77b4a
Implemented a "--reST" option for printing reST substitution definitions from keywords
Franz Glasner <hg@dom66.de>
parents:
76
diff
changeset
|
344 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
|
345 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
|
346 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
|
347 |
|
109
be4811239acf
kwprint: print example file-dependent keywords also.
Franz Glasner <hg@dom66.de>
parents:
108
diff
changeset
|
348 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
|
349 example file. |
|
be4811239acf
kwprint: print example file-dependent keywords also.
Franz Glasner <hg@dom66.de>
parents:
108
diff
changeset
|
350 |
|
45
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
351 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
|
352 |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
353 ''' |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
354 |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
355 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
|
356 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
|
357 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
|
358 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
|
359 node = ctx.node() |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
360 |
|
331
99b44c866f4f
Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
330
diff
changeset
|
361 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
|
362 |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
363 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
|
364 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
|
365 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
|
366 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
|
367 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
|
368 # 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
|
369 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
|
370 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
|
371 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
|
372 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
|
373 b"a4dd6f4b22e11fec41158eec187630c24a43120a") |
|
294
2eb443e77cff
Refactor: put the real keyword printing into a separate function.
Franz Glasner <hg@dom66.de>
parents:
293
diff
changeset
|
374 else: |
|
2eb443e77cff
Refactor: put the real keyword printing into a separate function.
Franz Glasner <hg@dom66.de>
parents:
293
diff
changeset
|
375 file_keywords = None |
|
2eb443e77cff
Refactor: put the real keyword printing into a separate function.
Franz Glasner <hg@dom66.de>
parents:
293
diff
changeset
|
376 _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
|
377 opts.get(b"reST"), |
|
99b44c866f4f
Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
330
diff
changeset
|
378 opts.get(b"no_file")) |
|
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 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
|
380 _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
|
381 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
|
382 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
|
383 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
|
384 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
|
385 |
|
2eb443e77cff
Refactor: put the real keyword printing into a separate function.
Franz Glasner <hg@dom66.de>
parents:
293
diff
changeset
|
386 |
|
2eb443e77cff
Refactor: put the real keyword printing into a separate function.
Franz Glasner <hg@dom66.de>
parents:
293
diff
changeset
|
387 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
|
388 """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
|
389 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
|
390 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
|
391 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
|
392 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
|
393 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
|
394 # |
|
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 # 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
|
396 # 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
|
397 # |
|
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".. |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
|
399 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
|
400 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
|
401 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
|
402 ui.write(b"\n") |
|
109
be4811239acf
kwprint: print example file-dependent keywords also.
Franz Glasner <hg@dom66.de>
parents:
108
diff
changeset
|
403 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
|
404 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
|
405 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
|
406 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
|
407 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
|
408 |
|
31d5d77c297d
Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents:
290
diff
changeset
|
409 |
|
294
2eb443e77cff
Refactor: put the real keyword printing into a separate function.
Franz Glasner <hg@dom66.de>
parents:
293
diff
changeset
|
410 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
|
411 """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
|
412 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
|
413 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
|
414 # 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
|
415 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
|
416 continue |
|
291
31d5d77c297d
Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents:
290
diff
changeset
|
417 subrep = ctx.workingsub(subpath) |
|
31d5d77c297d
Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents:
290
diff
changeset
|
418 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
|
419 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
|
420 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
|
421 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
|
422 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
|
423 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
|
424 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
|
425 if not no_file: |
|
330
793161e48af2
FIX: Remove duplicate assignment to file_keywords
Franz Glasner <fzglas.hg@dom66.de>
parents:
328
diff
changeset
|
426 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
|
427 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
|
428 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
|
429 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
|
430 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
|
431 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
|
432 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
|
433 _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
|
434 # 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
|
435 _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
|
436 |
|
31d5d77c297d
Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents:
290
diff
changeset
|
437 |
|
31d5d77c297d
Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents:
290
diff
changeset
|
438 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
|
439 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
|
440 for subpath in sorted(ctx.substate): |
|
31d5d77c297d
Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents:
290
diff
changeset
|
441 ui.write("SUBPATH: " + subpath + "\n"); |
|
31d5d77c297d
Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents:
290
diff
changeset
|
442 subrep = ctx.workingsub(subpath) |
|
31d5d77c297d
Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents:
290
diff
changeset
|
443 ui.write(repr(subrep) + ": subrelpath=" + subrepo.subrelpath(subrep) |
|
31d5d77c297d
Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents:
290
diff
changeset
|
444 + " reporelpath=" + subrepo.reporelpath(subrep._repo) |
|
31d5d77c297d
Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents:
290
diff
changeset
|
445 + '\n') |
|
31d5d77c297d
Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents:
290
diff
changeset
|
446 # Yes(!) |
|
31d5d77c297d
Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents:
290
diff
changeset
|
447 assert subrepo.subrelpath(subrep) == subrepo.reporelpath(subrep._repo) |
|
31d5d77c297d
Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents:
290
diff
changeset
|
448 assert subrepo.subrelpath(subrep).endswith(subpath) |
|
31d5d77c297d
Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents:
290
diff
changeset
|
449 ui.write(" " + repr(subrep._getctx()) + '\n') |
|
31d5d77c297d
Begin real keyword expansion for subrepos
Franz Glasner <hg@dom66.de>
parents:
290
diff
changeset
|
450 _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
|
451 |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
452 |
|
33
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
453 def patch_archiver_class(archivername, filter): |
|
32
cfa53f8a6607
Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents:
31
diff
changeset
|
454 """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
|
455 |
|
cfa53f8a6607
Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents:
31
diff
changeset
|
456 archiver_class = getattr(archival, archivername) |
|
cfa53f8a6607
Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents:
31
diff
changeset
|
457 orig_addfile = getattr(archiver_class, "addfile") |
|
cfa53f8a6607
Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents:
31
diff
changeset
|
458 |
|
287
95c207d21bbf
FIX: Typo in argument: "isline" -> "islink"
Franz Glasner <hg@dom66.de>
parents:
255
diff
changeset
|
459 def new_addfile(self, name, mode, islink, data): |
|
95c207d21bbf
FIX: Typo in argument: "isline" -> "islink"
Franz Glasner <hg@dom66.de>
parents:
255
diff
changeset
|
460 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
|
461 |
|
cfa53f8a6607
Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents:
31
diff
changeset
|
462 setattr(archiver_class, "addfile", new_addfile) |
|
cfa53f8a6607
Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents:
31
diff
changeset
|
463 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
|
464 |
|
28
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
465 |
|
293
75070825d111
- make_node_keywords() and make_keyword_filter() do not need a "repo" argument.
Franz Glasner <hg@dom66.de>
parents:
292
diff
changeset
|
466 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
|
467 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
|
468 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
|
469 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
|
470 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
|
471 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
|
472 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
|
473 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
|
474 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
|
475 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
|
476 } |
|
298
aa945541d2ca
kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents:
296
diff
changeset
|
477 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
|
478 _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
|
479 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
|
480 kwconfig, |
|
aa945541d2ca
kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents:
296
diff
changeset
|
481 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
|
482 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
|
483 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
|
484 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
|
485 |
|
15d23729d176
Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents:
295
diff
changeset
|
486 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
|
487 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
|
488 if archive_class != "fileit": |
|
15d23729d176
Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents:
295
diff
changeset
|
489 if prefix: |
|
15d23729d176
Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents:
295
diff
changeset
|
490 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
|
491 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
|
492 # 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
|
493 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
|
494 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
|
495 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
|
496 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
|
497 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
|
498 else: |
|
aa945541d2ca
kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents:
296
diff
changeset
|
499 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
|
500 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
|
501 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
|
502 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
|
503 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
|
504 |
|
aa945541d2ca
kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents:
296
diff
changeset
|
505 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
|
506 #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
|
507 return data |
|
15d23729d176
Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents:
295
diff
changeset
|
508 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
|
509 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
|
510 except LookupError: |
|
15d23729d176
Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents:
295
diff
changeset
|
511 nodeid = None |
|
15d23729d176
Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents:
295
diff
changeset
|
512 # 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
|
513 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
|
514 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
|
515 _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
|
516 _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
|
517 # 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
|
518 _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
|
519 _MARKER_RST = b'|' |
|
296
15d23729d176
Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents:
295
diff
changeset
|
520 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
|
521 # |
|
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
|
522 # 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
|
523 # 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
|
524 # |
|
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
|
525 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
|
526 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
|
527 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
|
528 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
|
529 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
|
530 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
|
531 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
|
532 # 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
|
533 _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
|
534 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
|
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 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
|
537 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
|
538 # 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
|
539 kwds = [] |
|
296
15d23729d176
Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents:
295
diff
changeset
|
540 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
|
541 # 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
|
542 kwds = [kw] |
|
15d23729d176
Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents:
295
diff
changeset
|
543 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
|
544 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
|
545 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
|
546 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
|
547 % (_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
|
548 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
|
549 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
|
550 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
|
551 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
|
552 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
|
553 return data |
|
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 return _filter |
|
15d23729d176
Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents:
295
diff
changeset
|
556 |
|
15d23729d176
Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents:
295
diff
changeset
|
557 |
|
15d23729d176
Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents:
295
diff
changeset
|
558 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
|
559 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
|
560 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
|
561 hgpath=hgpath, |
|
93
fa84debfb50e
Replace "no-shorten-url" by "path-filter"
Franz Glasner <hg@dom66.de>
parents:
92
diff
changeset
|
562 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
|
563 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
|
564 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
|
565 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
|
566 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
|
567 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
|
568 kwconfigname = kwconfig |
|
33
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
569 try: |
|
47
94ae433383a2
Allow an alternate patterns file (instead of .hgkwarchive) with the --kwconfig option.
Franz Glasner <hg@dom66.de>
parents:
46
diff
changeset
|
570 if kwconfigdata is None: |
|
156
d92850f876a4
Use a constant to define the ".hgkwarchive" name
Franz Glasner <hg@dom66.de>
parents:
155
diff
changeset
|
571 # use versioned .hgkwarchive |
|
d92850f876a4
Use a constant to define the ".hgkwarchive" name
Franz Glasner <hg@dom66.de>
parents:
155
diff
changeset
|
572 kwconfigdata = ctx[KWARCHIVE_CONFIG].data() |
|
d92850f876a4
Use a constant to define the ".hgkwarchive" name
Franz Glasner <hg@dom66.de>
parents:
155
diff
changeset
|
573 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
|
574 except (IOError, LookupError): |
|
296
15d23729d176
Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents:
295
diff
changeset
|
575 # 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
|
576 return None |
|
33
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
577 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
|
578 # |
|
71b321436cc1
Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents:
42
diff
changeset
|
579 # 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
|
580 # 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
|
581 # |
|
33
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
582 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
|
583 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
|
584 include = [] |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
585 exclude = [] |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
586 patterns = [] |
|
118
e9c78a0bfe6a
Allow multiple style keyword expansion in one file.
Franz Glasner <hg@dom66.de>
parents:
116
diff
changeset
|
587 patterns_rcs = [] |
|
79
53c9f2f6a13e
Work in reST style keywords in kwarchive
Franz Glasner <hg@dom66.de>
parents:
78
diff
changeset
|
588 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
|
589 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
|
590 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
|
591 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
|
592 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
|
593 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
|
594 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
|
595 exclude.append(pattern) |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
596 else: |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
597 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
|
598 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
|
599 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
|
600 if b"RCS" in styles: |
|
118
e9c78a0bfe6a
Allow multiple style keyword expansion in one file.
Franz Glasner <hg@dom66.de>
parents:
116
diff
changeset
|
601 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
|
602 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
|
603 patterns_rst.append(pattern) |
|
e9c78a0bfe6a
Allow multiple style keyword expansion in one file.
Franz Glasner <hg@dom66.de>
parents:
116
diff
changeset
|
604 else: |
|
e9c78a0bfe6a
Allow multiple style keyword expansion in one file.
Franz Glasner <hg@dom66.de>
parents:
116
diff
changeset
|
605 # 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
|
606 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
|
607 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
|
608 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
|
609 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
|
610 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
|
611 |
|
e9c78a0bfe6a
Allow multiple style keyword expansion in one file.
Franz Glasner <hg@dom66.de>
parents:
116
diff
changeset
|
612 # |
|
e9c78a0bfe6a
Allow multiple style keyword expansion in one file.
Franz Glasner <hg@dom66.de>
parents:
116
diff
changeset
|
613 # 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
|
614 # true. |
|
e9c78a0bfe6a
Allow multiple style keyword expansion in one file.
Franz Glasner <hg@dom66.de>
parents:
116
diff
changeset
|
615 # |
|
e9c78a0bfe6a
Allow multiple style keyword expansion in one file.
Franz Glasner <hg@dom66.de>
parents:
116
diff
changeset
|
616 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
|
617 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
|
618 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
|
619 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
|
620 patterns=patterns_rcs, |
|
118
e9c78a0bfe6a
Allow multiple style keyword expansion in one file.
Franz Glasner <hg@dom66.de>
parents:
116
diff
changeset
|
621 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
|
622 # |
|
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 # 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
|
624 # 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
|
625 # |
|
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 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
|
627 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
|
628 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
|
629 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
|
630 patterns=patterns_rst, |
|
79
53c9f2f6a13e
Work in reST style keywords in kwarchive
Franz Glasner <hg@dom66.de>
parents:
78
diff
changeset
|
631 include=[], exclude=[]) |
|
33
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
632 |
|
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
|
633 # |
|
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
|
634 # 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
|
635 # 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
|
636 # 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
|
637 # 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
|
638 # expansion. |
|
133
8d16138e00af
Implemented substitution type keyword expansion
Franz Glasner <hg@dom66.de>
parents:
131
diff
changeset
|
639 # |
|
8d16138e00af
Implemented substitution type keyword expansion
Franz Glasner <hg@dom66.de>
parents:
131
diff
changeset
|
640 keyword_substitutions = {} |
|
8d16138e00af
Implemented substitution type keyword expansion
Franz Glasner <hg@dom66.de>
parents:
131
diff
changeset
|
641 |
|
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
|
642 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
|
643 keyword_substitutions[alias] = value |
|
122
e6037655967b
Implemented a keyword white-list including aliases.
Franz Glasner <hg@dom66.de>
parents:
120
diff
changeset
|
644 |
|
e6037655967b
Implemented a keyword white-list including aliases.
Franz Glasner <hg@dom66.de>
parents:
120
diff
changeset
|
645 # |
|
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
|
646 # 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
|
647 # |
|
65789e3e8e3d
Provide a "HGnodeid" per file keyword that expands to the NodeID of the artifact.
Franz Glasner <hg@dom66.de>
parents:
103
diff
changeset
|
648 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
|
649 |
|
296
15d23729d176
Generate the real filter configuration data in an independent function.
Franz Glasner <hg@dom66.de>
parents:
295
diff
changeset
|
650 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
|
651 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
|
652 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
|
653 |
|
71b321436cc1
Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents:
42
diff
changeset
|
654 |
|
298
aa945541d2ca
kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents:
296
diff
changeset
|
655 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
|
656 ui, |
|
aa945541d2ca
kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents:
296
diff
changeset
|
657 ctx, |
|
aa945541d2ca
kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents:
296
diff
changeset
|
658 kwconfig, |
|
aa945541d2ca
kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents:
296
diff
changeset
|
659 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
|
660 |
|
aa945541d2ca
kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents:
296
diff
changeset
|
661 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
|
662 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
|
663 # 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
|
664 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
|
665 continue |
|
aa945541d2ca
kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents:
296
diff
changeset
|
666 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
|
667 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
|
668 |
|
aa945541d2ca
kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents:
296
diff
changeset
|
669 # 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
|
670 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
|
671 _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
|
672 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
|
673 |
|
aa945541d2ca
kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents:
296
diff
changeset
|
674 # 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
|
675 _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
|
676 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
|
677 kwconfig, |
|
aa945541d2ca
kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents:
296
diff
changeset
|
678 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
|
679 |
|
aa945541d2ca
kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents:
296
diff
changeset
|
680 |
|
293
75070825d111
- make_node_keywords() and make_keyword_filter() do not need a "repo" argument.
Franz Glasner <hg@dom66.de>
parents:
292
diff
changeset
|
681 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
|
682 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
|
683 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
|
684 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
|
685 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
|
686 """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
|
687 |
|
71b321436cc1
Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents:
42
diff
changeset
|
688 """ |
|
342
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
689 if path_filter == b"repo": |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
690 path_uri = b"repo:" + ctx.repo()[ctx.repo().lookup(b'0')].hex() |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
691 elif path_filter == b"reposhort": |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
692 path_uri = b"repo:" + templatefilters.short( |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
693 ctx.repo()[ctx.repo().lookup(b'0')].hex()) |
|
44
71b321436cc1
Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents:
42
diff
changeset
|
694 else: |
|
342
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
695 if (hglocation is not None) and hgpath: |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
696 raise ValueError("either `hgpath' or `hglocation` can be set") |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
697 if (hglocation is not None) or (hgpath and hgpath != b"."): |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
698 if hglocation is None: |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
699 hglocation = ui.paths[hgpath].loc |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
700 try: |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
701 if path_filter == b"full": |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
702 path_uri = bytes(util.url(hglocation)) |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
703 elif path_filter == b"nopwd": |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
704 path_uri = util.hidepassword(hglocation) |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
705 elif path_filter == b"nouser": |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
706 path_url = util.url(hglocation) |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
707 path_url.user = None |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
708 path_url.passwd = None |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
709 path_uri = bytes(path_url) |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
710 elif path_filter == b"short": |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
711 path_url = util.url(hglocation) |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
712 path_url.scheme = SHORTENED_HG_SCHEMES.get(path_url.scheme, |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
713 b"hg") |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
714 path_url.user = None |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
715 path_url.passwd = None |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
716 path_url.host = stripped_hostname(path_url.host) |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
717 path_url.port = None |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
718 path_uri = bytes(path_url) |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
719 elif path_filter == b"last": |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
720 path_url = str(util.url(hglocation)).split('/') |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
721 path_uri = pycompat.sysbytes(".../"+path_url[-1]) |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
722 else: |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
723 raise error.Abort(b"path-filter `%s' not implemented" |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
724 % path_filter) |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
725 except LookupError: |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
726 raise error.Abort( |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
727 _(b"remote repository named `%s' not found") % hgpath) |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
728 else: |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
729 path_uri = ctx.repo().root |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
730 if path_filter == b"last": |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
731 m = max(path_uri.rfind(b"/"), path_uri.rfind(b"\\")) |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
732 if m >= 0: |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
733 path_uri = b".../" + path_uri[m+1:] |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
734 if path_uri.startswith(b"\\\\"): |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
735 # Make an URL from a Windows UNC path |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
736 path_uri = b"file:///" + path_uri.replace(b'\\', b'/') |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
737 elif len(path_uri) >= 2 \ |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
738 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')))) \ |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
739 and path_uri[1] == b':': |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
740 # make an URL from a Windows path with drive letter |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
741 path_uri = b"file:///" + path_uri.replace(b'\\', b'/') |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
742 elif path_uri.startswith(b'/'): |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
743 # an absolute POSIX path |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
744 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
|
745 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
|
746 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
|
747 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
|
748 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
|
749 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
|
750 } |
|
71288cb43ba9
kwarchive: Make it work with Mercurial 4.6+ (really tested on 4.8.1).
Franz Glasner <hg@dom66.de>
parents:
300
diff
changeset
|
751 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
|
752 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
|
753 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
|
754 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
|
755 b"HGrepoid": ctx.repo()[ctx.repo().lookup(b'0')].hex(), # repo id |
|
338
038cca685729
Add a short representation of the repo id with name "HGshortrepoid"
Franz Glasner <hg@dom66.de>
parents:
337
diff
changeset
|
756 b"HGshortrepoid": templatefilters.short(ctx.repo()[ctx.repo().lookup(b'0')].hex()), # short form of the repo id |
|
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
|
757 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
|
758 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
|
759 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
|
760 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
|
761 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
|
762 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
|
763 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
|
764 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
|
765 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
|
766 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
|
767 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
|
768 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
|
769 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
|
770 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
|
771 # 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
|
772 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
|
773 } |
|
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
|
774 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
|
775 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
|
776 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
|
777 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
|
778 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
|
779 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
|
780 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
|
781 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
|
782 # |
|
e02aceb91a9b
Make "full" a user filter and "none" an alias to "full"
Franz Glasner <hg@dom66.de>
parents:
80
diff
changeset
|
783 # "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
|
784 # alias for "full". |
|
e02aceb91a9b
Make "full" a user filter and "none" an alias to "full"
Franz Glasner <hg@dom66.de>
parents:
80
diff
changeset
|
785 # 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
|
786 # |
|
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
|
787 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
|
788 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
|
789 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
|
790 |
|
44
71b321436cc1
Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents:
42
diff
changeset
|
791 return keywords |
|
51
3807a60ee0dd
Shorten path urls by default when expanding keywords.
Franz Glasner <hg@dom66.de>
parents:
47
diff
changeset
|
792 |
|
3807a60ee0dd
Shorten path urls by default when expanding keywords.
Franz Glasner <hg@dom66.de>
parents:
47
diff
changeset
|
793 |
|
298
aa945541d2ca
kwarchive: fully implements recursing into Mercurial subrepos and do keyword expansion there also
Franz Glasner <hg@dom66.de>
parents:
296
diff
changeset
|
794 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
|
795 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
|
796 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
|
797 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
|
798 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
|
799 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
|
800 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
|
801 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
|
802 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
|
803 b"HGnodeid": nodeid or b'', |
|
109
be4811239acf
kwprint: print example file-dependent keywords also.
Franz Glasner <hg@dom66.de>
parents:
108
diff
changeset
|
804 } |
|
be4811239acf
kwprint: print example file-dependent keywords also.
Franz Glasner <hg@dom66.de>
parents:
108
diff
changeset
|
805 |
|
be4811239acf
kwprint: print example file-dependent keywords also.
Franz Glasner <hg@dom66.de>
parents:
108
diff
changeset
|
806 |
|
51
3807a60ee0dd
Shorten path urls by default when expanding keywords.
Franz Glasner <hg@dom66.de>
parents:
47
diff
changeset
|
807 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
|
808 """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
|
809 if not hostname: |
|
3807a60ee0dd
Shorten path urls by default when expanding keywords.
Franz Glasner <hg@dom66.de>
parents:
47
diff
changeset
|
810 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
|
811 idx = hostname.find(b'.') |
|
51
3807a60ee0dd
Shorten path urls by default when expanding keywords.
Franz Glasner <hg@dom66.de>
parents:
47
diff
changeset
|
812 if idx < 0: |
|
3807a60ee0dd
Shorten path urls by default when expanding keywords.
Franz Glasner <hg@dom66.de>
parents:
47
diff
changeset
|
813 return hostname |
|
3807a60ee0dd
Shorten path urls by default when expanding keywords.
Franz Glasner <hg@dom66.de>
parents:
47
diff
changeset
|
814 return hostname[:idx] |
|
65
bdb549d71148
Allow customization of the $Author$ output when expanding keywords.
Franz Glasner <hg@dom66.de>
parents:
64
diff
changeset
|
815 |
|
bdb549d71148
Allow customization of the $Author$ output when expanding keywords.
Franz Glasner <hg@dom66.de>
parents:
64
diff
changeset
|
816 |
|
136
f470702886b4
Renamed some internal functions to provide a more descriptive name
Franz Glasner <hg@dom66.de>
parents:
134
diff
changeset
|
817 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
|
818 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
|
819 # "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
|
820 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
|
821 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
|
822 _(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
|
823 return uf |
|
93
fa84debfb50e
Replace "no-shorten-url" by "path-filter"
Franz Glasner <hg@dom66.de>
parents:
92
diff
changeset
|
824 |
|
fa84debfb50e
Replace "no-shorten-url" by "path-filter"
Franz Glasner <hg@dom66.de>
parents:
92
diff
changeset
|
825 |
|
136
f470702886b4
Renamed some internal functions to provide a more descriptive name
Franz Glasner <hg@dom66.de>
parents:
134
diff
changeset
|
826 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
|
827 pf = opts.get(b"path_filter") |
|
342
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
828 if pf not in (b"full", b"nopwd", b"nouser", b"short", b"last", |
|
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
829 b"repo", b"reposhort"): |
|
114
a51822141ccf
Style: handled some more flake8 warnings: consistent command declaration list formatting
Franz Glasner <hg@dom66.de>
parents:
112
diff
changeset
|
830 raise error.Abort( |
|
342
a69c89c18546
Implemented the "repo" and "reposhort" path filter variants to print the (shortened) repository id instead of the repository path
Franz Glasner <fzglas.hg@dom66.de>
parents:
338
diff
changeset
|
831 _(b"path filter must be any of `full', `nopwd', `nouser`, `short', `last', `repo' or `reposhort'")) |
|
93
fa84debfb50e
Replace "no-shorten-url" by "path-filter"
Franz Glasner <hg@dom66.de>
parents:
92
diff
changeset
|
832 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
|
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 |
|
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
|
835 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
|
836 # 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
|
837 _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
|
838 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
|
839 _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
|
840 |
|
99b44c866f4f
Ported the kwarchive extension to Python3 and tested with Mercurial 5.0.1
Franz Glasner <fzglas.hg@dom66.de>
parents:
330
diff
changeset
|
841 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
|
842 |
|
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 # 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
|
844 |
|
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 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
|
846 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
|
847 |
|
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
|
848 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
|
849 |
|
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
|
850 # 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
|
851 |
|
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
|
852 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
|
853 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
|
854 |
|
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
|
855 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
|
856 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
|
857 |
|
71288cb43ba9
kwarchive: Make it work with Mercurial 4.6+ (really tested on 4.8.1).
Franz Glasner <hg@dom66.de>
parents:
300
diff
changeset
|
858 |
|
71288cb43ba9
kwarchive: Make it work with Mercurial 4.6+ (really tested on 4.8.1).
Franz Glasner <hg@dom66.de>
parents:
300
diff
changeset
|
859 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
|
860 |
|
71288cb43ba9
kwarchive: Make it work with Mercurial 4.6+ (really tested on 4.8.1).
Franz Glasner <hg@dom66.de>
parents:
300
diff
changeset
|
861 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
|
862 |
|
71288cb43ba9
kwarchive: Make it work with Mercurial 4.6+ (really tested on 4.8.1).
Franz Glasner <hg@dom66.de>
parents:
300
diff
changeset
|
863 @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
|
864 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
|
865 return mapping[name] |
