[PATCH 07 of 19] context: add _generatestatus method

Pierre-Yves David pierre-yves.david at ens-lyon.org
Thu May 15 22:50:35 CDT 2014



On 05/15/2014 05:48 PM, Sean Farley wrote:
>
> Pierre-Yves David <pierre-yves.david at ens-lyon.org> writes:
>
>> On 05/15/2014 02:16 PM, Sean Farley wrote:
>>> # HG changeset patch
>>> # User Sean Farley <sean.michael.farley at gmail.com>
>>> # Date 1398134136 18000
>>> #      Mon Apr 21 21:35:36 2014 -0500
>>> # Node ID 1ae1f9895dc54cceeafa95e095f19f936917d2fd
>>> # Parent  d49a306617e4a3fad4587c8e30ee71b80767011f
>>> context: add _generatestatus method
>>>
>>> This method is a copy of localstatus.status's core logic.
>>>
>>> diff --git a/mercurial/context.py b/mercurial/context.py
>>> --- a/mercurial/context.py
>>> +++ b/mercurial/context.py
>>> @@ -70,10 +70,35 @@ class basectx(object):
>>>            for fn in mf.keys():
>>>                if not match(fn):
>>>                    del mf[fn]
>>>            return mf
>>>
>>> +    def _generatestatus(self, other, s, match, listignored, listclean,
>>> +                        listunknown):
>>> +        """generate a status with respect to another context"""
>>> +        mf1 = other._manifestmatches(match, s)
>>> +        mf2 = self._manifestmatches(match, s)
>>> +
>>> +        modified, added, clean = [], [], []
>>> +        deleted, unknown, ignored = s[3], [], []
>>> +        withflags = mf1.withflags() | mf2.withflags()
>>> +        for fn, mf2node in mf2.iteritems():
>>> +            if fn in mf1:
>>> +                if (fn not in deleted and
>>> +                    ((fn in withflags and mf1.flags(fn) != mf2.flags(fn)) or
>>> +                     (mf1[fn] != mf2node and
>>> +                      (mf2node or self[fn].cmp(other[fn]))))):
>>
>>
>> note: This if statement is very awful. I know it is not yours but If you
>> find time to clean it up someday; that would be great.
>
> Indeed it is awful :-( I will have to clean it up when memctx learns how
> to compare its manifest with other non-memctx objects. But that's many
> patch series away (need memctx to inherit from committablectx first)

There is two things here:

1. The amount of condition would scare a moose as good as look at mq 
source code.

2. The fact it is spawn on not one, not two, not three, but, ladies and 
gentlemen, four lines.

On that case, one can use a new and shiny variable available in Python: 
variables. Prebuilding the condition explicitly possibly with a few new 
line madness but also with a bit more freedom on the identation.

Anyway, this was awful before, so this patch can keep this abomination 
onboard. If you feel like it, you can clean it up in a follow up patches.

-- 
Pierre-Yves David


More information about the Mercurial-devel mailing list