# HG changeset patch # User Anton Shestakov # Date 1651599328 -14400 # Node ID 7ad8107d953ac82b31e0a8217cb5c3c3a8518aa4 # Parent 318b81560f8cb5a1b661c9d439185b521ba53352 topic: introduce topic namespaces concept starting with simple parsing diff -r 318b81560f8c -r 7ad8107d953a hgext3rd/topic/__init__.py --- a/hgext3rd/topic/__init__.py Thu May 12 20:02:40 2022 +0400 +++ b/hgext3rd/topic/__init__.py Tue May 03 21:35:28 2022 +0400 @@ -1500,3 +1500,15 @@ # Restore the topic if need if topic: _changecurrenttopic(repo, topic) + +@command(b'debug-parse-fqbn', commands.formatteropts, _(b'FQBN'), optionalrepo=True) +def debugparsefqbn(ui, repo, fqbn, **opts): + """parse branch//namespace/topic string into its components""" + branch, tns, topic = common.parsefqbn(fqbn) + opts = pycompat.byteskwargs(opts) + fm = ui.formatter(b'debug-parse-namespace', opts) + fm.startitem() + fm.write(b'branch', b'branch: %s\n', branch) + fm.write(b'topic_namespace', b'namespace: %s\n', tns) + fm.write(b'topic', b'topic: %s\n', topic) + fm.end() diff -r 318b81560f8c -r 7ad8107d953a hgext3rd/topic/common.py --- a/hgext3rd/topic/common.py Thu May 12 20:02:40 2022 +0400 +++ b/hgext3rd/topic/common.py Tue May 03 21:35:28 2022 +0400 @@ -6,3 +6,38 @@ def hastopicext(repo): """True if the repo use the topic extension""" return getattr(repo, 'hastopicext', False) + +def parsefqbn(string): + """parse branch//namespace/topic string into branch, namespace and topic + + >>> parsefqbn(b'branch//topic') + ('branch', 'default', 'topic') + >>> parsefqbn(b'//namespace/topic') + ('default', 'namespace', 'topic') + >>> parsefqbn(b'branch//') + ('branch', 'default', '') + >>> parsefqbn(b'//namespace/') + ('default', 'namespace', '') + >>> parsefqbn(b'/topic') + ('/topic', 'default', '') + >>> parsefqbn(b'//topic') + ('default', 'default', 'topic') + >>> parsefqbn(b'branch//namespace/topic') + ('branch', 'namespace', 'topic') + >>> parsefqbn(b'file:///tmp/branch//') + ('file:///tmp/branch', 'default', '') + >>> parsefqbn(b'http://example.com/branch//namespace/topic') + ('http://example.com/branch', 'namespace', 'topic') + """ + branch, sep, other = string.rpartition(b'//') + if not sep: + # when there's no // anywhere in the string, rpartition returns + # untouched string as the 3rd element, and the first two are empty + branch, other = other, b'' + if not branch: + branch = b'default' + tns, sep, topic = other.partition(b'/') + if not sep: + # when there's no / in the rest of the string, there can only be topic + tns, topic = b'default', tns + return branch, tns, topic diff -r 318b81560f8c -r 7ad8107d953a tests/test-check-sdist.t --- a/tests/test-check-sdist.t Thu May 12 20:02:40 2022 +0400 +++ b/tests/test-check-sdist.t Tue May 03 21:35:28 2022 +0400 @@ -35,7 +35,7 @@ $ tar -tzf hg-evolve-*.tar.gz | sed 's|^hg-evolve-[^/]*/||' | sort > files $ wc -l files - 358 files + 359 files $ fgrep debian files tests/test-check-debian.t $ fgrep __init__.py files diff -r 318b81560f8c -r 7ad8107d953a tests/test-doctest.py --- a/tests/test-doctest.py Thu May 12 20:02:40 2022 +0400 +++ b/tests/test-doctest.py Tue May 03 21:35:28 2022 +0400 @@ -110,6 +110,7 @@ expected_mods_tested = set( [ ('hgext3rd.evolve.obshistory', '{}'), + ('hgext3rd.topic.common', '{}'), ] ) diff -r 318b81560f8c -r 7ad8107d953a tests/test-namespaces.t --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/tests/test-namespaces.t Tue May 03 21:35:28 2022 +0400 @@ -0,0 +1,14 @@ +https://www.mercurial-scm.org/wiki/TopicPlan#sub_branches.2C_namespacing_and_representation + + $ . "$TESTDIR/testlib/topic_setup.sh" + +Parsing + + $ hg debugparsefqbn foo/bar//user26/feature -T '[{branch}] <{topic_namespace}> ({topic})\n' + [foo/bar] (feature) + +no double slashes means it's a named branch + $ hg debug-parse-fqbn foo/bar + branch: foo/bar + namespace: default + topic: