[PATCH 2 of 2] revsets: let parents() return parents of working dir

Kevin Bullock kbullock+mercurial at ringworld.org
Thu Nov 4 17:09:53 CDT 2010


# HG changeset patch
# User Kevin Bullock <kbullock at ringworld.org>
# Date 1288908540 18000
# Node ID 820374004b0a39382d3bdc509d299f6788132706
# Parent  8b88770f6880f1b8ac0fc3700ab592ff027ef704
revsets: let parents() return parents of working dir

This patch makes the 'set' argument to revset function parents() optional.
Like p1() and p2(), if no argument is given, returns the parent(s) of the
working directory.

Morally equivalent to 'p1()+p2()', as expected.

diff --git a/mercurial/revset.py b/mercurial/revset.py
--- a/mercurial/revset.py
+++ b/mercurial/revset.py
@@ -232,9 +232,13 @@
     return [r for r in subset if r in ps]
 
 def parents(repo, subset, x):
-    """``parents(set)``
-    The set of all parents for all changesets in set.
+    """``parents([set])``
+    The set of all parents for all changesets in set, or the working directory.
     """
+    repo.ui.debug(repr(x), '\n')
+    if x is None:
+        return [r.rev() for r in repo[x].parents()]
+
     ps = set()
     cl = repo.changelog
     for r in getset(repo, range(len(repo)), x):
diff --git a/tests/test-revset-dirstate-parents.t b/tests/test-revset-dirstate-parents.t
--- a/tests/test-revset-dirstate-parents.t
+++ b/tests/test-revset-dirstate-parents.t
@@ -21,6 +21,7 @@
 null revision
   $ log 'p1()'
   $ log 'p2()'
+  $ log 'parents()'
 
 working dir with a single parent
   $ echo a > a
@@ -28,6 +29,8 @@
   $ log 'p1()'
   0
   $ log 'p2()'
+  $ log 'parents()'
+  0
 
 merge in progress
   $ echo b > b
@@ -40,3 +43,6 @@
   2
   $ log 'p2()'
   1
+  $ log 'parents()'
+  2
+  1


More information about the Mercurial-devel mailing list