~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/plugins/weave_fmt/bzrdir.py

  • Committer: Vincent Ladeuil
  • Date: 2011-06-15 11:36:05 UTC
  • mto: This revision was merged to the branch mainline in revision 5975.
  • Revision ID: v.ladeuil+lp@free.fr-20110615113605-p7zyyfry9wy1hquc
Make ContentConflict resolution more robust

Show diffs side-by-side

added added

removed removed

Lines of Context:
44
44
    weave,
45
45
    xml5,
46
46
    )
47
 
from bzrlib.i18n import gettext
48
47
from bzrlib.store.versioned import VersionedFileStore
49
48
from bzrlib.transactions import WriteTransaction
50
49
from bzrlib.transport import (
223
222
        """See Converter.convert()."""
224
223
        self.bzrdir = to_convert
225
224
        if pb is not None:
226
 
            warnings.warn(gettext("pb parameter to convert() is deprecated"))
 
225
            warnings.warn("pb parameter to convert() is deprecated")
227
226
        self.pb = ui.ui_factory.nested_progress_bar()
228
227
        try:
229
 
            ui.ui_factory.note(gettext('starting upgrade from format 4 to 5'))
 
228
            ui.ui_factory.note('starting upgrade from format 4 to 5')
230
229
            if isinstance(self.bzrdir.transport, local.LocalTransport):
231
230
                self.bzrdir.get_workingtree_transport(None).delete('stat-cache')
232
231
            self._convert_to_weaves()
235
234
            self.pb.finished()
236
235
 
237
236
    def _convert_to_weaves(self):
238
 
        ui.ui_factory.note(gettext(
239
 
          'note: upgrade may be faster if all store files are ungzipped first'))
 
237
        ui.ui_factory.note('note: upgrade may be faster if all store files are ungzipped first')
240
238
        try:
241
239
            # TODO permissions
242
240
            stat = self.bzrdir.transport.stat('weaves')
252
250
        self.bzrdir.transport.delete('branch-format')
253
251
        self.branch = self.bzrdir.open_branch()
254
252
        self._convert_working_inv()
255
 
        rev_history = self.branch._revision_history()
 
253
        rev_history = self.branch.revision_history()
256
254
        # to_read is a stack holding the revisions we still need to process;
257
255
        # appending to it adds new highest-priority revisions
258
256
        self.known_revisions = set(rev_history)
265
263
        self.pb.clear()
266
264
        to_import = self._make_order()
267
265
        for i, rev_id in enumerate(to_import):
268
 
            self.pb.update(gettext('converting revision'), i, len(to_import))
 
266
            self.pb.update('converting revision', i, len(to_import))
269
267
            self._convert_one_rev(rev_id)
270
268
        self.pb.clear()
271
269
        self._write_all_weaves()
272
270
        self._write_all_revs()
273
 
        ui.ui_factory.note(gettext('upgraded to weaves:'))
274
 
        ui.ui_factory.note('  ' + gettext('%6d revisions and inventories') %
275
 
                                                        len(self.revisions))
276
 
        ui.ui_factory.note('  ' + gettext('%6d revisions not present') %
277
 
                                                    len(self.absent_revisions))
278
 
        ui.ui_factory.note('  ' + gettext('%6d texts') % self.text_count)
 
271
        ui.ui_factory.note('upgraded to weaves:')
 
272
        ui.ui_factory.note('  %6d revisions and inventories' % len(self.revisions))
 
273
        ui.ui_factory.note('  %6d revisions not present' % len(self.absent_revisions))
 
274
        ui.ui_factory.note('  %6d texts' % self.text_count)
279
275
        self._cleanup_spare_files_after_format4()
280
276
        self.branch._transport.put_bytes(
281
277
            'branch-format',
311
307
        try:
312
308
            i = 0
313
309
            for file_id, file_weave in self.text_weaves.items():
314
 
                self.pb.update(gettext('writing weave'), i,
315
 
                                                        len(self.text_weaves))
 
310
                self.pb.update('writing weave', i, len(self.text_weaves))
316
311
                weaves._put_weave(file_id, file_weave, transaction)
317
312
                i += 1
318
 
            self.pb.update(gettext('inventory'), 0, 1)
 
313
            self.pb.update('inventory', 0, 1)
319
314
            controlweaves._put_weave('inventory', self.inv_weave, transaction)
320
 
            self.pb.update(gettext('inventory'), 1, 1)
 
315
            self.pb.update('inventory', 1, 1)
321
316
        finally:
322
317
            self.pb.clear()
323
318
 
334
329
            lambda:True, lambda:True)
335
330
        try:
336
331
            for i, rev_id in enumerate(self.converted_revs):
337
 
                self.pb.update(gettext('write revision'), i,
338
 
                                                len(self.converted_revs))
 
332
                self.pb.update('write revision', i, len(self.converted_revs))
339
333
                text = serializer_v5.write_revision_to_string(
340
334
                    self.revisions[rev_id])
341
335
                key = (rev_id,)
348
342
 
349
343
        Any parents not either loaded or abandoned get queued to be
350
344
        loaded."""
351
 
        self.pb.update(gettext('loading revision'),
 
345
        self.pb.update('loading revision',
352
346
                       len(self.revisions),
353
347
                       len(self.known_revisions))
354
348
        if not self.branch.repository.has_revision(rev_id):
355
349
            self.pb.clear()
356
 
            ui.ui_factory.note(gettext('revision {%s} not present in branch; '
357
 
                         'will be converted as a ghost') %
 
350
            ui.ui_factory.note('revision {%s} not present in branch; '
 
351
                         'will be converted as a ghost' %
358
352
                         rev_id)
359
353
            self.absent_revisions.add(rev_id)
360
354
        else:
493
487
        self.bzrdir = to_convert
494
488
        pb = ui.ui_factory.nested_progress_bar()
495
489
        try:
496
 
            ui.ui_factory.note(gettext('starting upgrade from format 5 to 6'))
 
490
            ui.ui_factory.note('starting upgrade from format 5 to 6')
497
491
            self._convert_to_prefixed()
498
492
            return BzrDir.open(self.bzrdir.user_url)
499
493
        finally:
503
497
        from bzrlib.store import TransportStore
504
498
        self.bzrdir.transport.delete('branch-format')
505
499
        for store_name in ["weaves", "revision-store"]:
506
 
            ui.ui_factory.note(gettext("adding prefixes to %s") % store_name)
 
500
            ui.ui_factory.note("adding prefixes to %s" % store_name)
507
501
            store_transport = self.bzrdir.transport.clone(store_name)
508
502
            store = TransportStore(store_transport, prefixed=True)
509
503
            for urlfilename in store_transport.list_dir('.'):
543
537
        self.dir_mode = self.bzrdir._get_dir_mode()
544
538
        self.file_mode = self.bzrdir._get_file_mode()
545
539
 
546
 
        ui.ui_factory.note(gettext('starting upgrade from format 6 to metadir'))
 
540
        ui.ui_factory.note('starting upgrade from format 6 to metadir')
547
541
        self.bzrdir.transport.put_bytes(
548
542
                'branch-format',
549
543
                "Converting to format 6",
551
545
        # its faster to move specific files around than to open and use the apis...
552
546
        # first off, nuke ancestry.weave, it was never used.
553
547
        try:
554
 
            self.step(gettext('Removing ancestry.weave'))
 
548
            self.step('Removing ancestry.weave')
555
549
            self.bzrdir.transport.delete('ancestry.weave')
556
550
        except errors.NoSuchFile:
557
551
            pass
558
552
        # find out whats there
559
 
        self.step(gettext('Finding branch files'))
 
553
        self.step('Finding branch files')
560
554
        last_revision = self.bzrdir.open_branch().last_revision()
561
555
        bzrcontents = self.bzrdir.transport.list_dir('.')
562
556
        for name in bzrcontents:
566
560
        repository_names = [('inventory.weave', True),
567
561
                            ('revision-store', True),
568
562
                            ('weaves', True)]
569
 
        self.step(gettext('Upgrading repository') + '  ')
 
563
        self.step('Upgrading repository  ')
570
564
        self.bzrdir.transport.mkdir('repository', mode=self.dir_mode)
571
565
        self.make_lock('repository')
572
566
        # we hard code the formats here because we are converting into
576
570
        for entry in repository_names:
577
571
            self.move_entry('repository', entry)
578
572
 
579
 
        self.step(gettext('Upgrading branch') + '      ')
 
573
        self.step('Upgrading branch      ')
580
574
        self.bzrdir.transport.mkdir('branch', mode=self.dir_mode)
581
575
        self.make_lock('branch')
582
576
        self.put_format('branch', BzrBranchFormat5())
599
593
        else:
600
594
            has_checkout = True
601
595
        if not has_checkout:
602
 
            ui.ui_factory.note(gettext('No working tree.'))
 
596
            ui.ui_factory.note('No working tree.')
603
597
            # If some checkout files are there, we may as well get rid of them.
604
598
            for name, mandatory in checkout_files:
605
599
                if name in bzrcontents:
606
600
                    self.bzrdir.transport.delete(name)
607
601
        else:
608
602
            from bzrlib.workingtree_3 import WorkingTreeFormat3
609
 
            self.step(gettext('Upgrading working tree'))
 
603
            self.step('Upgrading working tree')
610
604
            self.bzrdir.transport.mkdir('checkout', mode=self.dir_mode)
611
605
            self.make_lock('checkout')
612
606
            self.put_format(
627
621
 
628
622
    def make_lock(self, name):
629
623
        """Make a lock for the new control dir name."""
630
 
        self.step(gettext('Make %s lock') % name)
 
624
        self.step('Make %s lock' % name)
631
625
        ld = lockdir.LockDir(self.bzrdir.transport,
632
626
                             '%s/lock' % name,
633
627
                             file_modebits=self.file_mode,
638
632
        """Move then entry name into new_dir."""
639
633
        name = entry[0]
640
634
        mandatory = entry[1]
641
 
        self.step(gettext('Moving %s') % name)
 
635
        self.step('Moving %s' % name)
642
636
        try:
643
637
            self.bzrdir.transport.move(name, '%s/%s' % (new_dir, name))
644
638
        except errors.NoSuchFile:
753
747
            tree.clone(result)
754
748
        return result
755
749
 
756
 
    def create_branch(self, name=None, repository=None,
757
 
                      append_revisions_only=None):
 
750
    def create_branch(self, name=None, repository=None):
758
751
        """See BzrDir.create_branch."""
759
752
        if repository is not None:
760
753
            raise NotImplementedError(
761
754
                "create_branch(repository=<not None>) on %r" % (self,))
762
 
        return self._format.get_branch_format().initialize(self, name=name,
763
 
            append_revisions_only=append_revisions_only)
 
755
        return self._format.get_branch_format().initialize(self, name=name)
764
756
 
765
757
    def destroy_branch(self, name=None):
766
758
        """See BzrDir.destroy_branch."""