[PATCH] keyword: pass context to kwtemplater.overwrite

Christian Ebert blacktrash at gmx.net
Wed Jun 9 05:02:15 CDT 2010


* Martin Geisler on Tuesday, June 08, 2010 at 13:59:23 +0200
> Christian Ebert <blacktrash at gmx.net> writes:
>> # HG changeset patch
>> # User Christian Ebert <blacktrash at gmx.net>
>> # Date 1275954002 -3600
>> # Node ID 6e94857052f709d104fe967d270376705ad9ae92
>> # Parent  3d0591a661189bcb0a5e8ef3393c59ecd7e42f79
>> keyword: pass context to kwtemplater.overwrite
>> 
>> Now that we have retrieved the context in every calling function
>> except commit, pass it as argument to kwtemplater.overwrite to
>> avoid looking it up twice.
> 
> Perhaps the node argument should go then?

The expand argument /could/ go as well. However this is sort of
reverting the direction of this change: to pass all information
that is known to the calling function in the arguments.

It could look like this (detect kwexpand/kwshrink inside
overwrite()):

    def overwrite(self, ctx, candidates):
        '''Overwrites selected files expanding/shrinking keywords.'''
        mf = ctx.manifest()
        if self.record:
            candidates = [f for f in ctx.files() if f in mf]
        candidates = [f for f in candidates if self.iskwfile(f, ctx.flags)]
        if candidates:
            iswctx = ctx.node() is None # kwexpand/kwshrink
            expand = kwtools['hgcmd'] != 'kwshrink'
            ...


Or like this (use info known to calling function):

    def overwrite(self, ctx, candidates, expand, iswctx):
        '''Overwrites selected files expanding/shrinking keywords.'''
        mf = ctx.manifest()
        if self.record:
            candidates = [f for f in ctx.files() if f in mf]
        candidates = [f for f in candidates if self.iskwfile(f, ctx.flags)]
        if candidates:
            ...

where iswctx or kwcall or whatever would be a plain boolean.

What do you think?

c
-- 
theatre - books - texts - movies
Black Trash Productions at home: http://www.blacktrash.org/
Black Trash Productions on Facebook:
http://www.facebook.com/blacktrashproductions


More information about the Mercurial-devel mailing list