revsets: let parents() return parents of working dir
authorKevin Bullock <kbullock@ringworld.org>
Thu, 04 Nov 2010 17:09:00 -0500
changeset 12929 515c2786e1cf
parent 12928 a5f7f1e9340e
child 12931 7ff1c4542b9d
child 12982 053e31626737
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.
mercurial/revset.py
tests/test-revset-dirstate-parents.t
--- a/mercurial/revset.py	Thu Nov 04 16:59:03 2010 -0500
+++ b/mercurial/revset.py	Thu Nov 04 17:09:00 2010 -0500
@@ -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):
--- a/tests/test-revset-dirstate-parents.t	Thu Nov 04 16:59:03 2010 -0500
+++ b/tests/test-revset-dirstate-parents.t	Thu Nov 04 17:09:00 2010 -0500
@@ -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