[PATCH] merge3 fails with python2.3

John A Meinel john at arbash-meinel.com
Wed Jul 6 01:50:46 BST 2005


John A Meinel wrote:

> Martin Pool wrote:
>
>> My bzr tree now has some code in bzrlib.merge3 to do a 3-way text
>> merge in pure Python.  I think(?) this might remove the main external
>> dependency, aside from patch for importing changesets, which I hope we
>> can also fix.  I think it works.  Comments or bug reports are welcome.
>>
>>
>>
> BUG!! In python2.3 merge3.py currently does not write out lines if MINE
> has a tail.

I found the bug. It turns out that the way iterables work with python2.3
is different than with python2.4
It seems that doing:

aiter = iter(SequenceMatcher(None, self.base, self.a).get_matching_blocks())

In python2.4 these evaluate to False when they run out of entries, so:

while aiter:
    aiter.next()

Will loop properly. But in python2.3, they do not evaluate to False,
instead raising a StopIteration exception. So it basically becomes:

while True:
    aiter.next() # This raises a StopIteration exception, which won't be
caught by the while

I assume this is because they were designed to work with for loops only.

The attached patch just catches the final exception, and makes the loop
stop. Now, I don't know what values are actually returned in the
'next()' statement, but everything seems to work.

Is there a reason to do "while aiter and biter:"? I assume because you
only want to call 'next()' on one of them, not both like 'zip()' would do.

Anyway, use the patch, and things will work on python2.3

John
=:->

PS> Why don't all the tests run with python2.3? I have subprocess installed
-------------- next part --------------
A non-text attachment was scrubbed...
Name: merge3-fix-iteration.patch
Type: text/x-patch
Size: 990 bytes
Desc: not available
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20050705/18d973de/attachment.bin 
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 253 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20050705/18d973de/attachment.pgp 


More information about the bazaar mailing list