~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

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

  • Committer: Martin Packman
  • Date: 2012-01-05 09:50:04 UTC
  • mfrom: (6424 +trunk)
  • mto: This revision was merged to the branch mainline in revision 6426.
  • Revision ID: martin.packman@canonical.com-20120105095004-mia9xb7y0efmto0v
Merge bzr.dev to resolve conflicts in bzrlib.builtins

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
"""Weave-era BzrDir formats."""
18
18
 
 
19
from __future__ import absolute_import
 
20
 
19
21
from bzrlib.bzrdir import (
20
22
    BzrDir,
21
23
    BzrDirFormat,
44
46
    weave,
45
47
    xml5,
46
48
    )
 
49
from bzrlib.i18n import gettext
47
50
from bzrlib.store.versioned import VersionedFileStore
48
51
from bzrlib.transactions import WriteTransaction
49
52
from bzrlib.transport import (
80
83
            stack_on_pwd=stack_on_pwd, repo_format_name=repo_format_name,
81
84
            make_working_trees=make_working_trees, shared_repo=shared_repo)
82
85
 
 
86
    @classmethod
 
87
    def from_string(cls, format_string):
 
88
        if format_string != cls.get_format_string():
 
89
            raise AssertionError("unexpected format string %r" % format_string)
 
90
        return cls()
 
91
 
83
92
 
84
93
class BzrDirFormat5(BzrDirFormatAllInOne):
85
94
    """Bzr control format 5.
97
106
    def __eq__(self, other):
98
107
        return type(self) == type(other)
99
108
 
100
 
    def get_format_string(self):
 
109
    @classmethod
 
110
    def get_format_string(cls):
101
111
        """See BzrDirFormat.get_format_string()."""
102
112
        return "Bazaar-NG branch, format 5\n"
103
113
 
160
170
    def __eq__(self, other):
161
171
        return type(self) == type(other)
162
172
 
163
 
    def get_format_string(self):
 
173
    @classmethod
 
174
    def get_format_string(cls):
164
175
        """See BzrDirFormat.get_format_string()."""
165
176
        return "Bazaar-NG branch, format 6\n"
166
177
 
222
233
        """See Converter.convert()."""
223
234
        self.bzrdir = to_convert
224
235
        if pb is not None:
225
 
            warnings.warn("pb parameter to convert() is deprecated")
 
236
            warnings.warn(gettext("pb parameter to convert() is deprecated"))
226
237
        self.pb = ui.ui_factory.nested_progress_bar()
227
238
        try:
228
 
            ui.ui_factory.note('starting upgrade from format 4 to 5')
 
239
            ui.ui_factory.note(gettext('starting upgrade from format 4 to 5'))
229
240
            if isinstance(self.bzrdir.transport, local.LocalTransport):
230
241
                self.bzrdir.get_workingtree_transport(None).delete('stat-cache')
231
242
            self._convert_to_weaves()
234
245
            self.pb.finished()
235
246
 
236
247
    def _convert_to_weaves(self):
237
 
        ui.ui_factory.note('note: upgrade may be faster if all store files are ungzipped first')
 
248
        ui.ui_factory.note(gettext(
 
249
          'note: upgrade may be faster if all store files are ungzipped first'))
238
250
        try:
239
251
            # TODO permissions
240
252
            stat = self.bzrdir.transport.stat('weaves')
250
262
        self.bzrdir.transport.delete('branch-format')
251
263
        self.branch = self.bzrdir.open_branch()
252
264
        self._convert_working_inv()
253
 
        rev_history = self.branch.revision_history()
 
265
        rev_history = self.branch._revision_history()
254
266
        # to_read is a stack holding the revisions we still need to process;
255
267
        # appending to it adds new highest-priority revisions
256
268
        self.known_revisions = set(rev_history)
263
275
        self.pb.clear()
264
276
        to_import = self._make_order()
265
277
        for i, rev_id in enumerate(to_import):
266
 
            self.pb.update('converting revision', i, len(to_import))
 
278
            self.pb.update(gettext('converting revision'), i, len(to_import))
267
279
            self._convert_one_rev(rev_id)
268
280
        self.pb.clear()
269
281
        self._write_all_weaves()
270
282
        self._write_all_revs()
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)
 
283
        ui.ui_factory.note(gettext('upgraded to weaves:'))
 
284
        ui.ui_factory.note('  ' + gettext('%6d revisions and inventories') %
 
285
                                                        len(self.revisions))
 
286
        ui.ui_factory.note('  ' + gettext('%6d revisions not present') %
 
287
                                                    len(self.absent_revisions))
 
288
        ui.ui_factory.note('  ' + gettext('%6d texts') % self.text_count)
275
289
        self._cleanup_spare_files_after_format4()
276
290
        self.branch._transport.put_bytes(
277
291
            'branch-format',
307
321
        try:
308
322
            i = 0
309
323
            for file_id, file_weave in self.text_weaves.items():
310
 
                self.pb.update('writing weave', i, len(self.text_weaves))
 
324
                self.pb.update(gettext('writing weave'), i,
 
325
                                                        len(self.text_weaves))
311
326
                weaves._put_weave(file_id, file_weave, transaction)
312
327
                i += 1
313
 
            self.pb.update('inventory', 0, 1)
 
328
            self.pb.update(gettext('inventory'), 0, 1)
314
329
            controlweaves._put_weave('inventory', self.inv_weave, transaction)
315
 
            self.pb.update('inventory', 1, 1)
 
330
            self.pb.update(gettext('inventory'), 1, 1)
316
331
        finally:
317
332
            self.pb.clear()
318
333
 
329
344
            lambda:True, lambda:True)
330
345
        try:
331
346
            for i, rev_id in enumerate(self.converted_revs):
332
 
                self.pb.update('write revision', i, len(self.converted_revs))
 
347
                self.pb.update(gettext('write revision'), i,
 
348
                                                len(self.converted_revs))
333
349
                text = serializer_v5.write_revision_to_string(
334
350
                    self.revisions[rev_id])
335
351
                key = (rev_id,)
342
358
 
343
359
        Any parents not either loaded or abandoned get queued to be
344
360
        loaded."""
345
 
        self.pb.update('loading revision',
 
361
        self.pb.update(gettext('loading revision'),
346
362
                       len(self.revisions),
347
363
                       len(self.known_revisions))
348
364
        if not self.branch.repository.has_revision(rev_id):
349
365
            self.pb.clear()
350
 
            ui.ui_factory.note('revision {%s} not present in branch; '
351
 
                         'will be converted as a ghost' %
 
366
            ui.ui_factory.note(gettext('revision {%s} not present in branch; '
 
367
                         'will be converted as a ghost') %
352
368
                         rev_id)
353
369
            self.absent_revisions.add(rev_id)
354
370
        else:
487
503
        self.bzrdir = to_convert
488
504
        pb = ui.ui_factory.nested_progress_bar()
489
505
        try:
490
 
            ui.ui_factory.note('starting upgrade from format 5 to 6')
 
506
            ui.ui_factory.note(gettext('starting upgrade from format 5 to 6'))
491
507
            self._convert_to_prefixed()
492
508
            return BzrDir.open(self.bzrdir.user_url)
493
509
        finally:
497
513
        from bzrlib.store import TransportStore
498
514
        self.bzrdir.transport.delete('branch-format')
499
515
        for store_name in ["weaves", "revision-store"]:
500
 
            ui.ui_factory.note("adding prefixes to %s" % store_name)
 
516
            ui.ui_factory.note(gettext("adding prefixes to %s") % store_name)
501
517
            store_transport = self.bzrdir.transport.clone(store_name)
502
518
            store = TransportStore(store_transport, prefixed=True)
503
519
            for urlfilename in store_transport.list_dir('.'):
537
553
        self.dir_mode = self.bzrdir._get_dir_mode()
538
554
        self.file_mode = self.bzrdir._get_file_mode()
539
555
 
540
 
        ui.ui_factory.note('starting upgrade from format 6 to metadir')
 
556
        ui.ui_factory.note(gettext('starting upgrade from format 6 to metadir'))
541
557
        self.bzrdir.transport.put_bytes(
542
558
                'branch-format',
543
559
                "Converting to format 6",
545
561
        # its faster to move specific files around than to open and use the apis...
546
562
        # first off, nuke ancestry.weave, it was never used.
547
563
        try:
548
 
            self.step('Removing ancestry.weave')
 
564
            self.step(gettext('Removing ancestry.weave'))
549
565
            self.bzrdir.transport.delete('ancestry.weave')
550
566
        except errors.NoSuchFile:
551
567
            pass
552
568
        # find out whats there
553
 
        self.step('Finding branch files')
 
569
        self.step(gettext('Finding branch files'))
554
570
        last_revision = self.bzrdir.open_branch().last_revision()
555
571
        bzrcontents = self.bzrdir.transport.list_dir('.')
556
572
        for name in bzrcontents:
560
576
        repository_names = [('inventory.weave', True),
561
577
                            ('revision-store', True),
562
578
                            ('weaves', True)]
563
 
        self.step('Upgrading repository  ')
 
579
        self.step(gettext('Upgrading repository') + '  ')
564
580
        self.bzrdir.transport.mkdir('repository', mode=self.dir_mode)
565
581
        self.make_lock('repository')
566
582
        # we hard code the formats here because we are converting into
570
586
        for entry in repository_names:
571
587
            self.move_entry('repository', entry)
572
588
 
573
 
        self.step('Upgrading branch      ')
 
589
        self.step(gettext('Upgrading branch') + '      ')
574
590
        self.bzrdir.transport.mkdir('branch', mode=self.dir_mode)
575
591
        self.make_lock('branch')
576
592
        self.put_format('branch', BzrBranchFormat5())
593
609
        else:
594
610
            has_checkout = True
595
611
        if not has_checkout:
596
 
            ui.ui_factory.note('No working tree.')
 
612
            ui.ui_factory.note(gettext('No working tree.'))
597
613
            # If some checkout files are there, we may as well get rid of them.
598
614
            for name, mandatory in checkout_files:
599
615
                if name in bzrcontents:
600
616
                    self.bzrdir.transport.delete(name)
601
617
        else:
602
618
            from bzrlib.workingtree_3 import WorkingTreeFormat3
603
 
            self.step('Upgrading working tree')
 
619
            self.step(gettext('Upgrading working tree'))
604
620
            self.bzrdir.transport.mkdir('checkout', mode=self.dir_mode)
605
621
            self.make_lock('checkout')
606
622
            self.put_format(
621
637
 
622
638
    def make_lock(self, name):
623
639
        """Make a lock for the new control dir name."""
624
 
        self.step('Make %s lock' % name)
 
640
        self.step(gettext('Make %s lock') % name)
625
641
        ld = lockdir.LockDir(self.bzrdir.transport,
626
642
                             '%s/lock' % name,
627
643
                             file_modebits=self.file_mode,
632
648
        """Move then entry name into new_dir."""
633
649
        name = entry[0]
634
650
        mandatory = entry[1]
635
 
        self.step('Moving %s' % name)
 
651
        self.step(gettext('Moving %s') % name)
636
652
        try:
637
653
            self.bzrdir.transport.move(name, '%s/%s' % (new_dir, name))
638
654
        except errors.NoSuchFile:
663
679
    def __eq__(self, other):
664
680
        return type(self) == type(other)
665
681
 
666
 
    def get_format_string(self):
 
682
    @classmethod
 
683
    def get_format_string(cls):
667
684
        """See BzrDirFormat.get_format_string()."""
668
685
        return "Bazaar-NG branch, format 0.0.4\n"
669
686
 
702
719
        return RepositoryFormat4()
703
720
    repository_format = property(__return_repository_format)
704
721
 
 
722
    @classmethod
 
723
    def from_string(cls, format_string):
 
724
        if format_string != cls.get_format_string():
 
725
            raise AssertionError("unexpected format string %r" % format_string)
 
726
        return cls()
 
727
 
705
728
 
706
729
class BzrDirPreSplitOut(BzrDir):
707
730
    """A common class for the all-in-one formats."""
747
770
            tree.clone(result)
748
771
        return result
749
772
 
750
 
    def create_branch(self, name=None, repository=None):
 
773
    def create_branch(self, name=None, repository=None,
 
774
                      append_revisions_only=None):
751
775
        """See BzrDir.create_branch."""
752
776
        if repository is not None:
753
777
            raise NotImplementedError(
754
778
                "create_branch(repository=<not None>) on %r" % (self,))
755
 
        return self._format.get_branch_format().initialize(self, name=name)
 
779
        return self._format.get_branch_format().initialize(self, name=name,
 
780
            append_revisions_only=append_revisions_only)
756
781
 
757
782
    def destroy_branch(self, name=None):
758
783
        """See BzrDir.destroy_branch."""
859
884
        return not isinstance(self._format, format.__class__)
860
885
 
861
886
    def open_branch(self, name=None, unsupported=False,
862
 
                    ignore_fallbacks=False):
 
887
                    ignore_fallbacks=False, possible_transports=None):
863
888
        """See BzrDir.open_branch."""
864
889
        from bzrlib.plugins.weave_fmt.branch import BzrBranchFormat4
865
890
        format = BzrBranchFormat4()
866
891
        format.check_support_status(unsupported)
867
 
        return format.open(self, name, _found=True)
 
892
        return format.open(self, name, _found=True,
 
893
            possible_transports=possible_transports)
868
894
 
869
895
    def sprout(self, url, revision_id=None, force_new_repo=False,
870
896
               possible_transports=None, accelerator_tree=None,
940
966
        from bzrlib.plugins.weave_fmt.repository import RepositoryFormat5
941
967
        return RepositoryFormat5().open(self, _found=True)
942
968
 
943
 
    def open_workingtree(self, _unsupported=False,
 
969
    def open_workingtree(self, unsupported=False,
944
970
            recommend_upgrade=True):
945
971
        """See BzrDir.create_workingtree."""
946
972
        from bzrlib.plugins.weave_fmt.workingtree import WorkingTreeFormat2
965
991
        from bzrlib.plugins.weave_fmt.repository import RepositoryFormat6
966
992
        return RepositoryFormat6().open(self, _found=True)
967
993
 
968
 
    def open_workingtree(self, _unsupported=False,
969
 
        recommend_upgrade=True):
 
994
    def open_workingtree(self, unsupported=False, recommend_upgrade=True):
970
995
        """See BzrDir.create_workingtree."""
971
996
        # we don't warn here about upgrades; that ought to be handled for the
972
997
        # bzrdir as a whole