~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-03-07 17:52:19 UTC
  • mfrom: (5697.2.2 weave-branch)
  • Revision ID: pqm@pqm.ubuntu.com-20110307175219-4wuflxgl4hfzivom
(jelmer) Move weave-era branch formats to bzrlib.branch_weave.
 (Jelmer Vernooij)

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
        bzrdir,
26
26
        cache_utf8,
27
27
        config as _mod_config,
28
 
        controldir,
29
28
        debug,
30
29
        errors,
31
30
        fetch,
50
49
    )
51
50
""")
52
51
 
53
 
from bzrlib.decorators import needs_read_lock, needs_write_lock, only_raises
 
52
from bzrlib import (
 
53
    controldir,
 
54
    )
 
55
from bzrlib.decorators import (
 
56
    needs_read_lock,
 
57
    needs_write_lock,
 
58
    only_raises,
 
59
    )
54
60
from bzrlib.hooks import HookPoint, Hooks
55
61
from bzrlib.inter import InterObject
56
62
from bzrlib.lock import _RelockDebugMixin, LogicalLockResult
805
811
 
806
812
    def _unstack(self):
807
813
        """Change a branch to be unstacked, copying data as needed.
808
 
        
 
814
 
809
815
        Don't call this directly, use set_stacked_on_url(None).
810
816
        """
811
817
        pb = ui.ui_factory.nested_progress_bar()
1650
1656
            hook(params)
1651
1657
 
1652
1658
    def _initialize_helper(self, a_bzrdir, utf8_files, name=None,
1653
 
                           repository=None, lock_type='metadir',
1654
 
                           set_format=True):
 
1659
                           repository=None):
1655
1660
        """Initialize a branch in a bzrdir, with specified files
1656
1661
 
1657
1662
        :param a_bzrdir: The bzrdir to initialize the branch in
1658
1663
        :param utf8_files: The files to create as a list of
1659
1664
            (filename, content) tuples
1660
1665
        :param name: Name of colocated branch to create, if any
1661
 
        :param set_format: If True, set the format with
1662
 
            self.get_format_string.  (BzrBranch4 has its format set
1663
 
            elsewhere)
1664
1666
        :return: a branch in this format
1665
1667
        """
1666
1668
        mutter('creating branch %r in %s', self, a_bzrdir.user_url)
1667
1669
        branch_transport = a_bzrdir.get_branch_transport(self, name=name)
1668
 
        lock_map = {
1669
 
            'metadir': ('lock', lockdir.LockDir),
1670
 
            'branch4': ('branch-lock', lockable_files.TransportLock),
1671
 
        }
1672
 
        lock_name, lock_class = lock_map[lock_type]
1673
1670
        control_files = lockable_files.LockableFiles(branch_transport,
1674
 
            lock_name, lock_class)
 
1671
            'lock', lockdir.LockDir)
1675
1672
        control_files.create_lock()
 
1673
        control_files.lock_write()
1676
1674
        try:
1677
 
            control_files.lock_write()
1678
 
        except errors.LockContention:
1679
 
            if lock_type != 'branch4':
1680
 
                raise
1681
 
            lock_taken = False
1682
 
        else:
1683
 
            lock_taken = True
1684
 
        if set_format:
1685
1675
            utf8_files += [('format', self.get_format_string())]
1686
 
        try:
1687
1676
            for (filename, content) in utf8_files:
1688
1677
                branch_transport.put_bytes(
1689
1678
                    filename, content,
1690
1679
                    mode=a_bzrdir._get_file_mode())
1691
1680
        finally:
1692
 
            if lock_taken:
1693
 
                control_files.unlock()
 
1681
            control_files.unlock()
1694
1682
        branch = self.open(a_bzrdir, name, _found=True,
1695
1683
                found_repository=repository)
1696
1684
        self._run_post_branch_init_hooks(a_bzrdir, name, branch)
2025
2013
            self.revision_id)
2026
2014
 
2027
2015
 
2028
 
class BzrBranchFormat4(BranchFormat):
2029
 
    """Bzr branch format 4.
2030
 
 
2031
 
    This format has:
2032
 
     - a revision-history file.
2033
 
     - a branch-lock lock file [ to be shared with the bzrdir ]
2034
 
    """
2035
 
 
2036
 
    def get_format_description(self):
2037
 
        """See BranchFormat.get_format_description()."""
2038
 
        return "Branch format 4"
2039
 
 
2040
 
    def initialize(self, a_bzrdir, name=None, repository=None):
2041
 
        """Create a branch of this format in a_bzrdir."""
2042
 
        if repository is not None:
2043
 
            raise NotImplementedError(
2044
 
                "initialize(repository=<not None>) on %r" % (self,))
2045
 
        utf8_files = [('revision-history', ''),
2046
 
                      ('branch-name', ''),
2047
 
                      ]
2048
 
        return self._initialize_helper(a_bzrdir, utf8_files, name=name,
2049
 
                                       lock_type='branch4', set_format=False)
2050
 
 
2051
 
    def __init__(self):
2052
 
        super(BzrBranchFormat4, self).__init__()
2053
 
        self._matchingbzrdir = bzrdir.BzrDirFormat6()
2054
 
 
2055
 
    def network_name(self):
2056
 
        """The network name for this format is the control dirs disk label."""
2057
 
        return self._matchingbzrdir.get_format_string()
2058
 
 
2059
 
    def open(self, a_bzrdir, name=None, _found=False, ignore_fallbacks=False,
2060
 
            found_repository=None):
2061
 
        """See BranchFormat.open()."""
2062
 
        if not _found:
2063
 
            # we are being called directly and must probe.
2064
 
            raise NotImplementedError
2065
 
        if found_repository is None:
2066
 
            found_repository = a_bzrdir.open_repository()
2067
 
        return BzrBranchPreSplitOut(_format=self,
2068
 
                         _control_files=a_bzrdir._control_files,
2069
 
                         a_bzrdir=a_bzrdir,
2070
 
                         name=name,
2071
 
                         _repository=found_repository)
2072
 
 
2073
 
    def __str__(self):
2074
 
        return "Bazaar-NG branch format 4"
2075
 
 
2076
 
    def supports_leaving_lock(self):
2077
 
        return False
2078
 
 
2079
 
 
2080
2016
class BranchFormatMetadir(BranchFormat):
2081
2017
    """Common logic for meta-dir based branch formats."""
2082
2018
 
2403
2339
 
2404
2340
# formats which have no format string are not discoverable
2405
2341
# and not independently creatable, so are not registered.
2406
 
__format4 = BzrBranchFormat4()
2407
2342
__format5 = BzrBranchFormat5()
2408
2343
__format6 = BzrBranchFormat6()
2409
2344
__format7 = BzrBranchFormat7()
2414
2349
format_registry.register(__format7)
2415
2350
format_registry.register(__format8)
2416
2351
format_registry.set_default(__format7)
2417
 
format_registry.register_extra(__format4)
2418
 
network_format_registry.register(__format4.network_name(), __format4)
 
2352
format_registry.register_extra_lazy("bzrlib.branch_weave",
 
2353
    "BzrBranchFormat4")
 
2354
network_format_registry.register_lazy("Bazaar-NG branch, format 6\n",
 
2355
    "bzrlib.branch_weave", "BzrBranchFormat4")
2419
2356
 
2420
2357
 
2421
2358
class BranchWriteLockResult(LogicalLockResult):
2726
2663
                mode=self.bzrdir._get_file_mode())
2727
2664
 
2728
2665
 
2729
 
class BzrBranchPreSplitOut(BzrBranch):
2730
 
 
2731
 
    def _get_checkout_format(self):
2732
 
        """Return the most suitable metadir for a checkout of this branch.
2733
 
        Weaves are used if this branch's repository uses weaves.
2734
 
        """
2735
 
        from bzrlib.repofmt.weaverepo import RepositoryFormat7
2736
 
        from bzrlib.bzrdir import BzrDirMetaFormat1
2737
 
        format = BzrDirMetaFormat1()
2738
 
        format.repository_format = RepositoryFormat7()
2739
 
        return format
2740
 
 
2741
 
 
2742
2666
class BzrBranch5(BzrBranch):
2743
2667
    """A format 5 branch. This supports new features over plain branches.
2744
2668