Mercurial > hgrepos > DevTools > mercurial-extensions
annotate extensions/kwarchive.py @ 47:94ae433383a2
Allow an alternate patterns file (instead of .hgkwarchive) with the --kwconfig option.
ADD: A VERSION file with the logical version and the revision info.
| author | Franz Glasner <hg@dom66.de> |
|---|---|
| date | Wed, 15 Nov 2017 09:30:36 +0100 |
| parents | 4a0c26dfef3c |
| children | 3807a60ee0dd |
| 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 -*- |
|
34
7c4addd60935
Put keyword into the extensions itself
Franz Glasner <hg@dom66.de>
parents:
33
diff
changeset
|
2 # $HGheader$ |
|
7c4addd60935
Put keyword into the extensions itself
Franz Glasner <hg@dom66.de>
parents:
33
diff
changeset
|
3 # |
|
28
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
4 """archive with keyword expansion into selected files |
|
33
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
5 |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
6 The patterns of files to to expanded are configured in an versioned |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
7 ``.hgkwarchive`` configuration file found in the root of the working |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
8 directory. |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
9 |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
10 The ``.hgkwarchive`` file uses the same syntax as all other Mercurial |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
11 configuration files. |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
12 |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
13 The ``[patterns]`` section specifies which files should have the keywords |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
14 expanded. |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
15 |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
16 |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
17 Example:: |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
18 |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
19 [patterns] |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
20 # expand keywords in every python file except those matching "x*" |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
21 **.py = |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
22 x* = NO |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
23 |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
24 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
|
25 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
|
26 |
|
28
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
27 """ |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
28 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
29 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
|
30 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
31 |
|
42
b46ab29aefd8
Remove the "__version__" variable: use "__revision__" only instead
Franz Glasner <hg@dom66.de>
parents:
41
diff
changeset
|
32 __revision__ = "$Revision$" |
|
28
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
33 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
34 __author__ = "Franz Glasner" |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
35 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
36 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
37 import os |
|
33
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
38 import itertools |
|
28
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
39 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
40 from mercurial.i18n import _ |
|
33
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
41 from mercurial import (archival, commands, config, cmdutil, error, match, |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
42 pycompat, scmutil, templatefilters, util) |
|
28
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
43 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
44 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
45 testedwith = "4.3.2" |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
46 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
47 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
48 cmdtable = {} |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
49 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
50 command = cmdutil.command(cmdtable) |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
51 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
52 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
53 @command('kwarchive', |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
54 [('', 'no-decode', None, _('do not pass files through decoders')), |
|
47
94ae433383a2
Allow an alternate patterns file (instead of .hgkwarchive) with the --kwconfig option.
Franz Glasner <hg@dom66.de>
parents:
46
diff
changeset
|
55 ('p', 'prefix', '', _('directory prefix for files in archive'), |
|
28
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
56 _('PREFIX')), |
|
47
94ae433383a2
Allow an alternate patterns file (instead of .hgkwarchive) with the --kwconfig option.
Franz Glasner <hg@dom66.de>
parents:
46
diff
changeset
|
57 ('r', 'rev', '', _('revision to distribute'), _('REV')), |
|
94ae433383a2
Allow an alternate patterns file (instead of .hgkwarchive) with the --kwconfig option.
Franz Glasner <hg@dom66.de>
parents:
46
diff
changeset
|
58 ('t', 'type', '', _('type of distribution to create'), _('TYPE')), |
|
94ae433383a2
Allow an alternate patterns file (instead of .hgkwarchive) with the --kwconfig option.
Franz Glasner <hg@dom66.de>
parents:
46
diff
changeset
|
59 ('', 'path', 'default', _('the canonical repository to use'), _('PATH')), |
|
94ae433383a2
Allow an alternate patterns file (instead of .hgkwarchive) with the --kwconfig option.
Franz Glasner <hg@dom66.de>
parents:
46
diff
changeset
|
60 ('', "kwconfig", '', _('an alternate pattern configuration configuration file'), _('PATTERNCONFIG')), |
|
28
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
61 ] + cmdutil.subrepoopts + cmdutil.walkopts, |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
62 _('[OPTION]... DEST')) |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
63 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
|
64 '''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
|
65 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
66 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
|
67 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
|
68 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
69 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
|
70 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
|
71 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
72 .. container:: verbose |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
73 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
74 Examples: |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
75 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
76 - 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
|
77 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
78 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
|
79 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
80 - 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
|
81 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
82 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
|
83 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
84 Valid types are: |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
85 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
86 :``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
|
87 :``tar``: tar archive, uncompressed |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
88 :``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
|
89 :``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
|
90 :``uzip``: zip archive, uncompressed |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
91 :``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
|
92 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
93 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
|
94 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
|
95 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
96 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
|
97 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
|
98 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
|
99 removed. |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
100 |
| 41 | 101 Use --path to specify named path information from :hg:`paths` as |
| 102 the canonical repository location. Use ``.`` for the current | |
| 103 repository root root. If no path is given then ``default`` is | |
| 104 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
|
105 |
|
28
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
106 Returns 0 on success. |
| 41 | 107 |
|
28
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
108 ''' |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
109 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
110 opts = pycompat.byteskwargs(opts) |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
111 ctx = scmutil.revsingle(repo, opts.get('rev')) |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
112 if not ctx: |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
113 raise error.Abort(_('no working directory: please specify a revision')) |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
114 node = ctx.node() |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
115 dest = cmdutil.makefilename(repo, dest, node) |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
116 if os.path.realpath(dest) == repo.root: |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
117 raise error.Abort(_('repository root cannot be destination')) |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
118 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
119 kind = opts.get('type') or archival.guesskind(dest) or 'files' |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
120 prefix = opts.get('prefix') |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
121 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
122 if dest == '-': |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
123 if kind == 'files': |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
124 raise error.Abort(_('cannot archive plain files to stdout')) |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
125 dest = cmdutil.makefileobj(repo, dest) |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
126 if not prefix: |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
127 prefix = os.path.basename(repo.root) + '-%h' |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
128 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
129 prefix = cmdutil.makefilename(repo, prefix, node) |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
130 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
|
131 |
|
58f47399691c
New successful PoC: monkey-patch all relevant archiver's "addfile()" method
Franz Glasner <hg@dom66.de>
parents:
28
diff
changeset
|
132 # |
|
31
0597395e2d18
Comment: better explanation of what is monkey-patched
Franz Glasner <hg@dom66.de>
parents:
30
diff
changeset
|
133 # 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
|
134 # expands keywords |
|
58f47399691c
New successful PoC: monkey-patch all relevant archiver's "addfile()" method
Franz Glasner <hg@dom66.de>
parents:
28
diff
changeset
|
135 # |
|
32
cfa53f8a6607
Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents:
31
diff
changeset
|
136 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
|
137 patch_archiver_class( |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
138 ac, |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
139 make_keyword_filter( |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
140 ui, |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
141 repo, |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
142 ctx, |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
143 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
|
144 archival.tidyprefix(dest, kind, prefix), |
|
47
94ae433383a2
Allow an alternate patterns file (instead of .hgkwarchive) with the --kwconfig option.
Franz Glasner <hg@dom66.de>
parents:
46
diff
changeset
|
145 hgpath=opts.get("path"), |
|
94ae433383a2
Allow an alternate patterns file (instead of .hgkwarchive) with the --kwconfig option.
Franz Glasner <hg@dom66.de>
parents:
46
diff
changeset
|
146 kwconfig=opts.get("kwconfig"))) |
|
30
1670760f695f
Monkey-patch all current archivers in mercurial.archival: fileit, tarit and ziptit
Franz Glasner <hg@dom66.de>
parents:
29
diff
changeset
|
147 |
|
28
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
148 archival.archive(repo, dest, node, kind, not opts.get('no_decode'), |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
149 matchfn, prefix, subrepos=opts.get('subrepos')) |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
150 |
|
32
cfa53f8a6607
Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents:
31
diff
changeset
|
151 # XXX FIXME: Should the original methods be restored here? |
|
cfa53f8a6607
Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents:
31
diff
changeset
|
152 |
|
46
4a0c26dfef3c
Comment about automatically amending .hg_archival.txt with "path" items.
Franz Glasner <hg@dom66.de>
parents:
45
diff
changeset
|
153 # 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
|
154 # 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
|
155 # 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
|
156 # 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
|
157 |
|
32
cfa53f8a6607
Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents:
31
diff
changeset
|
158 |
|
45
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
159 @command('kwprint', |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
160 [('r', 'rev', '', _('revision to distribute'), _('REV')), |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
161 ('', 'path', 'default', _('the canonical repository to use'), _('PATH')), |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
162 ] + cmdutil.subrepoopts + cmdutil.walkopts, |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
163 _('[OPTION]...')) |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
164 def kwprint(ui, repo, **opts): |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
165 '''print the file-independent keywords |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
166 |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
167 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
|
168 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
|
169 |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
170 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
|
171 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
|
172 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
|
173 assumed. |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
174 |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
175 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
|
176 |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
177 ''' |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
178 |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
179 opts = pycompat.byteskwargs(opts) |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
180 ctx = scmutil.revsingle(repo, opts.get('rev')) |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
181 if not ctx: |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
182 raise error.Abort(_('no working directory: please specify a revision')) |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
183 node = ctx.node() |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
184 |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
185 prefix = cmdutil.makefilename(repo, "", node) |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
186 |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
187 keywords = make_node_keywords( |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
188 ui, repo, ctx, prefix, hgpath=opts.get("path")) |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
189 for key in sorted(keywords.keys()): |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
190 ui.write("$%s: %s $\n" % (key, keywords[key])) |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
191 |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
192 |
|
33
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
193 def patch_archiver_class(archivername, filter): |
|
32
cfa53f8a6607
Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents:
31
diff
changeset
|
194 """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
|
195 |
|
cfa53f8a6607
Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents:
31
diff
changeset
|
196 archiver_class = getattr(archival, archivername) |
|
cfa53f8a6607
Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents:
31
diff
changeset
|
197 orig_addfile = getattr(archiver_class, "addfile") |
|
cfa53f8a6607
Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents:
31
diff
changeset
|
198 |
|
cfa53f8a6607
Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents:
31
diff
changeset
|
199 def new_addfile(self, name, mode, isline, data): |
|
33
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
200 return orig_addfile(self, name, mode, isline, filter(name, data)) |
|
32
cfa53f8a6607
Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents:
31
diff
changeset
|
201 |
|
cfa53f8a6607
Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents:
31
diff
changeset
|
202 setattr(archiver_class, "addfile", new_addfile) |
|
cfa53f8a6607
Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents:
31
diff
changeset
|
203 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
|
204 |
|
28
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
205 |
|
33
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
206 def make_keyword_filter(ui, repo, ctx, archive_class, prefix, |
|
47
94ae433383a2
Allow an alternate patterns file (instead of .hgkwarchive) with the --kwconfig option.
Franz Glasner <hg@dom66.de>
parents:
46
diff
changeset
|
207 hgpath="default", |
|
94ae433383a2
Allow an alternate patterns file (instead of .hgkwarchive) with the --kwconfig option.
Franz Glasner <hg@dom66.de>
parents:
46
diff
changeset
|
208 kwconfig=""): |
|
44
71b321436cc1
Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents:
42
diff
changeset
|
209 keywords = make_node_keywords(ui, repo, ctx, prefix, hgpath=hgpath) |
|
47
94ae433383a2
Allow an alternate patterns file (instead of .hgkwarchive) with the --kwconfig option.
Franz Glasner <hg@dom66.de>
parents:
46
diff
changeset
|
210 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
|
211 if kwconfig: |
|
94ae433383a2
Allow an alternate patterns file (instead of .hgkwarchive) with the --kwconfig option.
Franz Glasner <hg@dom66.de>
parents:
46
diff
changeset
|
212 kwconfigdata = open(kwconfig, "rb").read() |
|
94ae433383a2
Allow an alternate patterns file (instead of .hgkwarchive) with the --kwconfig option.
Franz Glasner <hg@dom66.de>
parents:
46
diff
changeset
|
213 kwconfigname = kwconfig |
|
33
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
214 try: |
|
47
94ae433383a2
Allow an alternate patterns file (instead of .hgkwarchive) with the --kwconfig option.
Franz Glasner <hg@dom66.de>
parents:
46
diff
changeset
|
215 if kwconfigdata is None: |
|
94ae433383a2
Allow an alternate patterns file (instead of .hgkwarchive) with the --kwconfig option.
Franz Glasner <hg@dom66.de>
parents:
46
diff
changeset
|
216 # .hgkwarchive |
|
94ae433383a2
Allow an alternate patterns file (instead of .hgkwarchive) with the --kwconfig option.
Franz Glasner <hg@dom66.de>
parents:
46
diff
changeset
|
217 kwconfigdata = ctx[".hgkwarchive"].data() |
|
94ae433383a2
Allow an alternate patterns file (instead of .hgkwarchive) with the --kwconfig option.
Franz Glasner <hg@dom66.de>
parents:
46
diff
changeset
|
218 kwconfigname = ".kwarchive" |
|
33
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
219 except (IOError, LookupError): |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
220 def _filter(name, data): |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
221 return data |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
222 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
|
223 # |
|
71b321436cc1
Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents:
42
diff
changeset
|
224 # 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
|
225 # 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
|
226 # |
|
33
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
227 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
|
228 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
|
229 include = [] |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
230 exclude = [] |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
231 patterns = [] |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
232 if cfg.items("patterns"): |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
233 for pattern, style in cfg.items("patterns"): |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
234 style = style.upper() |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
235 if style in ("YES", "INCLUDE",): |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
236 include.append(pattern) |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
237 if style in ("NO", "EXCLUDE",): |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
238 exclude.append(pattern) |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
239 else: |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
240 patterns.append(pattern) |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
241 matcher = match.match(repo.root, '', patterns=patterns, |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
242 include=include, exclude=exclude) |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
243 else: |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
244 matcher = match.never(repo.root, '') |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
245 |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
246 def _filter(name, data): |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
247 real_name = name |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
248 if archive_class != "fileit": |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
249 if prefix: |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
250 assert name.startswith(prefix) |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
251 real_name = name[len(prefix):] |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
252 if not matcher(real_name): |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
253 return data |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
254 # file specific keywords |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
255 file_keywords = { |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
256 "HGsource": keywords["HGpath"] + '/' + real_name, |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
257 "Source": real_name, |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
258 "File": templatefilters.basename(real_name), |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
259 "Header": "%s %s %s %s" % (real_name, keywords["Revision"], keywords["Date"], keywords["Author"]), |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
260 "HGid": "%s %s %s %s" % (keywords["HGpath"] + '/' + real_name, keywords["Revision"], keywords["Date"], keywords["Author"]), |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
261 "HGheader": "%s %s %s %s" % (keywords["HGpath"] + '/' + real_name, keywords["HGrevision"], keywords["Date"], keywords["Author"]), |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
262 "Id": "%s %s %s %s" % (templatefilters.basename(real_name), keywords["Revision"], keywords["Date"], keywords["Author"]), |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
263 } |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
264 # This prevents unwanted keyword expansion here |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
265 _MARKER = '$' |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
266 for kw, value in itertools.chain(keywords.items(), file_keywords.items()): |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
267 filekw = _MARKER + kw + _MARKER |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
268 filevalue = "%s%s: %s %s" % (_MARKER, kw, value, _MARKER) |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
269 data = data.replace(filekw, filevalue) |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
270 return data |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
271 |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
272 return _filter |
|
44
71b321436cc1
Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents:
42
diff
changeset
|
273 |
|
71b321436cc1
Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents:
42
diff
changeset
|
274 |
|
71b321436cc1
Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents:
42
diff
changeset
|
275 def make_node_keywords(ui, repo, ctx, prefix, hgpath="default"): |
|
71b321436cc1
Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents:
42
diff
changeset
|
276 """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
|
277 |
|
71b321436cc1
Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents:
42
diff
changeset
|
278 """ |
|
71b321436cc1
Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents:
42
diff
changeset
|
279 if hgpath: |
|
71b321436cc1
Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents:
42
diff
changeset
|
280 if hgpath == '.': |
|
71b321436cc1
Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents:
42
diff
changeset
|
281 path_url = repo.root |
|
71b321436cc1
Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents:
42
diff
changeset
|
282 else: |
|
71b321436cc1
Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents:
42
diff
changeset
|
283 try: |
|
71b321436cc1
Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents:
42
diff
changeset
|
284 path_url = util.hidepassword(ui.paths[hgpath].loc) |
|
71b321436cc1
Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents:
42
diff
changeset
|
285 except LookupError: |
|
71b321436cc1
Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents:
42
diff
changeset
|
286 raise error.Abort(_('repository %s not found') % hgpath) |
|
71b321436cc1
Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents:
42
diff
changeset
|
287 else: |
|
71b321436cc1
Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents:
42
diff
changeset
|
288 path_url = repo.root |
|
71b321436cc1
Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents:
42
diff
changeset
|
289 keywords = { |
|
71b321436cc1
Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents:
42
diff
changeset
|
290 "HGpath": path_url, |
|
71b321436cc1
Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents:
42
diff
changeset
|
291 "HGrevision": ctx.hex(), |
|
71b321436cc1
Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents:
42
diff
changeset
|
292 "Revision": templatefilters.short(ctx.hex()), |
|
71b321436cc1
Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents:
42
diff
changeset
|
293 "Author": templatefilters.person(ctx.user()), |
|
71b321436cc1
Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents:
42
diff
changeset
|
294 "Date": templatefilters.isodatesec(ctx.date()), |
|
71b321436cc1
Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents:
42
diff
changeset
|
295 } |
|
71b321436cc1
Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents:
42
diff
changeset
|
296 return keywords |
