diff hgext3rd/topic/__init__.py @ 6877:f8ea46c21b56

topic: make formatfqbn() able to produce FQBN of 3 different lengths
author Anton Shestakov <av6@dwimlabs.net>
date Thu, 26 Sep 2024 17:09:11 +0400
parents 2edffcd94850
children 2fbe91d762ef
line wrap: on
line diff
--- a/hgext3rd/topic/__init__.py	Thu Sep 19 16:50:21 2024 +0400
+++ b/hgext3rd/topic/__init__.py	Thu Sep 26 17:09:11 2024 +0400
@@ -380,12 +380,12 @@
         return None
 context.basectx.topicidx = _contexttopicidx
 
-def _contextfqbn(self, short=True):
+def _contextfqbn(self, length=common.FQBN_NORMAL):
     """return branch//namespace/topic of the changeset, also known as fully
     qualified branch name
     """
     branch = encoding.tolocal(self.extra()[b'branch'])
-    return common.formatfqbn(branch, self.topic_namespace(), self.topic(), short=short)
+    return common.formatfqbn(branch, self.topic_namespace(), self.topic(), length=length)
 
 context.basectx.fqbn = _contextfqbn
 
@@ -974,11 +974,11 @@
             if ce:
                 ce.refresh()
 
-        def fqbn(self, short=True):
+        def fqbn(self, length=common.FQBN_NORMAL):
             branch = encoding.tolocal(self._branch)
             tns = encoding.tolocal(self._tns)
             topic = encoding.tolocal(self._topic)
-            return common.formatfqbn(branch, tns, topic, short=short)
+            return common.formatfqbn(branch, tns, topic, length=length)
 
     dirstate.dirstate = topicdirstate
 
@@ -1983,12 +1983,21 @@
     fm.end()
 
 @command(b'debug-format-fqbn', [
-        (b'b', b'branch', b'', b'branch'),
-        (b'n', b'topic-namespace', b'', b'topic namespace'),
-        (b't', b'topic', b'', b'topic'),
-        (b's', b'short', True, b'short format'),
+        (b'b', b'branch', b'', b'branch', b'BRANCH'),
+        (b'n', b'topic-namespace', b'', b'topic namespace', b'TNS'),
+        (b't', b'topic', b'', b'topic', b'TOPIC'),
+        (b'l', b'length', b'normal', b'length (short, normal, or full)', b'LENGTH'),
     ], optionalrepo=True)
 def debugformatfqbn(ui, repo, **opts):
     """format branch, namespace and topic into branch//namespace/topic string"""
-    short = common.formatfqbn(opts.get('branch'), opts.get('topic_namespace'), opts.get('topic'), opts.get('short'))
-    ui.write(b'%s\n' % short)
+    length = opts['length']
+    if length == b'short':
+        length = common.FQBN_SHORT
+    elif length == b'normal':
+        length = common.FQBN_NORMAL
+    elif length == b'full':
+        length = common.FQBN_FULL
+    else:
+        raise compat.InputError(b"invalid --length value: %s" % length)
+    fqbn = common.formatfqbn(opts.get('branch'), opts.get('topic_namespace'), opts.get('topic'), length=length)
+    ui.write(b'%s\n' % fqbn)