/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/repofmt/weaverepo.py

  • Committer: Jelmer Vernooij
  • Date: 2011-03-22 12:10:34 UTC
  • mto: This revision was merged to the branch mainline in revision 5737.
  • Revision ID: jelmer@samba.org-20110322121034-70a7037sqrs2l2no
Rename check_status -> check_support_status.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2010 Canonical Ltd
 
1
# Copyright (C) 2007-2011 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
20
20
ghosts.
21
21
"""
22
22
 
 
23
import gzip
23
24
import os
24
25
from cStringIO import StringIO
25
26
import urllib
27
28
from bzrlib.lazy_import import lazy_import
28
29
lazy_import(globals(), """
29
30
from bzrlib import (
 
31
    bzrdir_weave,
30
32
    xml5,
31
33
    graph as _mod_graph,
 
34
    ui,
32
35
    )
33
36
""")
34
37
from bzrlib import (
35
 
    bzrdir,
36
38
    debug,
37
39
    errors,
38
40
    lockable_files,
39
41
    lockdir,
40
42
    osutils,
41
 
    revision as _mod_revision,
 
43
    symbol_versioning,
42
44
    trace,
 
45
    tuned_gzip,
43
46
    urlutils,
44
47
    versionedfile,
45
48
    weave,
48
51
from bzrlib.decorators import needs_read_lock, needs_write_lock
49
52
from bzrlib.repository import (
50
53
    CommitBuilder,
 
54
    InterRepository,
 
55
    InterSameDataRepository,
51
56
    MetaDirVersionedFileRepository,
52
57
    MetaDirRepositoryFormat,
53
58
    Repository,
54
59
    RepositoryFormat,
55
60
    )
56
61
from bzrlib.store.text import TextStore
57
 
from bzrlib.tuned_gzip import GzipFile, bytes_to_gzip
58
62
from bzrlib.versionedfile import (
59
63
    AbsentContentFactory,
60
64
    FulltextContentFactory,
273
277
    _fetch_order = 'topological'
274
278
    _fetch_reconcile = True
275
279
    fast_deltas = False
 
280
    supports_leaving_lock = False
 
281
    supports_full_versioned_files = True
276
282
 
277
283
    def initialize(self, a_bzrdir, shared=False, _internal=False):
278
284
        """Create a weave repository."""
324
330
        result.chk_bytes = None
325
331
        return result
326
332
 
 
333
    def is_deprecated(self):
 
334
        return True
 
335
 
327
336
 
328
337
class RepositoryFormat4(PreSplitOutRepositoryFormat):
329
338
    """Bzr repository format 4.
337
346
    has been removed.
338
347
    """
339
348
 
340
 
    _matchingbzrdir = bzrdir.BzrDirFormat4()
 
349
    supports_funky_characters = False
 
350
 
 
351
    _matchingbzrdir = bzrdir_weave.BzrDirFormat4()
341
352
 
342
353
    def get_format_description(self):
343
354
        """See RepositoryFormat.get_format_description()."""
385
396
    """
386
397
 
387
398
    _versionedfile_class = weave.WeaveFile
388
 
    _matchingbzrdir = bzrdir.BzrDirFormat5()
 
399
    _matchingbzrdir = bzrdir_weave.BzrDirFormat5()
 
400
    supports_funky_characters = False
 
401
 
389
402
    @property
390
403
    def _serializer(self):
391
404
        return xml5.serializer_v5
430
443
    """
431
444
 
432
445
    _versionedfile_class = weave.WeaveFile
433
 
    _matchingbzrdir = bzrdir.BzrDirFormat6()
 
446
    _matchingbzrdir = bzrdir_weave.BzrDirFormat6()
 
447
    supports_funky_characters = False
434
448
    @property
435
449
    def _serializer(self):
436
450
        return xml5.serializer_v5
480
494
    _versionedfile_class = weave.WeaveFile
481
495
    supports_ghosts = False
482
496
    supports_chks = False
 
497
    supports_funky_characters = False
 
498
    supports_full_versioned_files = True
483
499
 
484
500
    _fetch_order = 'topological'
485
501
    _fetch_reconcile = True
562
578
        result._transport = repo_transport
563
579
        return result
564
580
 
 
581
    def is_deprecated(self):
 
582
        return True
 
583
 
565
584
 
566
585
class TextVersionedFiles(VersionedFiles):
567
586
    """Just-a-bunch-of-files based VersionedFile stores."""
587
606
            raise ValueError('bad idea to put / in %r' % (key,))
588
607
        text = ''.join(lines)
589
608
        if self._compressed:
590
 
            text = bytes_to_gzip(text)
 
609
            text = tuned_gzip.bytes_to_gzip(text)
591
610
        path = self._map(key)
592
611
        self._transport.put_bytes_non_atomic(path, text, create_parent_dir=True)
593
612
 
635
654
            else:
636
655
                return None
637
656
        if compressed:
638
 
            text = GzipFile(mode='rb', fileobj=StringIO(text)).read()
 
657
            text = gzip.GzipFile(mode='rb', fileobj=StringIO(text)).read()
639
658
        return text
640
659
 
641
660
    def _map(self, key):
738
757
        paths = list(relpaths)
739
758
        return set([self._mapper.unmap(path) for path in paths])
740
759
 
741
 
_legacy_formats = [RepositoryFormat4(),
742
 
                   RepositoryFormat5(),
743
 
                   RepositoryFormat6()]
 
760
 
 
761
class InterWeaveRepo(InterSameDataRepository):
 
762
    """Optimised code paths between Weave based repositories.
 
763
    """
 
764
 
 
765
    @classmethod
 
766
    def _get_repo_format_to_test(self):
 
767
        return RepositoryFormat7()
 
768
 
 
769
    @staticmethod
 
770
    def is_compatible(source, target):
 
771
        """Be compatible with known Weave formats.
 
772
 
 
773
        We don't test for the stores being of specific types because that
 
774
        could lead to confusing results, and there is no need to be
 
775
        overly general.
 
776
        """
 
777
        try:
 
778
            return (isinstance(source._format, (RepositoryFormat5,
 
779
                                                RepositoryFormat6,
 
780
                                                RepositoryFormat7)) and
 
781
                    isinstance(target._format, (RepositoryFormat5,
 
782
                                                RepositoryFormat6,
 
783
                                                RepositoryFormat7)))
 
784
        except AttributeError:
 
785
            return False
 
786
 
 
787
    @needs_write_lock
 
788
    def copy_content(self, revision_id=None):
 
789
        """See InterRepository.copy_content()."""
 
790
        # weave specific optimised path:
 
791
        try:
 
792
            self.target.set_make_working_trees(self.source.make_working_trees())
 
793
        except (errors.RepositoryUpgradeRequired, NotImplemented):
 
794
            pass
 
795
        # FIXME do not peek!
 
796
        if self.source._transport.listable():
 
797
            pb = ui.ui_factory.nested_progress_bar()
 
798
            try:
 
799
                self.target.texts.insert_record_stream(
 
800
                    self.source.texts.get_record_stream(
 
801
                        self.source.texts.keys(), 'topological', False))
 
802
                pb.update('Copying inventory', 0, 1)
 
803
                self.target.inventories.insert_record_stream(
 
804
                    self.source.inventories.get_record_stream(
 
805
                        self.source.inventories.keys(), 'topological', False))
 
806
                self.target.signatures.insert_record_stream(
 
807
                    self.source.signatures.get_record_stream(
 
808
                        self.source.signatures.keys(),
 
809
                        'unordered', True))
 
810
                self.target.revisions.insert_record_stream(
 
811
                    self.source.revisions.get_record_stream(
 
812
                        self.source.revisions.keys(),
 
813
                        'topological', True))
 
814
            finally:
 
815
                pb.finished()
 
816
        else:
 
817
            self.target.fetch(self.source, revision_id=revision_id)
 
818
 
 
819
    @needs_read_lock
 
820
    def search_missing_revision_ids(self,
 
821
            revision_id=symbol_versioning.DEPRECATED_PARAMETER,
 
822
            find_ghosts=True, revision_ids=None, if_present_ids=None):
 
823
        """See InterRepository.search_missing_revision_ids()."""
 
824
        # we want all revisions to satisfy revision_id in source.
 
825
        # but we don't want to stat every file here and there.
 
826
        # we want then, all revisions other needs to satisfy revision_id
 
827
        # checked, but not those that we have locally.
 
828
        # so the first thing is to get a subset of the revisions to
 
829
        # satisfy revision_id in source, and then eliminate those that
 
830
        # we do already have.
 
831
        # this is slow on high latency connection to self, but as this
 
832
        # disk format scales terribly for push anyway due to rewriting
 
833
        # inventory.weave, this is considered acceptable.
 
834
        # - RBC 20060209
 
835
        if symbol_versioning.deprecated_passed(revision_id):
 
836
            symbol_versioning.warn(
 
837
                'search_missing_revision_ids(revision_id=...) was '
 
838
                'deprecated in 2.4.  Use revision_ids=[...] instead.',
 
839
                DeprecationWarning, stacklevel=2)
 
840
            if revision_ids is not None:
 
841
                raise AssertionError(
 
842
                    'revision_ids is mutually exclusive with revision_id')
 
843
            if revision_id is not None:
 
844
                revision_ids = [revision_id]
 
845
        del revision_id
 
846
        source_ids_set = self._present_source_revisions_for(
 
847
            revision_ids, if_present_ids)
 
848
        # source_ids is the worst possible case we may need to pull.
 
849
        # now we want to filter source_ids against what we actually
 
850
        # have in target, but don't try to check for existence where we know
 
851
        # we do not have a revision as that would be pointless.
 
852
        target_ids = set(self.target._all_possible_ids())
 
853
        possibly_present_revisions = target_ids.intersection(source_ids_set)
 
854
        actually_present_revisions = set(
 
855
            self.target._eliminate_revisions_not_present(possibly_present_revisions))
 
856
        required_revisions = source_ids_set.difference(actually_present_revisions)
 
857
        if revision_ids is not None:
 
858
            # we used get_ancestry to determine source_ids then we are assured all
 
859
            # revisions referenced are present as they are installed in topological order.
 
860
            # and the tip revision was validated by get_ancestry.
 
861
            result_set = required_revisions
 
862
        else:
 
863
            # if we just grabbed the possibly available ids, then
 
864
            # we only have an estimate of whats available and need to validate
 
865
            # that against the revision records.
 
866
            result_set = set(
 
867
                self.source._eliminate_revisions_not_present(required_revisions))
 
868
        return self.source.revision_ids_to_search_result(result_set)
 
869
 
 
870
 
 
871
InterRepository.register_optimiser(InterWeaveRepo)
 
872
 
 
873
 
 
874
def get_extra_interrepo_test_combinations():
 
875
    from bzrlib.repofmt import knitrepo
 
876
    return [(InterRepository, RepositoryFormat5(),
 
877
        knitrepo.RepositoryFormatKnit3())]