[PATCH RFC] context: add a changectx.diff() convenience function
Steve Borho
steve at borho.org
Wed May 5 10:25:02 CDT 2010
On Wed, May 5, 2010 at 1:29 AM, Dirkjan Ochtman <dirkjan at ochtman.nl> wrote:
> On Wed, May 5, 2010 at 03:14, Steve Borho <steve at borho.org> wrote:
>> # 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
>
> Definitely want.
>
>> 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)
>
> Maybe also add an if so that ctx2 can just be a rev or node instead? I.e.
>
> if ctx2 is not None and not isinstance(ctx2, context):
> ctx2 = self._repo[ctx2]
I pushed something similar as 9651fa5a3cbf.
--
Steve Borho
More information about the Mercurial-devel
mailing list