~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/branch.py

  • Committer: Jelmer Vernooij
  • Date: 2011-02-18 22:06:01 UTC
  • mto: (5582.12.2 weave-plugin)
  • mto: This revision was merged to the branch mainline in revision 5718.
  • Revision ID: jelmer@samba.org-20110218220601-k1zopdyl0abkzuz9
Factor out _initialize_helper.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1673
1673
            hook(params)
1674
1674
 
1675
1675
    def _initialize_helper(self, a_bzrdir, utf8_files, name=None,
1676
 
                           repository=None, lock_type='metadir',
1677
 
                           set_format=True):
 
1676
                           repository=None):
1678
1677
        """Initialize a branch in a bzrdir, with specified files
1679
1678
 
1680
1679
        :param a_bzrdir: The bzrdir to initialize the branch in
1681
1680
        :param utf8_files: The files to create as a list of
1682
1681
            (filename, content) tuples
1683
1682
        :param name: Name of colocated branch to create, if any
1684
 
        :param set_format: If True, set the format with
1685
 
            self.get_format_string.  (BzrBranch4 has its format set
1686
 
            elsewhere)
1687
1683
        :return: a branch in this format
1688
1684
        """
1689
1685
        mutter('creating branch %r in %s', self, a_bzrdir.user_url)
1690
1686
        branch_transport = a_bzrdir.get_branch_transport(self, name=name)
1691
 
        lock_map = {
1692
 
            'metadir': ('lock', lockdir.LockDir),
1693
 
            'branch4': ('branch-lock', lockable_files.TransportLock),
1694
 
        }
1695
 
        lock_name, lock_class = lock_map[lock_type]
1696
1687
        control_files = lockable_files.LockableFiles(branch_transport,
1697
 
            lock_name, lock_class)
 
1688
            'lock', lockdir.LockDir)
1698
1689
        control_files.create_lock()
 
1690
        control_files.lock_write()
1699
1691
        try:
1700
 
            control_files.lock_write()
1701
 
        except errors.LockContention:
1702
 
            if lock_type != 'branch4':
1703
 
                raise
1704
 
            lock_taken = False
1705
 
        else:
1706
 
            lock_taken = True
1707
 
        if set_format:
1708
1692
            utf8_files += [('format', self.get_format_string())]
1709
 
        try:
1710
1693
            for (filename, content) in utf8_files:
1711
1694
                branch_transport.put_bytes(
1712
1695
                    filename, content,
1713
1696
                    mode=a_bzrdir._get_file_mode())
1714
1697
        finally:
1715
 
            if lock_taken:
1716
 
                control_files.unlock()
 
1698
            control_files.unlock()
1717
1699
        branch = self.open(a_bzrdir, name, _found=True,
1718
1700
                found_repository=repository)
1719
1701
        self._run_post_branch_init_hooks(a_bzrdir, name, branch)