context: add a dirty method to detect modified contexts
authorMatt Mackall <mpm@selenic.com>
Thu, 04 Jun 2009 16:21:55 -0500
changeset 8717 e8de59577257
parent 8716 f3322bb29a0e
child 8718 3463b28681ee
context: add a dirty method to detect modified contexts
mercurial/context.py
--- a/mercurial/context.py	Thu Jun 04 16:21:09 2009 -0500
+++ b/mercurial/context.py	Thu Jun 04 16:21:55 2009 -0500
@@ -618,6 +618,13 @@
     def walk(self, match):
         return sorted(self._repo.dirstate.walk(match, True, False))
 
+    def dirty(self, missing=False):
+        "check whether a working directory is modified"
+
+        return (self.p2() or self.branch() != self.p1().branch() or
+                self.modified() or self.added() or self.removed() or
+                (missing and self.deleted()))
+
 class workingfilectx(filectx):
     """A workingfilectx object makes access to data related to a particular
        file in the working directory convenient."""