~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

merge bzr.dev.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1607
1607
        return not (self == other)
1608
1608
 
1609
1609
    @classmethod
1610
 
    def find_format(klass, controldir, name=None):
1611
 
        """Return the format for the branch object in controldir."""
1612
 
        try:
1613
 
            transport = controldir.get_branch_transport(None, name=name)
1614
 
        except errors.NoSuchFile:
1615
 
            raise errors.NotBranchError(path=name, bzrdir=controldir)
1616
 
        try:
1617
 
            format_string = transport.get_bytes("format")
1618
 
            return format_registry.get(format_string)
1619
 
        except errors.NoSuchFile:
1620
 
            raise errors.NotBranchError(path=transport.base, bzrdir=controldir)
1621
 
        except KeyError:
1622
 
            raise errors.UnknownFormatError(format=format_string, kind='branch')
1623
 
 
1624
 
    @classmethod
1625
1610
    @deprecated_method(deprecated_in((2, 4, 0)))
1626
1611
    def get_default_format(klass):
1627
1612
        """Return the current default format."""
1664
1649
        """
1665
1650
        raise NotImplementedError(self.set_reference)
1666
1651
 
1667
 
    def get_format_string(self):
1668
 
        """Return the ASCII format string that identifies this format."""
1669
 
        raise NotImplementedError(self.get_format_string)
1670
 
 
1671
1652
    def get_format_description(self):
1672
1653
        """Return the short format description for this format."""
1673
1654
        raise NotImplementedError(self.get_format_description)
1800
1781
        """
1801
1782
        registry._LazyObjectGetter.__init__(self, module_name, member_name)
1802
1783
        self._format_string = format_string
1803
 
        
 
1784
 
1804
1785
    def get_format_string(self):
1805
1786
        """See BranchFormat.get_format_string."""
1806
1787
        return self._format_string
2018
1999
            self.revision_id)
2019
2000
 
2020
2001
 
2021
 
class BranchFormatMetadir(BranchFormat):
2022
 
    """Common logic for meta-dir based branch formats."""
 
2002
class BranchFormatMetadir(bzrdir.BzrDirMetaComponentFormat, BranchFormat):
 
2003
    """Base class for branch formats that live in meta directories.
 
2004
    """
 
2005
 
 
2006
    def __init__(self):
 
2007
        BranchFormat.__init__(self)
 
2008
        bzrdir.BzrDirMetaComponentFormat.__init__(self)
 
2009
 
 
2010
    @classmethod
 
2011
    def find_format(klass, controldir, name=None):
 
2012
        """Return the format for the branch object in controldir."""
 
2013
        try:
 
2014
            transport = controldir.get_branch_transport(None, name=name)
 
2015
        except errors.NoSuchFile:
 
2016
            raise errors.NotBranchError(path=name, bzrdir=controldir)
 
2017
        try:
 
2018
            format_string = transport.get_bytes("format")
 
2019
        except errors.NoSuchFile:
 
2020
            raise errors.NotBranchError(path=transport.base, bzrdir=controldir)
 
2021
        return klass._find_format(format_registry, 'branch', format_string)
2023
2022
 
2024
2023
    def _branch_class(self):
2025
2024
        """What class to instantiate on open calls."""
2062
2061
        self._run_post_branch_init_hooks(a_bzrdir, name, branch)
2063
2062
        return branch
2064
2063
 
2065
 
    def network_name(self):
2066
 
        """A simple byte string uniquely identifying this format for RPC calls.
2067
 
 
2068
 
        Metadir branch formats use their format string.
2069
 
        """
2070
 
        return self.get_format_string()
2071
 
 
2072
2064
    def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False,
2073
2065
            found_repository=None, possible_transports=None):
2074
2066
        """See BranchFormat.open()."""
2075
2067
        if not _found:
2076
 
            format = BranchFormat.find_format(a_bzrdir, name=name)
 
2068
            format = BranchFormatMetadir.find_format(a_bzrdir, name=name)
2077
2069
            if format.__class__ != self.__class__:
2078
2070
                raise AssertionError("wrong format %r found for %r" %
2079
2071
                    (format, self))
2122
2114
    def _branch_class(self):
2123
2115
        return BzrBranch5
2124
2116
 
2125
 
    def get_format_string(self):
 
2117
    @classmethod
 
2118
    def get_format_string(cls):
2126
2119
        """See BranchFormat.get_format_string()."""
2127
2120
        return "Bazaar-NG branch format 5\n"
2128
2121
 
2158
2151
    def _branch_class(self):
2159
2152
        return BzrBranch6
2160
2153
 
2161
 
    def get_format_string(self):
 
2154
    @classmethod
 
2155
    def get_format_string(cls):
2162
2156
        """See BranchFormat.get_format_string()."""
2163
2157
        return "Bazaar Branch Format 6 (bzr 0.15)\n"
2164
2158
 
2190
2184
    def _branch_class(self):
2191
2185
        return BzrBranch8
2192
2186
 
2193
 
    def get_format_string(self):
 
2187
    @classmethod
 
2188
    def get_format_string(cls):
2194
2189
        """See BranchFormat.get_format_string()."""
2195
2190
        return "Bazaar Branch Format 8 (needs bzr 1.15)\n"
2196
2191
 
2244
2239
    def _branch_class(self):
2245
2240
        return BzrBranch7
2246
2241
 
2247
 
    def get_format_string(self):
 
2242
    @classmethod
 
2243
    def get_format_string(cls):
2248
2244
        """See BranchFormat.get_format_string()."""
2249
2245
        return "Bazaar Branch Format 7 (needs bzr 1.6)\n"
2250
2246
 
2276
2272
     - a format string
2277
2273
    """
2278
2274
 
2279
 
    def get_format_string(self):
 
2275
    @classmethod
 
2276
    def get_format_string(cls):
2280
2277
        """See BranchFormat.get_format_string()."""
2281
2278
        return "Bazaar-NG Branch Reference Format 1\n"
2282
2279
 
2342
2339
        :param possible_transports: An optional reusable transports list.
2343
2340
        """
2344
2341
        if not _found:
2345
 
            format = BranchFormat.find_format(a_bzrdir, name=name)
 
2342
            format = BranchFormatMetadir.find_format(a_bzrdir, name=name)
2346
2343
            if format.__class__ != self.__class__:
2347
2344
                raise AssertionError("wrong format %r found for %r" %
2348
2345
                    (format, self))