changeset 13877:653121e6941f

filectx: introduce p1/p2 convenience methods
author Matt Mackall <mpm@selenic.com>
date Mon, 04 Apr 2011 16:21:57 -0500
parents 10c7d92ac482
children a8d13ee0ce68
files mercurial/context.py
diffstat 1 files changed, 9 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- 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)