[BUG] transport/memory.py doesn't handle strings
Aaron Bentley
aaron.bentley at utoronto.ca
Wed Oct 19 07:06:07 BST 2005
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
John A Meinel wrote:
> Aaron Bentley wrote:
>
>>Robert Collins wrote:
>>
>>
>>>>On Tue, 2005-10-18 at 16:45 -0500, John A Meinel wrote:
>>>>
>>>>
>>>>
>>>>>There are a couple of changes that should be made to the
>>>>>transport/memory.py implementation.
>>>>>First, most of the "put" functions can take either a file-like object, or
>>>>>a string. Which means that MemoryTransport.put() shouldn't just call
>>>>>read(), it should also check to see if it is already a string. (Either
>>>>>that, or we can change the api if you really prefer).
>>>>
>>>>
>>>>I think that the ambigious api is very strange. I'd much rather have
>>>>explict put_stream, put_string etc.
>
>
> I don't think it is that ambiguous. Either it is a string, or it is
> considered to be a filelike object.
>
>
>>
>>I'd rather have put_iterable, because files are iterables of strings,
>>but so are lists, and so are strings. So all of these have the same result:
>
>
> Honestly, I think we only have strings and files. Strings because in
> lots of places you know the complete content of the file (such as when
> creating some of the control files in .bzr/).
>
> I think it is pretty rare that you want to put a list of strings into a
> file. And if you did, you could just do "put(''.join(lst))"
For files, it's fine. But I don't think it's okay to require us to hold
arbitrarily long strings in memory as we pass them to the file. If we
pass an iterator, it can produce the content as it's needed, the way we
handle file texts in the changeset code
I'm already using IterableFile with put in the central branch code, it's
just that it seems silly to have to adapt an iterator to supply a bunch
of operations that are never used.
> I believe that inside most put() functions, it would do exactly that.
> (Since you don't want to push a remote file 1 line at a time, at least
> in most cases, but certainly not 1 byte at a time).
Everything is buffered. I wouldn't be surprised if you couldn't see the
difference.
> Actually, there should be a test that transport.get('a/something') ==
> transport.clone('a').get('something')
Point.
Aaron
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.1 (GNU/Linux)
Comment: Using GnuPG with Thunderbird - http://enigmail.mozdev.org
iD8DBQFDVeJP0F+nu1YWqI0RAjRoAJ9pcBYiLcT3uvmSHmfY71BflxyynwCfQXiv
ebPZzkSub6a2X/QU2fREcR0=
=fgPH
-----END PGP SIGNATURE-----
More information about the bazaar
mailing list