diff --git a/mercurial/templatekw.py b/mercurial/templatekw.py --- a/mercurial/templatekw.py +++ b/mercurial/templatekw.py @@ -356,6 +356,22 @@ def showrev(repo, ctx, templ, **args): """: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 @@ keywords = { 'phase': showphase, 'phaseidx': showphaseidx, 'rev': showrev, + 'subrepos': showsubrepos, 'tags': showtags, } diff --git a/tests/test-subrepo.t b/tests/test-subrepo.t --- a/tests/test-subrepo.t +++ b/tests/test-subrepo.t @@ -1360,6 +1360,92 @@ Test that commit --secret works on both 6: secret $ cd ../../ +Test "subrepos" template keyword + + $ cd t + $ hg update -q 15 + $ cat > .hgsub < 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