/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: Vincent Ladeuil
  • Date: 2011-02-08 10:17:38 UTC
  • mto: (5609.2.12 2.3)
  • mto: This revision was merged to the branch mainline in revision 5652.
  • Revision ID: v.ladeuil+lp@free.fr-20110208101738-zvs9r18xy7youyhq
ReproduceĀ bugĀ #715068.

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
29
30
from bzrlib import (
30
31
    xml5,
31
32
    graph as _mod_graph,
 
33
    ui,
32
34
    )
33
35
""")
34
36
from bzrlib import (
38
40
    lockable_files,
39
41
    lockdir,
40
42
    osutils,
41
 
    revision as _mod_revision,
42
43
    trace,
 
44
    tuned_gzip,
43
45
    urlutils,
44
46
    versionedfile,
45
47
    weave,
48
50
from bzrlib.decorators import needs_read_lock, needs_write_lock
49
51
from bzrlib.repository import (
50
52
    CommitBuilder,
 
53
    InterRepository,
 
54
    InterSameDataRepository,
51
55
    MetaDirVersionedFileRepository,
52
56
    MetaDirRepositoryFormat,
53
57
    Repository,
54
58
    RepositoryFormat,
55
59
    )
56
60
from bzrlib.store.text import TextStore
57
 
from bzrlib.tuned_gzip import GzipFile, bytes_to_gzip
58
61
from bzrlib.versionedfile import (
59
62
    AbsentContentFactory,
60
63
    FulltextContentFactory,
337
340
    has been removed.
338
341
    """
339
342
 
 
343
    supports_funky_characters = False
 
344
 
340
345
    _matchingbzrdir = bzrdir.BzrDirFormat4()
341
346
 
342
347
    def get_format_description(self):
386
391
 
387
392
    _versionedfile_class = weave.WeaveFile
388
393
    _matchingbzrdir = bzrdir.BzrDirFormat5()
 
394
    supports_funky_characters = False
 
395
 
389
396
    @property
390
397
    def _serializer(self):
391
398
        return xml5.serializer_v5
431
438
 
432
439
    _versionedfile_class = weave.WeaveFile
433
440
    _matchingbzrdir = bzrdir.BzrDirFormat6()
 
441
    supports_funky_characters = False
434
442
    @property
435
443
    def _serializer(self):
436
444
        return xml5.serializer_v5
587
595
            raise ValueError('bad idea to put / in %r' % (key,))
588
596
        text = ''.join(lines)
589
597
        if self._compressed:
590
 
            text = bytes_to_gzip(text)
 
598
            text = tuned_gzip.bytes_to_gzip(text)
591
599
        path = self._map(key)
592
600
        self._transport.put_bytes_non_atomic(path, text, create_parent_dir=True)
593
601
 
635
643
            else:
636
644
                return None
637
645
        if compressed:
638
 
            text = GzipFile(mode='rb', fileobj=StringIO(text)).read()
 
646
            text = gzip.GzipFile(mode='rb', fileobj=StringIO(text)).read()
639
647
        return text
640
648
 
641
649
    def _map(self, key):
738
746
        paths = list(relpaths)
739
747
        return set([self._mapper.unmap(path) for path in paths])
740
748
 
 
749
 
 
750
class InterWeaveRepo(InterSameDataRepository):
 
751
    """Optimised code paths between Weave based repositories.
 
752
    """
 
753
 
 
754
    @classmethod
 
755
    def _get_repo_format_to_test(self):
 
756
        return RepositoryFormat7()
 
757
 
 
758
    @staticmethod
 
759
    def is_compatible(source, target):
 
760
        """Be compatible with known Weave formats.
 
761
 
 
762
        We don't test for the stores being of specific types because that
 
763
        could lead to confusing results, and there is no need to be
 
764
        overly general.
 
765
        """
 
766
        try:
 
767
            return (isinstance(source._format, (RepositoryFormat5,
 
768
                                                RepositoryFormat6,
 
769
                                                RepositoryFormat7)) and
 
770
                    isinstance(target._format, (RepositoryFormat5,
 
771
                                                RepositoryFormat6,
 
772
                                                RepositoryFormat7)))
 
773
        except AttributeError:
 
774
            return False
 
775
 
 
776
    @needs_write_lock
 
777
    def copy_content(self, revision_id=None):
 
778
        """See InterRepository.copy_content()."""
 
779
        # weave specific optimised path:
 
780
        try:
 
781
            self.target.set_make_working_trees(self.source.make_working_trees())
 
782
        except (errors.RepositoryUpgradeRequired, NotImplemented):
 
783
            pass
 
784
        # FIXME do not peek!
 
785
        if self.source._transport.listable():
 
786
            pb = ui.ui_factory.nested_progress_bar()
 
787
            try:
 
788
                self.target.texts.insert_record_stream(
 
789
                    self.source.texts.get_record_stream(
 
790
                        self.source.texts.keys(), 'topological', False))
 
791
                pb.update('Copying inventory', 0, 1)
 
792
                self.target.inventories.insert_record_stream(
 
793
                    self.source.inventories.get_record_stream(
 
794
                        self.source.inventories.keys(), 'topological', False))
 
795
                self.target.signatures.insert_record_stream(
 
796
                    self.source.signatures.get_record_stream(
 
797
                        self.source.signatures.keys(),
 
798
                        'unordered', True))
 
799
                self.target.revisions.insert_record_stream(
 
800
                    self.source.revisions.get_record_stream(
 
801
                        self.source.revisions.keys(),
 
802
                        'topological', True))
 
803
            finally:
 
804
                pb.finished()
 
805
        else:
 
806
            self.target.fetch(self.source, revision_id=revision_id)
 
807
 
 
808
    @needs_read_lock
 
809
    def search_missing_revision_ids(self, revision_id=None, find_ghosts=True):
 
810
        """See InterRepository.missing_revision_ids()."""
 
811
        # we want all revisions to satisfy revision_id in source.
 
812
        # but we don't want to stat every file here and there.
 
813
        # we want then, all revisions other needs to satisfy revision_id
 
814
        # checked, but not those that we have locally.
 
815
        # so the first thing is to get a subset of the revisions to
 
816
        # satisfy revision_id in source, and then eliminate those that
 
817
        # we do already have.
 
818
        # this is slow on high latency connection to self, but as this
 
819
        # disk format scales terribly for push anyway due to rewriting
 
820
        # inventory.weave, this is considered acceptable.
 
821
        # - RBC 20060209
 
822
        if revision_id is not None:
 
823
            source_ids = self.source.get_ancestry(revision_id)
 
824
            if source_ids[0] is not None:
 
825
                raise AssertionError()
 
826
            source_ids.pop(0)
 
827
        else:
 
828
            source_ids = self.source._all_possible_ids()
 
829
        source_ids_set = set(source_ids)
 
830
        # source_ids is the worst possible case we may need to pull.
 
831
        # now we want to filter source_ids against what we actually
 
832
        # have in target, but don't try to check for existence where we know
 
833
        # we do not have a revision as that would be pointless.
 
834
        target_ids = set(self.target._all_possible_ids())
 
835
        possibly_present_revisions = target_ids.intersection(source_ids_set)
 
836
        actually_present_revisions = set(
 
837
            self.target._eliminate_revisions_not_present(possibly_present_revisions))
 
838
        required_revisions = source_ids_set.difference(actually_present_revisions)
 
839
        if revision_id is not None:
 
840
            # we used get_ancestry to determine source_ids then we are assured all
 
841
            # revisions referenced are present as they are installed in topological order.
 
842
            # and the tip revision was validated by get_ancestry.
 
843
            result_set = required_revisions
 
844
        else:
 
845
            # if we just grabbed the possibly available ids, then
 
846
            # we only have an estimate of whats available and need to validate
 
847
            # that against the revision records.
 
848
            result_set = set(
 
849
                self.source._eliminate_revisions_not_present(required_revisions))
 
850
        return self.source.revision_ids_to_search_result(result_set)
 
851
 
 
852
 
741
853
_legacy_formats = [RepositoryFormat4(),
742
854
                   RepositoryFormat5(),
743
855
                   RepositoryFormat6()]
 
856
 
 
857
 
 
858
InterRepository.register_optimiser(InterWeaveRepo)