diff extensions/kwarchive.py @ 293:75070825d111

- make_node_keywords() and make_keyword_filter() do not need a "repo" argument. - make_node_keywords() does not need the prefix argument (unused) The repository will be gotten from "ctx.repo()". This also works better for subrepos.
author Franz Glasner <hg@dom66.de>
date Sun, 27 Jan 2019 16:08:31 +0100
parents 241b0b9eaa19
children 2eb443e77cff
line wrap: on
line diff
--- a/extensions/kwarchive.py	Sun Jan 27 15:39:03 2019 +0100
+++ b/extensions/kwarchive.py	Sun Jan 27 16:08:31 2019 +0100
@@ -254,7 +254,6 @@
             ac,
             make_keyword_filter(
                 ui,
-                repo,
                 ctx,
                 ac,
                 archival.tidyprefix(dest, kind, prefix),
@@ -339,7 +338,7 @@
     prefix = makefilename_compat(ctx, "")
 
     keywords = make_node_keywords(
-        ui, repo, ctx, prefix,
+        ui, ctx,
         hgpath=opts.get("path"),
         path_filter=get_checked_path_filter_option(opts),
         user_filter=get_checked_user_filter_option(opts))
@@ -372,18 +371,20 @@
 
 
 def _kwprint_subrepos(ctx, ui):
+    """For all subrepos in `ctx` do keyword expansion resursively"""
     ui.write("STATE: " + repr(subrepo.state(ctx, ui)) + "\n")
     for subpath in sorted(ctx.substate):
         subrep = ctx.workingsub(subpath)
         subctx = subrep._getctx()
-        keywords = make_node_keywords(ui, subrep._repo, subctx, subpath)
+        assert subctx.repo() == subrep._repo
+        keywords = make_node_keywords(ui, subctx)
         ui.write("KWD: " + repr(keywords) + "\n")
         # Recursively check for other subrepos
         _test_subrepos(subctx, ui)
 
 
 def _test_subrepos(ctx, ui):
-    ui.write("STATE: " + repr(subrepo.state(ctx, ui)) + "\n")    
+    ui.write("STATE: " + repr(subrepo.state(ctx, ui)) + "\n")
     for subpath in sorted(ctx.substate):
         ui.write("SUBPATH: " + subpath + "\n");
         subrep = ctx.workingsub(subpath)
@@ -410,12 +411,12 @@
     return orig_addfile
 
 
-def make_keyword_filter(ui, repo, ctx, archive_class, prefix,
+def make_keyword_filter(ui, ctx, archive_class, prefix,
                         hgpath="default",
                         path_filter="short",
                         user_filter="user",
                         kwconfig=""):
-    keywords = make_node_keywords(ui, repo, ctx, prefix,
+    keywords = make_node_keywords(ui, ctx,
                                   hgpath=hgpath,
                                   path_filter=path_filter,
                                   user_filter=user_filter)
@@ -461,28 +462,30 @@
                 else:
                     # default to RCS if no keyword style is given
                     patterns_rcs.append(pattern)
-            matcher = match.match(repo.root, '', patterns=patterns,
+            matcher = match.match(ctx.repo().root, '', patterns=patterns,
                                   include=include, exclude=exclude)
         else:
-            matcher = match.never(repo.root, '')
+            matcher = match.never(ctx.repo().root, '')
 
         #
         # An empty patterns_rcs does not mean that match_rcs is always
         # true.
         #
         if not patterns_rcs:
-            matcher_rcs = match.never(repo.root, '')
+            matcher_rcs = match.never(ctx.repo().root, '')
         else:
-            matcher_rcs = match.match(repo.root, '', patterns=patterns_rcs,
+            matcher_rcs = match.match(ctx.repo().root, '',
+                                      patterns=patterns_rcs,
                                       include=[], exclude=[])
         #
         # An empty patterns_rst does not mean that match_rst is always
         # true.
         #
         if not patterns_rst:
-            matcher_rst = match.never(repo.root, '')
+            matcher_rst = match.never(ctx.repo().root, '')
         else:
-            matcher_rst = match.match(repo.root, '', patterns=patterns_rst,
+            matcher_rst = match.match(ctx.repo().root, '',
+                                      patterns=patterns_rst,
                                       include=[], exclude=[])
 
         #
@@ -552,7 +555,7 @@
     return _filter
 
 
-def make_node_keywords(ui, repo, ctx, prefix,
+def make_node_keywords(ui, ctx,
                        hgpath="default",
                        path_filter="short",
                        user_filter="user"):
@@ -588,7 +591,7 @@
         except LookupError:
             raise error.Abort(_("remote repository named `%s' not found") % hgpath)
     else:
-        path_uri = repo.root
+        path_uri = ctx.repo().root
         if path_filter == "last":
             m = max(path_uri.rfind(b"/"), path_uri.rfind(b"\\"))
             if m >= 0: