# HG changeset patch # User Yuya Nishihara # Date 1587043811 -32400 # Node ID 59ad165f6cdb55a8fb9131e5c75f8486be8bb413 # Parent 694d40416d628607cf5291d5666162959423c1eb templatekw: fix shownames() to check if namespace exists in repo (issue6301) Namespace registration is dynamic, but the corresponding template keyword is registered statically. diff -r 694d40416d62 -r 59ad165f6cdb mercurial/namespaces.py --- a/mercurial/namespaces.py Wed Apr 15 20:10:35 2020 +0200 +++ b/mercurial/namespaces.py Thu Apr 16 22:30:11 2020 +0900 @@ -83,6 +83,9 @@ def __iter__(self): return self._names.__iter__() + def get(self, namespace, default=None): + return self._names.get(namespace, default) + def items(self): return pycompat.iteritems(self._names) diff -r 694d40416d62 -r 59ad165f6cdb mercurial/templatekw.py --- a/mercurial/templatekw.py Wed Apr 15 20:10:35 2020 +0200 +++ b/mercurial/templatekw.py Thu Apr 16 22:30:11 2020 +0900 @@ -562,7 +562,11 @@ """helper method to generate a template keyword for a namespace""" repo = context.resource(mapping, b'repo') ctx = context.resource(mapping, b'ctx') - ns = repo.names[namespace] + ns = repo.names.get(namespace) + if ns is None: + # namespaces.addnamespace() registers new template keyword, but + # the registered namespace might not exist in the current repo. + return names = ns.names(repo, ctx.node()) return compatlist( context, mapping, ns.templatename, names, plural=namespace diff -r 694d40416d62 -r 59ad165f6cdb tests/test-log.t --- a/tests/test-log.t Wed Apr 15 20:10:35 2020 +0200 +++ b/tests/test-log.t Thu Apr 16 22:30:11 2020 +0900 @@ -2273,6 +2273,8 @@ > from mercurial import namespaces > > def reposetup(ui, repo): + > if not repo.local(): + > return > foo = {b'foo': repo[0].node()} > names = lambda r: foo.keys() > namemap = lambda r, name: foo.get(name) @@ -2328,6 +2330,18 @@ $ cd .. +New namespace is registered per repo instance, but the template keyword +is global. So we shouldn't expect the namespace always exists. Using +ssh:// makes sure a bundle repository is created from scratch. (issue6301) + + $ hg clone -e "'$PYTHON' '$TESTDIR/dummyssh'" \ + > -qr0 "ssh://user@dummy/`pwd`/a" a-clone + $ hg incoming --config extensions.names=names.py -R a-clone \ + > -e "'$PYTHON' '$TESTDIR/dummyssh'" -T '{bars}\n' -l1 + comparing with ssh://user@dummy/$TESTTMP/a + searching for changes + + hg log -f dir across branches $ hg init acrossbranches