[BUG] serializer.write_inventory() != write_inventory_to_string()

John Arbash Meinel john at arbash-meinel.com
Thu Oct 20 08:04:53 BST 2005


It seems there is a small bug in how we write our xml out to a file.

I'm working on the changeset plugin, where I have the code:
        sio = StringIO()
        serializer_v5.write_inventory(inv, sio)

(this is before write_inventory_to_string() existed).

The problem is that with the above code, I get a final newline, while
the text stored inside the weave after a commit does not have one.
I'm guessing if you just do:

        sio = StringIO()
        serializer_v5.write_inventory(inv, sio)
 	assert sio.getvalue() == \
		serializer_v5.write_inventory_to_string(inv)

You would get an assertion error. I verified this by doing:

from bzrlib.branch import Branch
from bzrlib.xml5 import serializer_v5
from cStringIO import StringIO
b = Branch.open('.')
inv = b.get_inventory(b.last_revision())
sio = StringIO()
serializer_v5.write_inventory(inv, sio)
s = serializer_v5.write_inventory_to_string(inv)
s[-1] # == '>'
sio.getvalue()[-1] # == '\n'
s == sio.getvalue() # False


I've tested this on 2 different machines. I'm not sure what the
"correct" thing to do is. It seems that we are writing the revision XML
using the final newline, but we are writing the inventory using
*_to_string()

If you look at the code in xml.py, you can see that there is an extra
write('\n') statement in the code, but there is no "+ '\n'" in the
write_inventory_to_string() code.

John
=:->
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 256 bytes
Desc: OpenPGP digital signature
Url : https://lists.ubuntu.com/archives/bazaar/attachments/20051020/ad40880d/attachment.pgp 


More information about the bazaar mailing list