topic: refactor revset.py slightly
authorAnton Shestakov <av6@dwimlabs.net>
Tue, 04 Sep 2018 19:30:19 +0800
changeset 4095 aabf436c11cb
parent 4094 0171a7ceb574
child 4108 ef3c9ecb8099
topic: refactor revset.py slightly Checking both kind == 'literal' and topic.startswith('literal:') seems to be redundant, because of how stringutil.stringmatcher() works.
hgext3rd/topic/revset.py
--- 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):