Mercurial > hgrepos > DevTools > mercurial-extensions
annotate extensions/kwarchive.py @ 46:4a0c26dfef3c
Comment about automatically amending .hg_archival.txt with "path" items.
But this means shat we should know the complete configuration
("ui.archivemeta") and it's name and some output match filters (see
archival.archive()).
| author | Franz Glasner <hg@dom66.de> |
|---|---|
| date | Wed, 15 Nov 2017 09:08:35 +0100 |
| parents | c077d30da0ee |
| children | 94ae433383a2 |
| 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')), |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
55 ('p', 'prefix', '', _('directory prefix for files in archive'), |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
56 _('PREFIX')), |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
57 ('r', 'rev', '', _('revision to distribute'), _('REV')), |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
58 ('t', 'type', '', _('type of distribution to create'), _('TYPE')), |
|
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
|
59 ('', 'path', 'default', _('the canonical repository to use'), _('PATH')), |
|
28
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
60 ] + cmdutil.subrepoopts + cmdutil.walkopts, |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
61 _('[OPTION]... DEST')) |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
62 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
|
63 '''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
|
64 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
65 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
|
66 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
|
67 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
68 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
|
69 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
|
70 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
71 .. container:: verbose |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
72 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
73 Examples: |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
74 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
75 - 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
|
76 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
77 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
|
78 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
79 - 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
|
80 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
81 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
|
82 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
83 Valid types are: |
|
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 :``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
|
86 :``tar``: tar archive, uncompressed |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
87 :``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
|
88 :``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
|
89 :``uzip``: zip archive, uncompressed |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
90 :``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
|
91 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
92 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
|
93 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
|
94 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
95 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
|
96 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
|
97 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
|
98 removed. |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
99 |
| 41 | 100 Use --path to specify named path information from :hg:`paths` as |
| 101 the canonical repository location. Use ``.`` for the current | |
| 102 repository root root. If no path is given then ``default`` is | |
| 103 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
|
104 |
|
28
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
105 Returns 0 on success. |
| 41 | 106 |
|
28
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
107 ''' |
|
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 opts = pycompat.byteskwargs(opts) |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
110 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
|
111 if not ctx: |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
112 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
|
113 node = ctx.node() |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
114 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
|
115 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
|
116 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
|
117 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
118 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
|
119 prefix = opts.get('prefix') |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
120 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
121 if dest == '-': |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
122 if kind == 'files': |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
123 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
|
124 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
|
125 if not prefix: |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
126 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
|
127 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
128 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
|
129 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
|
130 |
|
58f47399691c
New successful PoC: monkey-patch all relevant archiver's "addfile()" method
Franz Glasner <hg@dom66.de>
parents:
28
diff
changeset
|
131 # |
|
31
0597395e2d18
Comment: better explanation of what is monkey-patched
Franz Glasner <hg@dom66.de>
parents:
30
diff
changeset
|
132 # 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
|
133 # expands keywords |
|
58f47399691c
New successful PoC: monkey-patch all relevant archiver's "addfile()" method
Franz Glasner <hg@dom66.de>
parents:
28
diff
changeset
|
134 # |
|
32
cfa53f8a6607
Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents:
31
diff
changeset
|
135 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
|
136 patch_archiver_class( |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
137 ac, |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
138 make_keyword_filter( |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
139 ui, |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
140 repo, |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
141 ctx, |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
142 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
|
143 archival.tidyprefix(dest, kind, prefix), |
|
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 hgpath=opts.get("path"))) |
|
30
1670760f695f
Monkey-patch all current archivers in mercurial.archival: fileit, tarit and ziptit
Franz Glasner <hg@dom66.de>
parents:
29
diff
changeset
|
145 |
|
28
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
146 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
|
147 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
|
148 |
|
32
cfa53f8a6607
Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents:
31
diff
changeset
|
149 # XXX FIXME: Should the original methods be restored here? |
|
cfa53f8a6607
Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents:
31
diff
changeset
|
150 |
|
46
4a0c26dfef3c
Comment about automatically amending .hg_archival.txt with "path" items.
Franz Glasner <hg@dom66.de>
parents:
45
diff
changeset
|
151 # 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
|
152 # 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
|
153 # 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
|
154 # 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
|
155 |
|
32
cfa53f8a6607
Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents:
31
diff
changeset
|
156 |
|
45
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
157 @command('kwprint', |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
158 [('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
|
159 ('', '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
|
160 ] + 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
|
161 _('[OPTION]...')) |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
162 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
|
163 '''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
|
164 |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
165 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
|
166 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
|
167 |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
168 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
|
169 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
|
170 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
|
171 assumed. |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
172 |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
173 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
|
174 |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
175 ''' |
|
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 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
|
178 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
|
179 if not ctx: |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
180 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
|
181 node = ctx.node() |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
182 |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
183 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
|
184 |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
185 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
|
186 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
|
187 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
|
188 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
|
189 |
|
c077d30da0ee
Implemented a "kwprint" command to print just some file-independent keywords
Franz Glasner <hg@dom66.de>
parents:
44
diff
changeset
|
190 |
|
33
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
191 def patch_archiver_class(archivername, filter): |
|
32
cfa53f8a6607
Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents:
31
diff
changeset
|
192 """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
|
193 |
|
cfa53f8a6607
Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents:
31
diff
changeset
|
194 archiver_class = getattr(archival, archivername) |
|
cfa53f8a6607
Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents:
31
diff
changeset
|
195 orig_addfile = getattr(archiver_class, "addfile") |
|
cfa53f8a6607
Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents:
31
diff
changeset
|
196 |
|
cfa53f8a6607
Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents:
31
diff
changeset
|
197 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
|
198 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
|
199 |
|
cfa53f8a6607
Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents:
31
diff
changeset
|
200 setattr(archiver_class, "addfile", new_addfile) |
|
cfa53f8a6607
Refactor the class' monkey-patching
Franz Glasner <hg@dom66.de>
parents:
31
diff
changeset
|
201 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
|
202 |
|
28
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
203 |
|
33
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
204 def make_keyword_filter(ui, repo, ctx, archive_class, prefix, |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
205 hgpath="default"): |
|
44
71b321436cc1
Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents:
42
diff
changeset
|
206 keywords = make_node_keywords(ui, repo, ctx, prefix, hgpath=hgpath) |
|
33
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
207 |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
208 # .hgkwarchive |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
209 try: |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
210 kwconfig = ctx[".hgkwarchive"] |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
211 except (IOError, LookupError): |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
212 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
|
213 return data |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
214 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
|
215 # |
|
71b321436cc1
Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents:
42
diff
changeset
|
216 # 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
|
217 # 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
|
218 # |
|
33
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
219 cfg = config.config() |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
220 cfg.parse(".kwarchive", kwconfig.data()) |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
221 include = [] |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
222 exclude = [] |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
223 patterns = [] |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
224 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
|
225 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
|
226 style = style.upper() |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
227 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
|
228 include.append(pattern) |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
229 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
|
230 exclude.append(pattern) |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
231 else: |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
232 patterns.append(pattern) |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
233 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
|
234 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
|
235 else: |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
236 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
|
237 |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
238 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
|
239 real_name = name |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
240 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
|
241 if prefix: |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
242 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
|
243 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
|
244 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
|
245 return data |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
246 # file specific keywords |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
247 file_keywords = { |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
248 "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
|
249 "Source": real_name, |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
250 "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
|
251 "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
|
252 "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
|
253 "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
|
254 "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
|
255 } |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
256 # 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
|
257 _MARKER = '$' |
|
dc8db9693262
kwarchive expands keyword on given files (.hgkwarchive with generic Mercurial patterns)
Franz Glasner <hg@dom66.de>
parents:
32
diff
changeset
|
258 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
|
259 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
|
260 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
|
261 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
|
262 return data |
|
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 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
|
265 |
|
71b321436cc1
Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents:
42
diff
changeset
|
266 |
|
71b321436cc1
Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents:
42
diff
changeset
|
267 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
|
268 """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
|
269 |
|
71b321436cc1
Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents:
42
diff
changeset
|
270 """ |
|
71b321436cc1
Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents:
42
diff
changeset
|
271 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
|
272 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
|
273 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
|
274 else: |
|
71b321436cc1
Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents:
42
diff
changeset
|
275 try: |
|
71b321436cc1
Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents:
42
diff
changeset
|
276 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
|
277 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
|
278 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
|
279 else: |
|
71b321436cc1
Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents:
42
diff
changeset
|
280 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
|
281 keywords = { |
|
71b321436cc1
Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents:
42
diff
changeset
|
282 "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
|
283 "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
|
284 "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
|
285 "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
|
286 "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
|
287 } |
|
71b321436cc1
Refactor: generate all node-specific keywords (file-path independent) in a dedicated function
Franz Glasner <hg@dom66.de>
parents:
42
diff
changeset
|
288 return keywords |
