changeset 6239:8861e33f3bb2

topic: setting current repo namespace with debug-namespace
author Anton Shestakov <av6@dwimlabs.net>
date Wed, 04 May 2022 15:38:24 +0400
parents 6bbd16579f0f
children 2686ecc90791
files hgext3rd/topic/__init__.py tests/test-namespaces.t
diffstat 2 files changed, 45 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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"""
--- 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'