Patchwork [2,of,3] revset: leverage orset() to flatten ancestor() arguments

login
register
mail settings
Submitter Yuya Nishihara
Date June 28, 2018, 1:42 p.m.
Message ID <fe4560fa5db2f1ee11cf.1530193375@mimosa>
Download mbox | patch
Permalink /patch/32481/
State Accepted
Headers show

Comments

Yuya Nishihara - June 28, 2018, 1:42 p.m.
# HG changeset patch
# User Yuya Nishihara <yuya@tcha.org>
# Date 1529158907 -32400
#      Sat Jun 16 23:21:47 2018 +0900
# Node ID fe4560fa5db2f1ee11cff233c55b7685e891517a
# Parent  5e1defd9170e93dea28ea06abc22a2959cd4b707
revset: leverage orset() to flatten ancestor() arguments

This also makes orset() accept an empty argument because nullary ancestor()
call is valid. That's not the case for orset(), but should be okay.

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -203,6 +203,8 @@  def _orsetlist(repo, subset, xs, order):
 
 def orset(repo, subset, x, order):
     xs = getlist(x)
+    if not xs:
+        return baseset()
     if order == followorder:
         # slow path to take the subset order
         return subset & _orsetlist(repo, fullreposet(repo), xs, anyorder)
@@ -309,17 +311,12 @@  def ancestor(repo, subset, x):
     Will return empty list when passed no args.
     Greatest common ancestor of a single changeset is that changeset.
     """
-    l = getlist(x)
-    rl = fullreposet(repo)
     anc = None
-
-    # (getset(repo, rl, i) for i in l) generates a list of lists
-    for revs in (getset(repo, rl, i) for i in l):
-        for r in revs:
-            if anc is None:
-                anc = repo[r]
-            else:
-                anc = anc.ancestor(repo[r])
+    for r in orset(repo, fullreposet(repo), x, order=anyorder):
+        if anc is None:
+            anc = repo[r]
+        else:
+            anc = anc.ancestor(repo[r])
 
     if anc is not None and anc.rev() in subset:
         return baseset([anc.rev()])