changeset 8406:6ad1f72bdf34

context: add p1 and p2 methods
author Matt Mackall <mpm@selenic.com>
date Thu, 14 May 2009 13:20:40 -0500
parents 7cbf8fcd2453
children 223000a687b0
files mercurial/context.py
diffstat 1 files changed, 11 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/mercurial/context.py	Thu May 14 13:20:40 2009 -0500
+++ b/mercurial/context.py	Thu May 14 13:20:40 2009 -0500
@@ -101,6 +101,14 @@
         """return contexts for each parent changeset"""
         return self._parents
 
+    def p1(self):
+        return self._parents[0]
+
+    def p2(self):
+        if len(self._parents) == 2:
+            return self._parents[1]
+        return changectx(self._repo, -1)
+
     def children(self):
         """return contexts for each child changeset"""
         c = self._repo.changelog.children(self._node)
@@ -750,6 +758,9 @@
     def __getitem__(self, key):
         return self.filectx(key)
 
+    def p1(self): return self._parents[0]
+    def p2(self): return self._parents[1]
+
     def user(self): return self._user or self._repo.ui.username()
     def date(self): return self._date
     def description(self): return self._text
@@ -800,4 +811,3 @@
     def isexec(self): return 'x' in self._flags
     def islink(self): return 'l' in self._flags
     def renamed(self): return self._copied
-