diff extensions/kwarchive.py @ 295:eeb8c52d8802

The "hg kwprint" command now is fully aware of subrepos if used with the "-S" flag
author Franz Glasner <hg@dom66.de>
date Mon, 28 Jan 2019 09:31:57 +0100
parents 2eb443e77cff
children 15d23729d176
line wrap: on
line diff
--- a/extensions/kwarchive.py	Sun Jan 27 16:36:30 2019 +0100
+++ b/extensions/kwarchive.py	Mon Jan 28 09:31:57 2019 +0100
@@ -386,13 +386,28 @@
 
 def _kwprint_subrepos(ctx, ui, rest, no_file, path_filter, user_filter):
     """For all subrepos in `ctx` do keyword expansion resursively"""
-    ui.write("STATE: " + repr(subrepo.state(ctx, ui)) + "\n")
     for subpath in sorted(ctx.substate):
+        substate = ctx.substate[subpath]
+        # skip on non-Mercurial subrepos
+        if substate[2] != "hg":
+            continue
         subrep = ctx.workingsub(subpath)
         subctx = subrep._getctx()
         assert subctx.repo() == subrep._repo
-        keywords = make_node_keywords(ui, subctx)
-        ui.write("KWD: " + repr(keywords) + "\n")
+        keywords = make_node_keywords(ui, subctx,
+                                      hgpath=None,
+                                      path_filter=path_filter,
+                                      user_filter=user_filter,
+                                      hglocation=substate[0])
+        if not no_file:
+            file_keywords = file_keywords = make_file_keywords(
+                keywords,
+                "dir3/dir4/test-s.file",
+                "ffffffff22e11fec41158eec187630c24a43120a")
+        else:
+            file_keywords = None
+        ui.write("\n\n")
+        _kwprint_keywords(ui, keywords, file_keywords, rest, no_file)
         # Recursively check for other subrepos
         _kwprint_subrepos(subctx, ui, rest, no_file, path_filter, user_filter)
 
@@ -572,23 +587,28 @@
 def make_node_keywords(ui, ctx,
                        hgpath="default",
                        path_filter="short",
-                       user_filter="user"):
+                       user_filter="user",
+                       hglocation=None):
     """Make all the node-specific (i.e. file-path independent) keywords
 
     """
-    if hgpath and hgpath != ".":
+    if (hglocation is not None) and hgpath:
+        raise ValueError("either `hgpath' or `hglocation` can be set")
+    if (hglocation is not None) or (hgpath and hgpath != "."):
+        if hglocation is None:
+            hglocation = ui.paths[hgpath].loc
         try:
             if path_filter == "full":
-                path_uri = bytes(util.url(ui.paths[hgpath].loc))
+                path_uri = bytes(util.url(hglocation))
             elif path_filter == "nopwd":
-                path_uri = util.hidepassword(ui.paths[hgpath].loc)
+                path_uri = util.hidepassword(hglocation)
             elif path_filter == "nouser":
-                path_url = util.url(ui.paths[hgpath].loc)
+                path_url = util.url(hglocation)
                 path_url.user = None
                 path_url.passwd = None
                 path_uri = bytes(path_url)
             elif path_filter == "short":
-                path_url = util.url(ui.paths[hgpath].loc)
+                path_url = util.url(hglocation)
                 path_url.scheme = SHORTENED_HG_SCHEMES.get(path_url.scheme,
                                                            "hg")
                 path_url.user = None
@@ -597,7 +617,7 @@
                 path_url.port = None
                 path_uri = bytes(path_url)
             elif path_filter == "last":
-                path_url = str(util.url(ui.paths[hgpath].loc)).split("/")
+                path_url = str(util.url(hglocation)).split("/")
                 path_uri = bytes(b".../"+path_url[-1])
             else:
                 raise error.Abort("path-filter `%s' not implemented"