~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/bzrdir.py

  • Committer: Martin Pool
  • Date: 2008-05-22 05:48:22 UTC
  • mfrom: (3407.2.16 controlfiles)
  • mto: This revision was merged to the branch mainline in revision 3448.
  • Revision ID: mbp@sourcefrog.net-20080522054822-lrq17tx62wbfzj8r
merge further LockableFile deprecations

Show diffs side-by-side

added added

removed removed

Lines of Context:
89
89
    BzrDir instances let you create or open any of the things that can be
90
90
    found within .bzr - checkouts, branches and repositories.
91
91
    
92
 
    transport
 
92
    :ivar transport:
93
93
        the transport which this bzr dir is rooted at (i.e. file:///.../.bzr/)
94
 
    root_transport
 
94
    :ivar root_transport:
95
95
        a transport connected to the directory this bzr was opened from
96
96
        (i.e. the parent directory holding the .bzr directory).
97
97
 
1086
1086
            except errors.NotLocalUrl:
1087
1087
                # but we cannot do it for remote trees.
1088
1088
                to_branch = result.open_branch()
1089
 
                WorkingTreeFormat2().stub_initialize_remote(to_branch.control_files)
 
1089
                WorkingTreeFormat2()._stub_initialize_remote(to_branch)
1090
1090
        return result
1091
1091
 
1092
1092
    def create_branch(self):
1547
1547
            win32utils.set_file_attr_hidden(transport._abspath('.bzr'))
1548
1548
        file_mode = temp_control._file_mode
1549
1549
        del temp_control
1550
 
        mutter('created control directory in ' + transport.base)
1551
 
        control = transport.clone('.bzr')
1552
 
        utf8_files = [('README', 
 
1550
        bzrdir_transport = transport.clone('.bzr')
 
1551
        utf8_files = [('README',
1553
1552
                       "This is a Bazaar control directory.\n"
1554
1553
                       "Do not change any files in this directory.\n"
1555
1554
                       "See http://bazaar-vcs.org/ for more information about Bazaar.\n"),
1556
1555
                      ('branch-format', self.get_format_string()),
1557
1556
                      ]
1558
1557
        # NB: no need to escape relative paths that are url safe.
1559
 
        control_files = lockable_files.LockableFiles(control,
1560
 
                            self._lock_file_name, self._lock_class)
 
1558
        control_files = lockable_files.LockableFiles(bzrdir_transport,
 
1559
            self._lock_file_name, self._lock_class)
1561
1560
        control_files.create_lock()
1562
1561
        control_files.lock_write()
1563
1562
        try:
1564
 
            for file, content in utf8_files:
1565
 
                control_files.put_utf8(file, content)
 
1563
            for (filename, content) in utf8_files:
 
1564
                bzrdir_transport.put_bytes(filename, content,
 
1565
                    mode=file_mode)
1566
1566
        finally:
1567
1567
            control_files.unlock()
1568
1568
        return self.open(transport, _found=True)
1762
1762
            except errors.NotLocalUrl:
1763
1763
                # Even though we can't access the working tree, we need to
1764
1764
                # create its control files.
1765
 
                WorkingTreeFormat2().stub_initialize_remote(branch.control_files)
 
1765
                WorkingTreeFormat2()._stub_initialize_remote(branch)
1766
1766
        return result
1767
1767
 
1768
1768
    def _open(self, transport):
1821
1821
            except errors.NotLocalUrl:
1822
1822
                # Even though we can't access the working tree, we need to
1823
1823
                # create its control files.
1824
 
                WorkingTreeFormat2().stub_initialize_remote(branch.control_files)
 
1824
                WorkingTreeFormat2()._stub_initialize_remote(branch)
1825
1825
        return result
1826
1826
 
1827
1827
    def _open(self, transport):
2008
2008
        self.pb.note('  %6d revisions not present', len(self.absent_revisions))
2009
2009
        self.pb.note('  %6d texts', self.text_count)
2010
2010
        self._cleanup_spare_files_after_format4()
2011
 
        self.branch.control_files.put_utf8('branch-format', BzrDirFormat5().get_format_string())
 
2011
        self.branch._transport.put_bytes(
 
2012
            'branch-format',
 
2013
            BzrDirFormat5().get_format_string(),
 
2014
            mode=self.bzrdir._get_file_mode())
2012
2015
 
2013
2016
    def _cleanup_spare_files_after_format4(self):
2014
2017
        # FIXME working tree upgrade foo.
2023
2026
 
2024
2027
    def _convert_working_inv(self):
2025
2028
        inv = xml4.serializer_v4.read_inventory(
2026
 
                    self.branch.control_files.get('inventory'))
 
2029
                self.branch._transport.get('inventory'))
2027
2030
        new_inv_xml = xml5.serializer_v5.write_inventory_to_string(inv, working=True)
2028
 
        # FIXME inventory is a working tree change.
2029
 
        self.branch.control_files.put('inventory', StringIO(new_inv_xml))
 
2031
        self.branch._transport.put_bytes('inventory', new_inv_xml,
 
2032
            mode=self.bzrdir._get_file_mode())
2030
2033
 
2031
2034
    def _write_all_weaves(self):
2032
2035
        controlweaves = WeaveStore(self.bzrdir.transport, prefixed=False)
2239
2242
                except errors.NoSuchFile: # catches missing dirs strangely enough
2240
2243
                    store_transport.mkdir(prefix_dir)
2241
2244
                    store_transport.move(filename, prefix_dir + '/' + filename)
2242
 
        self.bzrdir._control_files.put_utf8('branch-format', BzrDirFormat6().get_format_string())
 
2245
        self.bzrdir.transport.put_bytes(
 
2246
            'branch-format',
 
2247
            BzrDirFormat6().get_format_string(),
 
2248
            mode=self.bzrdir._get_file_mode())
2243
2249
 
2244
2250
 
2245
2251
class ConvertBzrDir6ToMeta(Converter):
2254
2260
        self.count = 0
2255
2261
        self.total = 20 # the steps we know about
2256
2262
        self.garbage_inventories = []
 
2263
        self.dir_mode = self.bzrdir._get_dir_mode()
 
2264
        self.file_mode = self.bzrdir._get_file_mode()
2257
2265
 
2258
2266
        self.pb.note('starting upgrade from format 6 to metadir')
2259
 
        self.bzrdir._control_files.put_utf8('branch-format', "Converting to format 6")
 
2267
        self.bzrdir.transport.put_bytes(
 
2268
                'branch-format',
 
2269
                "Converting to format 6",
 
2270
                mode=self.file_mode)
2260
2271
        # its faster to move specific files around than to open and use the apis...
2261
2272
        # first off, nuke ancestry.weave, it was never used.
2262
2273
        try:
2272
2283
            if name.startswith('basis-inventory.'):
2273
2284
                self.garbage_inventories.append(name)
2274
2285
        # create new directories for repository, working tree and branch
2275
 
        self.dir_mode = self.bzrdir._get_dir_mode()
2276
 
        self.file_mode = self.bzrdir._get_file_mode()
2277
2286
        repository_names = [('inventory.weave', True),
2278
2287
                            ('revision-store', True),
2279
2288
                            ('weaves', True)]
2327
2336
            for entry in checkout_files:
2328
2337
                self.move_entry('checkout', entry)
2329
2338
            if last_revision is not None:
2330
 
                self.bzrdir._control_files.put_utf8(
 
2339
                self.bzrdir.transport.put_bytes(
2331
2340
                    'checkout/last-revision', last_revision)
2332
 
        self.bzrdir._control_files.put_utf8(
2333
 
            'branch-format', BzrDirMetaFormat1().get_format_string())
 
2341
        self.bzrdir.transport.put_bytes(
 
2342
            'branch-format',
 
2343
            BzrDirMetaFormat1().get_format_string(),
 
2344
            mode=self.file_mode)
2334
2345
        return BzrDir.open(self.bzrdir.root_transport.base)
2335
2346
 
2336
2347
    def make_lock(self, name):
2354
2365
                raise
2355
2366
 
2356
2367
    def put_format(self, dirname, format):
2357
 
        self.bzrdir._control_files.put_utf8('%s/format' % dirname, format.get_format_string())
 
2368
        self.bzrdir.transport.put_bytes('%s/format' % dirname,
 
2369
            format.get_format_string(),
 
2370
            self.file_mode)
2358
2371
 
2359
2372
 
2360
2373
class ConvertMetaToMeta(Converter):