[PATCH RFC] context: add a changectx.diff() convenience function

Steve Borho steve at borho.org
Tue May 4 20:14:10 CDT 2010


# HG changeset patch
# User Steve Borho <steve at borho.org>
# Date 1273021978 18000
# Node ID 0307e0a504c4e38ffdfbf4e1967411c82fe1ecee
# Parent  b27a43eceda363147902532d9fc0354fa5c222bc
context: add a changectx.diff() convenience function

With this function, extracting diffs becomes trivial:

repo = hg.repository(ui.ui(), path=root)
ctx = repo['tip']
for out in ctx.diff():  print out

diff -r b27a43eceda3 -r 0307e0a504c4 mercurial/context.py
--- a/mercurial/context.py	Tue May 04 08:39:11 2010 -0300
+++ b/mercurial/context.py	Tue May 04 20:12:58 2010 -0500
@@ -7,7 +7,7 @@
 
 from node import nullid, nullrev, short, hex
 from i18n import _
-import ancestor, bdiff, error, util, subrepo
+import ancestor, bdiff, error, util, subrepo, patch
 import os, errno
 
 propertycache = util.propertycache
@@ -204,6 +204,12 @@
     def sub(self, path):
         return subrepo.subrepo(self, path)
 
+    def diff(self, ctx2=None, match=None):
+        """Returns a diff generator for the given contexts and matcher"""
+        if ctx2 is None:
+            ctx2 = self.p1()
+        return patch.diff(self._repo, ctx2.node(), self.node(), match=match)
+
 class filectx(object):
     """A filecontext object makes access to data related to a particular
        filerevision convenient."""


More information about the Mercurial-devel mailing list