changeset 21897:764adc332f6e

templatekw: add 'subrepos' keyword to show updated subrepositories 'subrepos' template keyword newly added by this patch shows updated subrepositories. For the compatibility with the list of subrepositories shown in the editor at commit: - 'subrepos' is empty, at revisions removing '.hgsub' itself - 'subrepos' is calculated between the revision and the first parent of it, at merge revisions To avoid silent regression, this patch also confirms "hg diff" of ".hgsubstate" and parents for each target revisions in the test.
author FUJIWARA Katsunori <foozy@lares.dti.ne.jp>
date Tue, 15 Jul 2014 23:34:13 +0900
parents 2b41ee1b5ea1
children 10fcfb615fb4
files mercurial/templatekw.py tests/test-subrepo.t
diffstat 2 files changed, 103 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/templatekw.py	Tue Jul 15 23:34:13 2014 +0900
+++ b/mercurial/templatekw.py	Tue Jul 15 23:34:13 2014 +0900
@@ -356,6 +356,22 @@
     """:rev: Integer. The repository-local changeset revision number."""
     return ctx.rev()
 
+def showsubrepos(**args):
+    """:subrepos: List of strings. Updated subrepositories in the changeset."""
+    ctx = args['ctx']
+    substate = ctx.substate
+    if not substate:
+        return showlist('subrepo', [], **args)
+    psubstate = ctx.parents()[0].substate or {}
+    subrepos = []
+    for sub in substate:
+        if sub not in psubstate or substate[sub] != psubstate[sub]:
+            subrepos.append(sub) # modified or newly added in ctx
+    for sub in psubstate:
+        if sub not in substate:
+            subrepos.append(sub) # removed in ctx
+    return showlist('subrepo', sorted(subrepos), **args)
+
 def showtags(**args):
     """:tags: List of strings. Any tags associated with the changeset."""
     return showlist('tag', args['ctx'].tags(), **args)
@@ -397,6 +413,7 @@
     'phase': showphase,
     'phaseidx': showphaseidx,
     'rev': showrev,
+    'subrepos': showsubrepos,
     'tags': showtags,
 }
 
--- a/tests/test-subrepo.t	Tue Jul 15 23:34:13 2014 +0900
+++ b/tests/test-subrepo.t	Tue Jul 15 23:34:13 2014 +0900
@@ -1360,6 +1360,92 @@
   6: secret
   $ cd ../../
 
+Test "subrepos" template keyword
+
+  $ cd t
+  $ hg update -q 15
+  $ cat > .hgsub <<EOF
+  > s = s
+  > EOF
+  $ hg commit -m "16"
+  warning: changes are committed in secret phase from subrepository s
+
+(addition of ".hgsub" itself)
+
+  $ hg diff --nodates -c 1 .hgsubstate
+  diff -r f7b1eb17ad24 -r 7cf8cfea66e4 .hgsubstate
+  --- /dev/null
+  +++ b/.hgsubstate
+  @@ -0,0 +1,1 @@
+  +e4ece1bf43360ddc8f6a96432201a37b7cd27ae4 s
+  $ hg log -r 1 --template "{p1node|short} {p2node|short}\n{subrepos % '{subrepo}\n'}"
+  f7b1eb17ad24 000000000000
+  s
+
+(modification of existing entry)
+
+  $ hg diff --nodates -c 2 .hgsubstate
+  diff -r 7cf8cfea66e4 -r df30734270ae .hgsubstate
+  --- a/.hgsubstate
+  +++ b/.hgsubstate
+  @@ -1,1 +1,1 @@
+  -e4ece1bf43360ddc8f6a96432201a37b7cd27ae4 s
+  +dc73e2e6d2675eb2e41e33c205f4bdab4ea5111d s
+  $ hg log -r 2 --template "{p1node|short} {p2node|short}\n{subrepos % '{subrepo}\n'}"
+  7cf8cfea66e4 000000000000
+  s
+
+(addition of entry)
+
+  $ hg diff --nodates -c 5 .hgsubstate
+  diff -r 7cf8cfea66e4 -r 1f14a2e2d3ec .hgsubstate
+  --- a/.hgsubstate
+  +++ b/.hgsubstate
+  @@ -1,1 +1,2 @@
+   e4ece1bf43360ddc8f6a96432201a37b7cd27ae4 s
+  +60ca1237c19474e7a3978b0dc1ca4e6f36d51382 t
+  $ hg log -r 5 --template "{p1node|short} {p2node|short}\n{subrepos % '{subrepo}\n'}"
+  7cf8cfea66e4 000000000000
+  t
+
+(removal of existing entry)
+
+  $ hg diff --nodates -c 16 .hgsubstate
+  diff -r 8bec38d2bd0b -r f2f70bc3d3c9 .hgsubstate
+  --- a/.hgsubstate
+  +++ b/.hgsubstate
+  @@ -1,2 +1,1 @@
+   0731af8ca9423976d3743119d0865097c07bdc1b s
+  -e202dc79b04c88a636ea8913d9182a1346d9b3dc t
+  $ hg log -r 16 --template "{p1node|short} {p2node|short}\n{subrepos % '{subrepo}\n'}"
+  8bec38d2bd0b 000000000000
+  t
+
+(merging)
+
+  $ hg diff --nodates -c 9 .hgsubstate
+  diff -r f6affe3fbfaa -r f0d2028bf86d .hgsubstate
+  --- a/.hgsubstate
+  +++ b/.hgsubstate
+  @@ -1,1 +1,2 @@
+   fc627a69481fcbe5f1135069e8a3881c023e4cf5 s
+  +60ca1237c19474e7a3978b0dc1ca4e6f36d51382 t
+  $ hg log -r 9 --template "{p1node|short} {p2node|short}\n{subrepos % '{subrepo}\n'}"
+  f6affe3fbfaa 1f14a2e2d3ec
+  t
+
+(removal of ".hgsub" itself)
+
+  $ hg diff --nodates -c 8 .hgsubstate
+  diff -r f94576341bcf -r 96615c1dad2d .hgsubstate
+  --- a/.hgsubstate
+  +++ /dev/null
+  @@ -1,2 +0,0 @@
+  -e4ece1bf43360ddc8f6a96432201a37b7cd27ae4 s
+  -7af322bc1198a32402fe903e0b7ebcfc5c9bf8f4 t
+  $ hg log -r 8 --template "{p1node|short} {p2node|short}\n{subrepos % '{subrepo}\n'}"
+  f94576341bcf 000000000000
+
 Test that '[paths]' is configured correctly at subrepo creation
 
   $ cd $TESTTMP/tc