# HG changeset patch # User Anton Shestakov # Date 1651664304 -14400 # Node ID 8861e33f3bb2aaf85fbcdc91761e2b6de203df38 # Parent 6bbd16579f0f12f71b6c54ebf048c9d6d2e7c3cb topic: setting current repo namespace with debug-namespace diff -r 6bbd16579f0f -r 8861e33f3bb2 hgext3rd/topic/__init__.py --- a/hgext3rd/topic/__init__.py Tue May 03 21:45:59 2022 +0400 +++ b/hgext3rd/topic/__init__.py Wed May 04 15:38:24 2022 +0400 @@ -1521,6 +1521,39 @@ if topic: _changecurrenttopic(repo, topic) +def _changecurrenttns(repo, tns): + if tns: + with repo.wlock(): + repo.vfs.write(b'topic-namespace', tns) + else: + repo.vfs.unlinkpath(b'topic-namespace', ignoremissing=True) + +@command(b'debug-topic-namespace', [ + (b'', b'clear', False, b'clear active topic namespace if any'), + ], + _(b'[NAMESPACE|--clear]')) +def debugtopicnamespace(ui, repo, tns=None, **opts): + """set or show the current topic namespace""" + if opts.get('clear'): + if tns: + raise error.Abort(_(b"cannot use --clear when setting a topic namespace")) + tns = None + elif not tns: + ui.write(b'%s\n' % repo.currenttns) + return + if tns: + tns = tns.strip() + if not tns: + raise error.Abort(_(b"topic namespace cannot consist entirely of whitespace")) + if b'/' in tns: + raise error.Abort(_(b"topic namespace cannot contain '/' character")) + scmutil.checknewlabel(repo, tns, b'topic namespace') + ctns = repo.currenttns + _changecurrenttns(repo, tns) + if ctns == b'default' and tns: + repo.ui.status(_(b'marked working directory as topic namespace: %s\n') + % tns) + @command(b'debug-topic-namespaces', []) def debugtopicnamespaces(ui, repo, **opts): """list repository namespaces""" diff -r 6bbd16579f0f -r 8861e33f3bb2 tests/test-namespaces.t --- a/tests/test-namespaces.t Tue May 03 21:45:59 2022 +0400 +++ b/tests/test-namespaces.t Wed May 04 15:38:24 2022 +0400 @@ -5,9 +5,21 @@ $ hg init repo $ cd repo + $ hg debug-topic-namespace space-name + marked working directory as topic namespace: space-name + $ hg debug-topic-namespaces + space-name + + $ hg branches + + $ hg debug-topic-namespace --clear $ hg debug-topic-namespaces default + $ hg debugtopicnamespace --clear nonsense + abort: cannot use --clear when setting a topic namespace + [255] + Parsing $ hg debugparsefqbn foo/bar//user26/feature -T '[{branch}] <{topic_namespace}> ({topic})\n'