diff --git a/mercurial/namespaces.py b/mercurial/namespaces.py --- a/mercurial/namespaces.py +++ b/mercurial/namespaces.py @@ -83,6 +83,9 @@ class namespaces(object): 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 --git a/mercurial/templatekw.py b/mercurial/templatekw.py --- a/mercurial/templatekw.py +++ b/mercurial/templatekw.py @@ -562,7 +562,11 @@ def shownames(context, mapping, namespac """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 --git a/tests/test-log.t b/tests/test-log.t --- a/tests/test-log.t +++ b/tests/test-log.t @@ -2273,6 +2273,8 @@ Check that adding an arbitrary name show > 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 @@ multi-line template with error $ 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