[MERGE] FormatRegistry

John Arbash Meinel john at arbash-meinel.com
Thu Dec 21 21:31:42 GMT 2006


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

...

>>> topic_registry.register_lazy('formats', 'bzrlib.bzrdir',
>>> 			     'format_registry.help_topic',
>>> 			      'directory formats')
>>>
>>> Though since you are nested 2 deep, that might need:
> 
> I *know* how to create a lazy wrapper.  Can do it in my sleep.
> 
> register_lazy freaks me, because I can tell it's not import.  Which
> means I have to learn something else that's not import.  So considering
> how little it does, I think using register_lazy is a net loss.


Well, IMO it is much cleaner looking to use register_lazy. Consider how
we register transports:

register_lazy_transport(None,
                        'bzrlib.transport.local',
                        'LocalTransport')

register_lazy_transport('file://',
                        'bzrlib.transport.local',
                        'LocalTransport')

register_lazy_transport('sftp://',
                        'bzrlib.transport.sftp',
                        'SFTPTransport')

register_lazy_transport('http+urllib://',
                        'bzrlib.transport.http._urllib',
                        'HttpTransport_urllib')

register_lazy_transport('https+urllib://',
                        'bzrlib.transport.http._urllib',
                        'HttpTransport_urllib')

register_lazy_transport('http+pycurl://',
                        'bzrlib.transport.http._pycurl',
                        'PyCurlTransport')

register_lazy_transport('https+pycurl://',
                        'bzrlib.transport.http._pycurl',
                        'PyCurlTransport')

If we didn't have 'register_lazy' this would be:

def get_local(base):
  import bzrlib.transport.local
  return bzrlib.transport.local.LocalTransport(base)
register_transport(None, get_local)
register_transport('file://', get_local)

def get_sftp(base):
  import bzrlib.transport.sftp
  return bzrlib.transport.sftp.SFTPTransport(base)
register_transport('sftp://', get_sftp)

def get_http_urllib(base):
  import bzrlib.transport.http._urllib
  return bzrlib.transport.http._urllib.HTTPTransport_urllib(base)
register_transport('http+urllib://', get_http_urllib)
...


We have 23 Transports that are registered in a lazy fashion. That is 23
helper functions that you have to write, versus just saying "look here
for it".

...

> 
> I certainly considered that option.  But my conclusion was that they are
> two different lists.  If it was simply about attaching help text, I
> certainly would have worked on turning BzrDir._control_formats into a
> registry, instead.
> 
> But BzrDir._control_formats is not intended as a list of subformats.  I
> think it would do a very poor job as one.

After reading your discussion, I agree with you. Keeping it separate
makes sense.


...

v- I thought the whole point of passing "default" was because you wanted
it to explicitly exist in the list. It seems you are changing it here,
which means that if something changes the registered "default", it still
won't use it.

 def get_format_type(typestring):
     """Parse and return a format specifier."""
- -    if typestring == "weave":
- -        return bzrdir.BzrDirFormat6()
+    # Have to use BzrDirMetaFormat1 directly, so that
+    # RepositoryFormat.set_default_format works
     if typestring == "default":
         return bzrdir.BzrDirMetaFormat1()


So other than wondering why you are hard-coding "default" +1.

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

iD8DBQFFiv0+JdeBCYSNAAMRAgfTAKDMM9+HuIb23kCWqb3AVYxn6rvX3ACgnkG6
bNqkN0KpB/Q2RYKMXmRj1KM=
=+r/J
-----END PGP SIGNATURE-----




More information about the bazaar mailing list