comparison 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
comparison
equal deleted inserted replaced
6876:2edffcd94850 6877:f8ea46c21b56
378 except IndexError: 378 except IndexError:
379 # Lets move to the last ctx of the current topic 379 # Lets move to the last ctx of the current topic
380 return None 380 return None
381 context.basectx.topicidx = _contexttopicidx 381 context.basectx.topicidx = _contexttopicidx
382 382
383 def _contextfqbn(self, short=True): 383 def _contextfqbn(self, length=common.FQBN_NORMAL):
384 """return branch//namespace/topic of the changeset, also known as fully 384 """return branch//namespace/topic of the changeset, also known as fully
385 qualified branch name 385 qualified branch name
386 """ 386 """
387 branch = encoding.tolocal(self.extra()[b'branch']) 387 branch = encoding.tolocal(self.extra()[b'branch'])
388 return common.formatfqbn(branch, self.topic_namespace(), self.topic(), short=short) 388 return common.formatfqbn(branch, self.topic_namespace(), self.topic(), length=length)
389 389
390 context.basectx.fqbn = _contextfqbn 390 context.basectx.fqbn = _contextfqbn
391 391
392 stackrev = re.compile(br'^s\d+$') 392 stackrev = re.compile(br'^s\d+$')
393 topicrev = re.compile(br'^t\d+$') 393 topicrev = re.compile(br'^t\d+$')
972 vfs.tryunlink(b'topic-namespace') 972 vfs.tryunlink(b'topic-namespace')
973 ce = self._filecache[b'_tns'] 973 ce = self._filecache[b'_tns']
974 if ce: 974 if ce:
975 ce.refresh() 975 ce.refresh()
976 976
977 def fqbn(self, short=True): 977 def fqbn(self, length=common.FQBN_NORMAL):
978 branch = encoding.tolocal(self._branch) 978 branch = encoding.tolocal(self._branch)
979 tns = encoding.tolocal(self._tns) 979 tns = encoding.tolocal(self._tns)
980 topic = encoding.tolocal(self._topic) 980 topic = encoding.tolocal(self._topic)
981 return common.formatfqbn(branch, tns, topic, short=short) 981 return common.formatfqbn(branch, tns, topic, length=length)
982 982
983 dirstate.dirstate = topicdirstate 983 dirstate.dirstate = topicdirstate
984 984
985 templatekeyword = registrar.templatekeyword() 985 templatekeyword = registrar.templatekeyword()
986 986
1981 fm.write(b'topic_namespace', b'namespace: %s\n', tns) 1981 fm.write(b'topic_namespace', b'namespace: %s\n', tns)
1982 fm.write(b'topic', b'topic: %s\n', topic) 1982 fm.write(b'topic', b'topic: %s\n', topic)
1983 fm.end() 1983 fm.end()
1984 1984
1985 @command(b'debug-format-fqbn', [ 1985 @command(b'debug-format-fqbn', [
1986 (b'b', b'branch', b'', b'branch'), 1986 (b'b', b'branch', b'', b'branch', b'BRANCH'),
1987 (b'n', b'topic-namespace', b'', b'topic namespace'), 1987 (b'n', b'topic-namespace', b'', b'topic namespace', b'TNS'),
1988 (b't', b'topic', b'', b'topic'), 1988 (b't', b'topic', b'', b'topic', b'TOPIC'),
1989 (b's', b'short', True, b'short format'), 1989 (b'l', b'length', b'normal', b'length (short, normal, or full)', b'LENGTH'),
1990 ], optionalrepo=True) 1990 ], optionalrepo=True)
1991 def debugformatfqbn(ui, repo, **opts): 1991 def debugformatfqbn(ui, repo, **opts):
1992 """format branch, namespace and topic into branch//namespace/topic string""" 1992 """format branch, namespace and topic into branch//namespace/topic string"""
1993 short = common.formatfqbn(opts.get('branch'), opts.get('topic_namespace'), opts.get('topic'), opts.get('short')) 1993 length = opts['length']
1994 ui.write(b'%s\n' % short) 1994 if length == b'short':
1995 length = common.FQBN_SHORT
1996 elif length == b'normal':
1997 length = common.FQBN_NORMAL
1998 elif length == b'full':
1999 length = common.FQBN_FULL
2000 else:
2001 raise compat.InputError(b"invalid --length value: %s" % length)
2002 fqbn = common.formatfqbn(opts.get('branch'), opts.get('topic_namespace'), opts.get('topic'), length=length)
2003 ui.write(b'%s\n' % fqbn)