Patchwork [2,of,6] revset: refactor parents() into a single return point

login
register
mail settings
Submitter Pierre-Yves David
Date Sept. 18, 2014, 9:40 p.m.
Message ID <fd7037c893a0471fee39.1411076455@marginatus.alto.octopoid.net>
Download mbox | patch
Permalink /patch/5873/
State Accepted
Headers show

Comments

Pierre-Yves David - Sept. 18, 2014, 9:40 p.m.
# HG changeset patch
# User Pierre-Yves David <pierre-yves.david@fb.com>
# Date 1411008243 25200
#      Wed Sep 17 19:44:03 2014 -0700
# Node ID fd7037c893a0471fee398c230b4b7a247ae5a561
# Parent  a49c721cc8d57a107cb883ee1dc3406183a70e1a
revset: refactor parents() into a single return point

Both path are doing similar thing at the end. We refactor the function so that
the `ps` set is commonly used at the end.

This will end excluding `nullrev` from this set in a future patch

Patch

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -1229,17 +1229,16 @@  def p2(repo, subset, x):
 def parents(repo, subset, x):
     """``parents([set])``
     The set of all parents for all changesets in set, or the working directory.
     """
     if x is None:
-        ps = tuple(p.rev() for p in repo[x].parents())
-        return subset & ps
-
-    ps = set()
-    cl = repo.changelog
-    for r in getset(repo, spanset(repo), x):
-        ps.update(cl.parentrevs(r))
+        ps = set(p.rev() for p in repo[x].parents())
+    else:
+        ps = set()
+        cl = repo.changelog
+        for r in getset(repo, spanset(repo), x):
+            ps.update(cl.parentrevs(r))
     return baseset(ps) & subset
 
 def parentspec(repo, subset, x, n):
     """``set^0``
     The set.