Mercurial > hgrepos > DevTools > mercurial-extensions
annotate extensions/kwarchive.py @ 28:c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
| author | Franz Glasner <hg@dom66.de> |
|---|---|
| date | Fri, 10 Nov 2017 09:14:16 +0100 |
| parents | |
| children | 58f47399691c a4de3b2e74c9 |
| 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 -*- |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
2 """archive with keyword expansion into selected files |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
3 """ |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
4 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
5 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
|
6 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
7 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
8 __version__ = "0.0.dev1" |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
9 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
10 __author__ = "Franz Glasner" |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
11 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
12 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
13 import os |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
14 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
15 from mercurial.i18n import _ |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
16 from mercurial import (archival, commands, cmdutil, error, pycompat, |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
17 scmutil, util) |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
18 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
19 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
20 testedwith = "4.3.2" |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
21 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
22 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
23 cmdtable = {} |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
24 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
25 command = cmdutil.command(cmdtable) |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
26 |
|
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 @command('kwarchive', |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
29 [('', '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
|
30 ('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
|
31 _('PREFIX')), |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
32 ('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
|
33 ('t', 'type', '', _('type of distribution to create'), _('TYPE')), |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
34 ] + cmdutil.subrepoopts + cmdutil.walkopts, |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
35 _('[OPTION]... DEST')) |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
36 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
|
37 '''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
|
38 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
39 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
|
40 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
|
41 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
42 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
|
43 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
|
44 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
45 .. container:: verbose |
|
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 Examples: |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
48 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
49 - 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
|
50 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
51 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
|
52 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
53 - 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
|
54 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
55 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
|
56 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
57 Valid types are: |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
58 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
59 :``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
|
60 :``tar``: tar archive, uncompressed |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
61 :``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
|
62 :``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
|
63 :``uzip``: zip archive, uncompressed |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
64 :``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
|
65 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
66 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
|
67 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
|
68 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
69 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
|
70 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
|
71 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
|
72 removed. |
|
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 Returns 0 on success. |
|
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 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
77 print "HUHU" |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
78 repo.adddatafilter("filter2", filter2) |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
79 repo.ui.setconfig("decode", "**.py", "filter2", 'kw') |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
80 opts = pycompat.byteskwargs(opts) |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
81 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
|
82 if not ctx: |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
83 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
|
84 node = ctx.node() |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
85 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
|
86 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
|
87 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
|
88 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
89 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
|
90 prefix = opts.get('prefix') |
|
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 if dest == '-': |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
93 if kind == 'files': |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
94 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
|
95 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
|
96 if not prefix: |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
97 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
|
98 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
99 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
|
100 matchfn = scmutil.match(ctx, [], opts) |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
101 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
|
102 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
|
103 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
104 |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
105 def filter2(s, params, ui, **kwargs): |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
106 print "=============>", repr(params), repr(kwargs) |
|
c8b7d0635656
PoC for archive with keyword expansion: works w/o touching subrepos
Franz Glasner <hg@dom66.de>
parents:
diff
changeset
|
107 return s |
