diff 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
line wrap: on
line diff
--- a/extensions/kwarchive.py	Wed Nov 15 09:08:35 2017 +0100
+++ b/extensions/kwarchive.py	Wed Nov 15 09:30:36 2017 +0100
@@ -52,11 +52,12 @@
 
 @command('kwarchive',
     [('', 'no-decode', None, _('do not pass files through decoders')),
-    ('p', 'prefix', '', _('directory prefix for files in archive'),
+     ('p', 'prefix', '', _('directory prefix for files in archive'),
      _('PREFIX')),
-    ('r', 'rev', '', _('revision to distribute'), _('REV')),
-    ('t', 'type', '', _('type of distribution to create'), _('TYPE')),
-    ('', 'path', 'default', _('the canonical repository to use'), _('PATH')),
+     ('r', 'rev', '', _('revision to distribute'), _('REV')),
+     ('t', 'type', '', _('type of distribution to create'), _('TYPE')),
+     ('', 'path', 'default', _('the canonical repository to use'), _('PATH')),
+     ('', "kwconfig", '', _('an alternate pattern configuration configuration file'), _('PATTERNCONFIG')),
     ] + cmdutil.subrepoopts + cmdutil.walkopts,
     _('[OPTION]... DEST'))
 def kwarchive(ui, repo, dest, **opts):
@@ -141,7 +142,8 @@
                 ctx,
                 ac,
                 archival.tidyprefix(dest, kind, prefix),
-                hgpath=opts.get("path")))
+                hgpath=opts.get("path"),
+                kwconfig=opts.get("kwconfig")))
 
     archival.archive(repo, dest, node, kind, not opts.get('no_decode'),
                      matchfn, prefix, subrepos=opts.get('subrepos'))
@@ -202,12 +204,18 @@
 
 
 def make_keyword_filter(ui, repo, ctx, archive_class, prefix,
-                        hgpath="default"):
+                        hgpath="default",
+                        kwconfig=""):
     keywords = make_node_keywords(ui, repo, ctx, prefix, hgpath=hgpath)
-
-    # .hgkwarchive
+    kwconfigdata = kwconfigname = None
+    if kwconfig:
+        kwconfigdata = open(kwconfig, "rb").read()
+        kwconfigname = kwconfig
     try:
-        kwconfig = ctx[".hgkwarchive"]
+        if kwconfigdata is None:
+            # .hgkwarchive
+            kwconfigdata = ctx[".hgkwarchive"].data()
+            kwconfigname = ".kwarchive"
     except (IOError, LookupError):
         def _filter(name, data):
             return data
@@ -217,7 +225,7 @@
         # Mercurial matcher
         #
         cfg = config.config()
-        cfg.parse(".kwarchive", kwconfig.data())
+        cfg.parse(kwconfigname, kwconfigdata)
         include = []
         exclude = []
         patterns = []