filectx: introduce p1/p2 convenience methods
authorMatt Mackall <mpm@selenic.com>
Mon, 04 Apr 2011 16:21:57 -0500
changeset 13877 653121e6941f
parent 13876 10c7d92ac482
child 13878 a8d13ee0ce68
filectx: introduce p1/p2 convenience methods
mercurial/context.py
--- a/mercurial/context.py	Mon Apr 04 15:52:55 2011 -0500
+++ b/mercurial/context.py	Mon Apr 04 16:21:57 2011 -0500
@@ -402,6 +402,15 @@
         return [filectx(self._repo, p, fileid=n, filelog=l)
                 for p, n, l in pl if n != nullid]
 
+    def p1(self):
+        return self.parents()[0]
+
+    def p2(self):
+        p = self.parents()
+        if len(p) == 2:
+            return p[1]
+        return filectx(self._repo, self._path, fileid=-1, filelog=self._filelog)
+
     def children(self):
         # hard for renames
         c = self._filelog.children(self._filenode)