~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Robert Collins
  • Date: 2009-02-23 05:12:05 UTC
  • mto: This revision was merged to the branch mainline in revision 4038.
  • Revision ID: robertc@robertcollins.net-20090223051205-92ypm6chik138tpy
Add a BranchFormat.network_name() method as preparation for creating branches via RPC calls.

Show diffs side-by-side

added added

removed removed

Lines of Context:
45
45
 
46
46
from bzrlib.decorators import needs_read_lock, needs_write_lock
47
47
from bzrlib.hooks import Hooks
 
48
from bzrlib import registry
48
49
from bzrlib.symbol_versioning import (
49
50
    deprecated_in,
50
51
    deprecated_method,
1258
1259
        """
1259
1260
        return True
1260
1261
 
 
1262
    def network_name(self):
 
1263
        """A simple byte string uniquely identifying this format for RPC calls.
 
1264
 
 
1265
        MetaDir branch formats use their disk format string to identify the
 
1266
        repository over the wire. All in one formats such as bzr < 0.8, and
 
1267
        foreign formats like svn/git and hg should use some marker which is
 
1268
        unique and immutable.
 
1269
        """
 
1270
        raise NotImplementedError(self.network_name)
 
1271
 
1261
1272
    def open(self, a_bzrdir, _found=False):
1262
1273
        """Return the branch object for a_bzrdir
1263
1274
 
1268
1279
 
1269
1280
    @classmethod
1270
1281
    def register_format(klass, format):
 
1282
        """Register a metadir format."""
1271
1283
        klass._formats[format.get_format_string()] = format
 
1284
        # Metadir formats have a network name of their format string.
 
1285
        network_format_registry.register(format.get_format_string(), format)
1272
1286
 
1273
1287
    @classmethod
1274
1288
    def set_default_format(klass, format):
1441
1455
        super(BzrBranchFormat4, self).__init__()
1442
1456
        self._matchingbzrdir = bzrdir.BzrDirFormat6()
1443
1457
 
 
1458
    def network_name(self):
 
1459
        """The network name for this format is the control dirs disk label."""
 
1460
        return self._matchingbzrdir.get_format_string()
 
1461
 
1444
1462
    def open(self, a_bzrdir, _found=False):
1445
1463
        """Return the branch object for a_bzrdir
1446
1464
 
1466
1484
        """What class to instantiate on open calls."""
1467
1485
        raise NotImplementedError(self._branch_class)
1468
1486
 
 
1487
    def network_name(self):
 
1488
        """A simple byte string uniquely identifying this format for RPC calls.
 
1489
 
 
1490
        Metadir branch formats use their format string.
 
1491
        """
 
1492
        return self.get_format_string()
 
1493
 
1469
1494
    def open(self, a_bzrdir, _found=False):
1470
1495
        """Return the branch object for a_bzrdir.
1471
1496
 
1688
1713
        return result
1689
1714
 
1690
1715
 
 
1716
network_format_registry = registry.FormatRegistry()
 
1717
"""Registry of formats indexed by their network name.
 
1718
 
 
1719
The network name for a repository format is an identifier that can be used when
 
1720
referring to formats with smart server operations. See
 
1721
BranchFormat.network_name() for more detail.
 
1722
"""
 
1723
 
 
1724
 
1691
1725
# formats which have no format string are not discoverable
1692
1726
# and not independently creatable, so are not registered.
1693
1727
__format5 = BzrBranchFormat5()
1699
1733
BranchFormat.register_format(__format7)
1700
1734
BranchFormat.set_default_format(__format6)
1701
1735
_legacy_formats = [BzrBranchFormat4(),
1702
 
                   ]
 
1736
    ]
 
1737
network_format_registry.register(
 
1738
    _legacy_formats[0].network_name(), _legacy_formats[0])
 
1739
 
1703
1740
 
1704
1741
class BzrBranch(Branch):
1705
1742
    """A branch stored in the actual filesystem.