Patchwork [07,of,19] context: add _generatestatus method

login
register
mail settings
Submitter Sean Farley
Date May 15, 2014, 9:16 p.m.
Message ID <1ae1f9895dc54cceeafa.1400188585@laptop.local>
Download mbox | patch
Permalink /patch/4766/
State Changes Requested
Headers show

Comments

Sean Farley - May 15, 2014, 9:16 p.m.
# HG changeset patch
# User Sean Farley <sean.michael.farley@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.
Pierre-Yves David - May 16, 2014, 12:09 a.m.
On 05/15/2014 02:16 PM, Sean Farley wrote:
> # HG changeset patch
> # User Sean Farley <sean.michael.farley@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.
Sean Farley - May 16, 2014, 12:48 a.m.
Pierre-Yves David <pierre-yves.david@ens-lyon.org> writes:

> On 05/15/2014 02:16 PM, Sean Farley wrote:
>> # HG changeset patch
>> # User Sean Farley <sean.michael.farley@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)
Pierre-Yves David - May 16, 2014, 3:50 a.m.
On 05/15/2014 05:48 PM, Sean Farley wrote:
>
> Pierre-Yves David <pierre-yves.david@ens-lyon.org> writes:
>
>> On 05/15/2014 02:16 PM, Sean Farley wrote:
>>> # HG changeset patch
>>> # User Sean Farley <sean.michael.farley@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.

Patch

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]))))):
+                    modified.append(fn)
+                elif listclean:
+                    clean.append(fn)
+                del mf1[fn]
+            elif fn not in deleted:
+                added.append(fn)
+        removed = mf1.keys()
+
+        return [modified, added, removed, deleted, unknown, ignored, clean]
+
     @propertycache
     def substate(self):
         return subrepo.state(self, self._repo.ui)
 
     def rev(self):