how to create a BzrDir of specified format

Martin Pool mbp at sourcefrog.net
Wed Mar 8 23:57:53 GMT 2006


On 8 Mar 2006, at 21:26 , Robert Collins wrote:

> On Wed, 2006-03-08 at 20:43 +1100, Martin Pool wrote:
>> I'm just trying to work out how to make a BzrDir, Branch, etc, of a
>> specified format for the purposes of testing.  The current api seems
>> a bit odd - strongly inclined to create the default format.  As a
>> result many of the existing tests need to set the default format
>> before they do anything.
>>
>> One perverse effect is that
>>
>>    BzrDirMetaFormat1.create('.')
>>
>> creates an instance of a different format!
>>
>> It seems to me that by static methods on e.g. a BzrDirFormat we ought
>> to be able to create an instance and the relevant internal  
>> components.

I've changed BzrDirFormat.create to this:

     @classmethod
     def create(cls, base):
         if cls is not BzrDir:
             raise AssertionError("BzrDir.create always creates the  
default format, "
                     "not one of %r" % cls)

so you'll get an assertion if you try to invoke it as I originally  
did.  I think this is a good practice for static methods that would  
be misleading/incorrect when invoked on subclasses.

> BzrDirMetaFormat1().intialize('.') ...

Thanks.

The other thing I found strange here was this, in BzrDirMeta1:

     def create_branch(self):
         """See BzrDir.create_branch."""
         from bzrlib.branch import BranchFormat
         return BranchFormat.get_default_format().initialize(self)

So when create_branch() is called on a BzrDirMeta1 object, it tries  
to create whichever is the global default branch format - but there's  
no guarantee that it's appropriate for this bzrdir.   
create_workingtree is similar.  Maybe this is OK - if people have  
specific requirements they should create one.  But I would have  
thought it should default to creating the recommended format for that  
bzrdir?  create_repository() asks the bzrdir format what repo format  
it should use, but even then ends up using the global default.

How about instead:

  - there's a global default BzrDirFormat
  - each BzrDirFormat knows its preferred repo, branch and wt  
formats, and creates them when asked
  - the most common special case is to want a particular bzrdir  
format, in which case you initialize it specifically
  - if you want to mix and match at a lower level, create them by hand

-- 
Martin Pool





More information about the bazaar mailing list