changeset 38490:5d88fd1bc2af

revset: move lookup of first ancestor() candidate out of the loop
author Yuya Nishihara <yuya@tcha.org>
date Sat, 16 Jun 2018 23:26:40 +0900
parents 626d29c6e987
children 72286f9e324f
files mercurial/revset.py
diffstat 1 files changed, 8 insertions(+), 7 deletions(-) [+]
line wrap: on
line diff
--- 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()