revset: move lookup of first ancestor() candidate out of the loop
authorYuya Nishihara <yuya@tcha.org>
Sat, 16 Jun 2018 23:26:40 +0900
changeset 38490 5d88fd1bc2af
parent 38489 626d29c6e987
child 38491 72286f9e324f
revset: move lookup of first ancestor() candidate out of the loop
mercurial/revset.py
--- a/mercurial/revset.py	Sat Jun 16 23:21:47 2018 +0900
+++ b/mercurial/revset.py	Sat Jun 16 23:26:40 2018 +0900
@@ -311,14 +311,15 @@
     Will return empty list when passed no args.
     Greatest common ancestor of a single changeset is that changeset.
     """
-    anc = None
-    for r in orset(repo, fullreposet(repo), x, order=anyorder):
-        if anc is None:
-            anc = repo[r]
-        else:
-            anc = anc.ancestor(repo[r])
+    reviter = iter(orset(repo, fullreposet(repo), x, order=anyorder))
+    try:
+        anc = repo[next(reviter)]
+    except StopIteration:
+        return baseset()
+    for r in reviter:
+        anc = anc.ancestor(repo[r])
 
-    if anc is not None and anc.rev() in subset:
+    if anc.rev() in subset:
         return baseset([anc.rev()])
     return baseset()