[MERGE] bzrlib.osutils fixes

John Arbash Meinel john at arbash-meinel.com
Sun Mar 11 15:12:40 GMT 2007


-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1

Andrew Bennetts wrote:
> Robert Collins wrote:
> [...]
>> Theres another possible with with using named variables; we have a bit
>> of an ugly smell around file kinds at the moment: they are strings, and
>> you call functions to get things related to those strings. The actual
>> strings are rarely printed anywhere though.
>>
>> Perhaps we could instead have:
>>
>> class PathKind(object):
>>     
>>     def __init__(self, marker, versionable):
>>         self.marker = marker
>>         self.versionable = versionable
>>
>>
>> kind_directory = PathKind('/', True)
>> kind_file = PathKind('', True)
>> kind_link = PathKind('@', True)
>> kind_socket = PathKind('$', False)
>> ...
>>
>> 'foo is kind_directory' will work, as will 'foo is not kind_directory'
>> and 'foo in (kind_directory, kind_file)' etc.
> 
> (Don't you wish python had a "is in" operator?  I know I do sometimes...)
> 
> This looks like a good solution.  The "is" operator should be just as fast
> regardless of the type of object involved (it's just comparing two pointers,
> basically), and having the 'marker' and 'versionable' attributes sounds like a
> good readability win.
> 
> -Andrew.

The downside is just in parsing. So now you have to map things rather
than just reading them. So we should at least know what the performance
effect is on DirState if we have to convert from our single character to
an object. But we don't have to *create* the object, so I don't think it
will kill us. But it is another function call and hash lookup in a
critical loop.

Also, there is the need for a C extension to grab the Python object, so
that it can return it. Which is certainly possible, just more difficult
than passing around python basic types. (I'm guessing that pyrex makes
this a lot easier, though).

John
=:->

-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.3 (GNU/Linux)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org

iD8DBQFF9BxoJdeBCYSNAAMRAhyBAKCTlSQ4dcgjNbYw4V8Cj6b0c1wajQCfY//6
bhbO9f2gS23Ss1FSCrb6SnQ=
=qP14
-----END PGP SIGNATURE-----



More information about the bazaar mailing list