changeset 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
files extensions/kwarchive.py tests/test-kwarchive.t
diffstat 2 files changed, 96 insertions(+), 10 deletions(-) [+]
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"
--- a/tests/test-kwarchive.t	Sun Jan 27 16:36:30 2019 +0100
+++ b/tests/test-kwarchive.t	Mon Jan 28 09:31:57 2019 +0100
@@ -347,3 +347,69 @@
   $ hg ci -m 'Include the nested subrepo'
   $ cat .hgsubstate
   178db3dd221b646aa0487b4051e267bda182159c subrepos1/subrepo1
+
+  $ hg kwprint -S
+  $Author: first.second $
+  $Date: 1970-01-01 00:00:00 +0000 $
+  $HGbookmarks:  $
+  $HGbranch: default $
+  $HGpath: hg+https://hg/repo.hg $
+  $HGrevision: 3d458771fce381c52a332311cb8a66ea2cc55a1a $
+  $HGshortdate: 1970-01-01 $
+  $HGtags:  $
+  $JustDate: 1970-01-01 $
+  $Revision: 3d458771fce3 $
+  $State: draft $
+  ^$ (re)
+  $File: test.file $
+  $HGheader: hg+https://hg/repo.hg/dir1/dir2/test.file 3d458771fce381c52a332311cb8a66ea2cc55a1a 1970-01-01 00:00:00 +0000 first.second draft $
+  $HGid: hg+https://hg/repo.hg/dir1/dir2/test.file 3d458771fce3 1970-01-01 00:00:00 +0000 first.second draft $
+  $HGnodeid: a4dd6f4b22e11fec41158eec187630c24a43120a $
+  $HGsource: hg+https://hg/repo.hg/dir1/dir2/test.file $
+  $Header: dir1/dir2/test.file 3d458771fce3 1970-01-01 00:00:00 +0000 first.second draft $
+  $Id: test.file 3d458771fce3 1970-01-01 00:00:00 +0000 first.second draft $
+  $Source: dir1/dir2/test.file $
+  ^$ (re)
+  ^$ (re)
+  $Author: first.second $
+  $Date: 1970-01-01 00:00:00 +0000 $
+  $HGbookmarks:  $
+  $HGbranch: default $
+  $HGpath: file:///subrepo1 $
+  $HGrevision: 178db3dd221b646aa0487b4051e267bda182159c $
+  $HGshortdate: 1970-01-01 $
+  $HGtags:  $
+  $JustDate: 1970-01-01 $
+  $Revision: 178db3dd221b $
+  $State: draft $
+  ^$ (re)
+  $File: test-s.file $
+  $HGheader: file:///subrepo1/dir3/dir4/test-s.file 178db3dd221b646aa0487b4051e267bda182159c 1970-01-01 00:00:00 +0000 first.second draft $
+  $HGid: file:///subrepo1/dir3/dir4/test-s.file 178db3dd221b 1970-01-01 00:00:00 +0000 first.second draft $
+  $HGnodeid: ffffffff22e11fec41158eec187630c24a43120a $
+  $HGsource: file:///subrepo1/dir3/dir4/test-s.file $
+  $Header: dir3/dir4/test-s.file 178db3dd221b 1970-01-01 00:00:00 +0000 first.second draft $
+  $Id: test-s.file 178db3dd221b 1970-01-01 00:00:00 +0000 first.second draft $
+  $Source: dir3/dir4/test-s.file $
+  ^$ (re)
+  ^$ (re)
+  $Author: first.second $
+  $Date: 1970-01-01 00:00:00 +0000 $
+  $HGbookmarks:  $
+  $HGbranch: default $
+  $HGpath: file:///subrepo2 $
+  $HGrevision: dac015e51ef48ba739a3c318dfb602011e236328 $
+  $HGshortdate: 1970-01-01 $
+  $HGtags:  $
+  $JustDate: 1970-01-01 $
+  $Revision: dac015e51ef4 $
+  $State: draft $
+  ^$ (re)
+  $File: test-s.file $
+  $HGheader: file:///subrepo2/dir3/dir4/test-s.file dac015e51ef48ba739a3c318dfb602011e236328 1970-01-01 00:00:00 +0000 first.second draft $
+  $HGid: file:///subrepo2/dir3/dir4/test-s.file dac015e51ef4 1970-01-01 00:00:00 +0000 first.second draft $
+  $HGnodeid: ffffffff22e11fec41158eec187630c24a43120a $
+  $HGsource: file:///subrepo2/dir3/dir4/test-s.file $
+  $Header: dir3/dir4/test-s.file dac015e51ef4 1970-01-01 00:00:00 +0000 first.second draft $
+  $Id: test-s.file dac015e51ef4 1970-01-01 00:00:00 +0000 first.second draft $
+  $Source: dir3/dir4/test-s.file $