[PATCH stable] convert.cvs: Initialize state variable

Mads Kiilerich mads at kiilerich.com
Wed Mar 24 11:32:13 CDT 2010


On 03/24/2010 05:07 PM, Frank Kingswood wrote:
> Mads Kiilerich wrote:
>> How about something like
>>
>> diff --git a/hgext/convert/cvs.py b/hgext/convert/cvs.py
>> --- a/hgext/convert/cvs.py
>> +++ b/hgext/convert/cvs.py
>> @@ -226,7 +226,8 @@
>> self.writep.write("Directory .\n%s\nco\n" % self.realroot)
>> self.writep.flush()
>>
>> - data = ""
>> + data = None
>> + mode = ""
>> while 1:
>> line = self.readp.readline()
>> if line.startswith("Created ") or line.startswith("Updated "):
>> @@ -244,6 +245,8 @@
>> data = chunkedread(self.readp, count)
>> else:
>> if line == "ok\n":
>> + if data is None:
>> + raise util.Abort(_('CVS response "ok" without data'))
>> return (data, "x" in mode and "x" or "")
>
> That creates a new problem in cases where we hit
> data += line[1:]
> (when data is None)

Right. That would be just ugly as using the uninitialized variable.

My reasoning was that that "never" happens because it would have to go 
to the Created/Updated case afterwards to set mode and thus also drop 
all the data we just carefully collected. Famous last wo

> +                    if mode is None:
> +                        raise util.Abort(_('malformed response from CVS'))

It seems a bit ugly to overload "mode" to indicate whether "data" is 
valid, but this suggestion makes the code more explicit and handles the 
case as good as currently possible.


/me wonders why there are so many programming paradigms out there, but 
AFAICS there is no obvious or high-profile way to create state machines 
with clear state-dependent invariants ...

/Mads


More information about the Mercurial-devel mailing list