changeset 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 f9d1cb2123c0
children 58f47399691c a4de3b2e74c9
files extensions/kwarchive.py
diffstat 1 files changed, 107 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/extensions/kwarchive.py	Fri Nov 10 09:14:16 2017 +0100
@@ -0,0 +1,107 @@
+# -*- coding: utf-8 -*-
+"""archive with keyword expansion into selected files
+"""
+
+from __future__ import absolute_import
+
+
+__version__ = "0.0.dev1"
+
+__author__ = "Franz Glasner"
+
+
+import os
+
+from mercurial.i18n import _
+from mercurial import (archival, commands, cmdutil, error, pycompat,
+                       scmutil, util)
+
+
+testedwith = "4.3.2"
+
+
+cmdtable = {}
+
+command = cmdutil.command(cmdtable)
+
+
+@command('kwarchive',
+    [('', 'no-decode', None, _('do not pass files through decoders')),
+    ('p', 'prefix', '', _('directory prefix for files in archive'),
+     _('PREFIX')),
+    ('r', 'rev', '', _('revision to distribute'), _('REV')),
+    ('t', 'type', '', _('type of distribution to create'), _('TYPE')),
+    ] + cmdutil.subrepoopts + cmdutil.walkopts,
+    _('[OPTION]... DEST'))
+def kwarchive(ui, repo, dest, **opts):
+    '''create an unversioned archive of a repository revision with some keywords expanded
+
+    By default, the revision used is the parent of the working
+    directory; use -r/--rev to specify a different revision.
+
+    The archive type is automatically detected based on file
+    extension (to override, use -t/--type).
+
+    .. container:: verbose
+
+      Examples:
+
+      - create a zip file containing the 1.0 release::
+
+          hg archive -r 1.0 project-1.0.zip
+
+      - create a tarball excluding .hg files::
+
+          hg archive project.tar.gz -X ".hg*"
+
+    Valid types are:
+
+    :``files``: a directory full of files (default)
+    :``tar``:   tar archive, uncompressed
+    :``tbz2``:  tar archive, compressed using bzip2
+    :``tgz``:   tar archive, compressed using gzip
+    :``uzip``:  zip archive, uncompressed
+    :``zip``:   zip archive, compressed using deflate
+
+    The exact name of the destination archive or directory is given
+    using a format string; see :hg:`help export` for details.
+
+    Each member added to an archive file has a directory prefix
+    prepended. Use -p/--prefix to specify a format string for the
+    prefix. The default is the basename of the archive, with suffixes
+    removed.
+
+    Returns 0 on success.
+    '''
+
+    print "HUHU"
+    repo.adddatafilter("filter2", filter2)
+    repo.ui.setconfig("decode", "**.py", "filter2", 'kw')
+    opts = pycompat.byteskwargs(opts)
+    ctx = scmutil.revsingle(repo, opts.get('rev'))
+    if not ctx:
+        raise error.Abort(_('no working directory: please specify a revision'))
+    node = ctx.node()
+    dest = cmdutil.makefilename(repo, dest, node)
+    if os.path.realpath(dest) == repo.root:
+        raise error.Abort(_('repository root cannot be destination'))
+
+    kind = opts.get('type') or archival.guesskind(dest) or 'files'
+    prefix = opts.get('prefix')
+
+    if dest == '-':
+        if kind == 'files':
+            raise error.Abort(_('cannot archive plain files to stdout'))
+        dest = cmdutil.makefileobj(repo, dest)
+        if not prefix:
+            prefix = os.path.basename(repo.root) + '-%h'
+
+    prefix = cmdutil.makefilename(repo, prefix, node)
+    matchfn = scmutil.match(ctx, [], opts)
+    archival.archive(repo, dest, node, kind, not opts.get('no_decode'),
+                     matchfn, prefix, subrepos=opts.get('subrepos'))
+
+
+def filter2(s, params, ui, **kwargs):
+    print "=============>", repr(params), repr(kwargs)
+    return s