hgext3rd/topic/revset.py
changeset 4061 ad4194399b47
parent 4060 54eade86ac31
child 4063 00c65abf99cd
--- a/hgext3rd/topic/revset.py	Thu Aug 30 20:21:17 2018 +0800
+++ b/hgext3rd/topic/revset.py	Thu Aug 30 21:05:17 2018 +0800
@@ -30,8 +30,6 @@
 
     If `string` starts with `re:` the remainder of the name is treated
     as a regular expression.
-
-    TODO: make `topic(revset)` work the same as `branch(revset)`.
     """
     args = revset.getargs(x, 0, 1, 'topic takes one or no arguments')
 
@@ -46,9 +44,7 @@
         # not a string, but another revset
         pass
     else:
-        if topic == '.':
-            topic = repo['.'].extra().get('topic', '')
-        _kind, _pattern, matcher = mkmatcher(topic)
+        kind, pattern, matcher = mkmatcher(topic)
 
         def matches(r):
             topic = repo[r].topic()
@@ -56,7 +52,22 @@
                 return False
             return matcher(topic)
 
-        if True:
+        if kind == 'literal':
+            # note: falls through to the revset case if no topic with this name
+            # exists and pattern kind is not specified explicitly
+
+            alltopics = set([repo.currenttopic])
+            for r in repo.unfiltered().set('all()'):
+                alltopics.add(r.topic(force=True))
+            alltopics.discard('')
+
+            if pattern in alltopics:
+                return (subset & mutable).filter(matches)
+
+            if topic.startswith('literal:'):
+                raise error.RepoLookupError("topic '%s' does not exist"
+                                            % pattern)
+        else:
             return (subset & mutable).filter(matches)
 
     s = revset.getset(repo, revset.fullreposet(repo), x)