diff hgext3rd/topic/revset.py @ 4095:aabf436c11cb

topic: refactor revset.py slightly Checking both kind == 'literal' and topic.startswith('literal:') seems to be redundant, because of how stringutil.stringmatcher() works.
author Anton Shestakov <av6@dwimlabs.net>
date Tue, 04 Sep 2018 19:30:19 +0800
parents a2c0133006c6
children 09337aae08d4
line wrap: on
line diff
--- a/hgext3rd/topic/revset.py	Wed Sep 12 12:02:17 2018 +0200
+++ b/hgext3rd/topic/revset.py	Tue Sep 04 19:30:19 2018 +0800
@@ -24,7 +24,7 @@
 revsetpredicate = registrar.revsetpredicate()
 
 def getstringstrict(x, err):
-    if x and (x[0] == 'string'):
+    if x and x[0] == 'string':
         return x[1]
     raise error.ParseError(err)
 
@@ -51,25 +51,19 @@
     else:
         kind, pattern, matcher = mkmatcher(topic)
 
+        if topic.startswith('literal:') and pattern not in repo.topics:
+            raise error.RepoLookupError("topic '%s' does not exist" % pattern)
+
         def matches(r):
             topic = repo[r].topic()
             if not topic:
                 return False
             return matcher(topic)
 
-        if kind == 'literal':
-            # note: falls through to the revset case if no topic with this name
-            # exists and pattern kind is not specified explicitly
-
-            if pattern not in repo.topics and topic.startswith('literal:'):
-                raise error.RepoLookupError("topic '%s' does not exist"
-                                            % pattern)
-            return (subset & mutable).filter(matches)
-        else:
-            return (subset & mutable).filter(matches)
+        return (subset & mutable).filter(matches)
 
     s = revset.getset(repo, revset.fullreposet(repo), x)
-    topics = set(repo[r].topic() for r in s)
+    topics = {repo[r].topic() for r in s}
     topics.discard('')
 
     def matches(r):