Mercurial > hg-stable
changeset 11097:9651fa5a3cbf
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
author | Steve Borho <steve@borho.org> |
---|---|
date | Tue, 04 May 2010 20:12:58 -0500 |
parents | 871088c223ec |
children | 380ab78dbd69 |
files | mercurial/context.py |
diffstat | 1 files changed, 9 insertions(+), 1 deletions(-) [+] |
line wrap: on
line diff
--- a/mercurial/context.py Wed May 05 14:02:45 2010 +0200 +++ 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,14 @@ 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() + if ctx2 is not None and not isinstance(ctx2, changectx): + ctx2 = self._repo[ctx2] + 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."""