~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

(jelmer) Factor out common code from BranchFormatRegistry,
 RepositoryFormatRegistry and WorkingTreeFormatRegistry into
 ControlComponentFormatRegistry. (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1532
1532
            raise AssertionError("invalid heads: %r" % (heads,))
1533
1533
 
1534
1534
 
1535
 
class BranchFormat(object):
 
1535
class BranchFormat(controldir.ControlComponentFormat):
1536
1536
    """An encapsulation of the initialization and open routines for a format.
1537
1537
 
1538
1538
    Formats provide three things:
2356
2356
        return result
2357
2357
 
2358
2358
 
2359
 
class BranchFormatRegistry(registry.FormatRegistry):
 
2359
class BranchFormatRegistry(controldir.ControlComponentFormatRegistry):
2360
2360
    """Branch format registry."""
2361
2361
 
2362
2362
    def __init__(self, other_registry=None):
2363
2363
        super(BranchFormatRegistry, self).__init__(other_registry)
2364
2364
        self._default_format = None
2365
 
        self._extra_formats = []
2366
 
 
2367
 
    def register(self, format):
2368
 
        """Register a new branch format."""
2369
 
        super(BranchFormatRegistry, self).register(
2370
 
            format.get_format_string(), format)
2371
 
 
2372
 
    def remove(self, format):
2373
 
        """Remove a registered branch format."""
2374
 
        super(BranchFormatRegistry, self).remove(
2375
 
            format.get_format_string())
2376
 
 
2377
 
    def register_extra(self, format):
2378
 
        """Register a branch format that can not be part of a metadir.
2379
 
 
2380
 
        This is mainly useful to allow custom branch formats, such as
2381
 
        older Bazaar formats and foreign formats, to be tested
2382
 
        """
2383
 
        self._extra_formats.append(registry._ObjectGetter(format))
2384
 
        network_format_registry.register(
2385
 
            format.network_name(), format.__class__)
2386
 
 
2387
 
    def register_extra_lazy(self, module_name, member_name):
2388
 
        """Register a branch format lazily.
2389
 
        """
2390
 
        self._extra_formats.append(
2391
 
            registry._LazyObjectGetter(module_name, member_name))
2392
 
 
2393
 
    @classmethod
2394
 
    def unregister_extra(self, format):
2395
 
        self._extra_formats.remove(registry._ObjectGetter(format))
2396
 
 
2397
 
    def _get_all(self):
2398
 
        result = []
2399
 
        for name, fmt in self.iteritems():
2400
 
            if callable(fmt):
2401
 
                fmt = fmt()
2402
 
            result.append(fmt)
2403
 
        for objgetter in self._extra_formats:
2404
 
            fmt = objgetter.get_obj()
2405
 
            if callable(fmt):
2406
 
                fmt = fmt()
2407
 
            result.append(fmt)
2408
 
        return result
2409
2365
 
2410
2366
    def set_default(self, format):
2411
2367
        self._default_format = format
2427
2383
 
2428
2384
# formats which have no format string are not discoverable
2429
2385
# and not independently creatable, so are not registered.
 
2386
__format4 = BzrBranchFormat4()
2430
2387
__format5 = BzrBranchFormat5()
2431
2388
__format6 = BzrBranchFormat6()
2432
2389
__format7 = BzrBranchFormat7()
2437
2394
format_registry.register(__format7)
2438
2395
format_registry.register(__format8)
2439
2396
format_registry.set_default(__format7)
2440
 
format_registry.register_extra(BzrBranchFormat4())
 
2397
format_registry.register_extra(__format4)
 
2398
network_format_registry.register(__format4.network_name(), __format4)
2441
2399
 
2442
2400
 
2443
2401
class BranchWriteLockResult(LogicalLockResult):