Mercurial > evolve
diff hgext3rd/topic/common.py @ 6237:0b9042408809
topic: formatting branch, namespace and topic into fully qualified branch name
author | Anton Shestakov <av6@dwimlabs.net> |
---|---|
date | Tue, 03 May 2022 21:46:23 +0400 |
parents | 7ad8107d953a |
children | 945d27da146c |
line wrap: on
line diff
--- a/hgext3rd/topic/common.py Tue May 03 21:35:28 2022 +0400 +++ b/hgext3rd/topic/common.py Tue May 03 21:46:23 2022 +0400 @@ -41,3 +41,33 @@ # when there's no / in the rest of the string, there can only be topic tns, topic = b'default', tns return branch, tns, topic + +def formatfqbn(branch=b'', namespace=b'', topic=b''): + """format branch, namespace and topic into branch//namespace/topic string + + >>> formatfqbn(branch=b'branch', topic=b'topic') + 'branch//topic' + >>> formatfqbn(namespace=b'namespace', topic=b'topic') + '//namespace/topic' + >>> formatfqbn(branch=b'branch') + 'branch' + >>> formatfqbn(namespace=b'namespace') + '//namespace/' + >>> formatfqbn(branch=b'/topic') + '/topic' + >>> formatfqbn(topic=b'topic') + '//topic' + >>> formatfqbn(branch=b'branch', namespace=b'namespace', topic=b'topic') + 'branch//namespace/topic' + >>> formatfqbn(branch=b'foo/bar', namespace=b'user26', topic=b'feature') + 'foo/bar//user26/feature' + """ + result = b'' + if branch: + result += branch + if namespace or topic: + result += b'//' + if namespace: + result += namespace + b'/' + result += topic + return result