/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

(jameinel) Transform.rename test shouldn't assume the str form of the
 exception because of locale issues. (Martin [gz])

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,
587
590
            raise ValueError('bad idea to put / in %r' % (key,))
588
591
        text = ''.join(lines)
589
592
        if self._compressed:
590
 
            text = bytes_to_gzip(text)
 
593
            text = tuned_gzip.bytes_to_gzip(text)
591
594
        path = self._map(key)
592
595
        self._transport.put_bytes_non_atomic(path, text, create_parent_dir=True)
593
596
 
635
638
            else:
636
639
                return None
637
640
        if compressed:
638
 
            text = GzipFile(mode='rb', fileobj=StringIO(text)).read()
 
641
            text = gzip.GzipFile(mode='rb', fileobj=StringIO(text)).read()
639
642
        return text
640
643
 
641
644
    def _map(self, key):
738
741
        paths = list(relpaths)
739
742
        return set([self._mapper.unmap(path) for path in paths])
740
743
 
 
744
 
 
745
class InterWeaveRepo(InterSameDataRepository):
 
746
    """Optimised code paths between Weave based repositories.
 
747
    """
 
748
 
 
749
    @classmethod
 
750
    def _get_repo_format_to_test(self):
 
751
        return RepositoryFormat7()
 
752
 
 
753
    @staticmethod
 
754
    def is_compatible(source, target):
 
755
        """Be compatible with known Weave formats.
 
756
 
 
757
        We don't test for the stores being of specific types because that
 
758
        could lead to confusing results, and there is no need to be
 
759
        overly general.
 
760
        """
 
761
        try:
 
762
            return (isinstance(source._format, (RepositoryFormat5,
 
763
                                                RepositoryFormat6,
 
764
                                                RepositoryFormat7)) and
 
765
                    isinstance(target._format, (RepositoryFormat5,
 
766
                                                RepositoryFormat6,
 
767
                                                RepositoryFormat7)))
 
768
        except AttributeError:
 
769
            return False
 
770
 
 
771
    @needs_write_lock
 
772
    def copy_content(self, revision_id=None):
 
773
        """See InterRepository.copy_content()."""
 
774
        # weave specific optimised path:
 
775
        try:
 
776
            self.target.set_make_working_trees(self.source.make_working_trees())
 
777
        except (errors.RepositoryUpgradeRequired, NotImplemented):
 
778
            pass
 
779
        # FIXME do not peek!
 
780
        if self.source._transport.listable():
 
781
            pb = ui.ui_factory.nested_progress_bar()
 
782
            try:
 
783
                self.target.texts.insert_record_stream(
 
784
                    self.source.texts.get_record_stream(
 
785
                        self.source.texts.keys(), 'topological', False))
 
786
                pb.update('Copying inventory', 0, 1)
 
787
                self.target.inventories.insert_record_stream(
 
788
                    self.source.inventories.get_record_stream(
 
789
                        self.source.inventories.keys(), 'topological', False))
 
790
                self.target.signatures.insert_record_stream(
 
791
                    self.source.signatures.get_record_stream(
 
792
                        self.source.signatures.keys(),
 
793
                        'unordered', True))
 
794
                self.target.revisions.insert_record_stream(
 
795
                    self.source.revisions.get_record_stream(
 
796
                        self.source.revisions.keys(),
 
797
                        'topological', True))
 
798
            finally:
 
799
                pb.finished()
 
800
        else:
 
801
            self.target.fetch(self.source, revision_id=revision_id)
 
802
 
 
803
    @needs_read_lock
 
804
    def search_missing_revision_ids(self, revision_id=None, find_ghosts=True):
 
805
        """See InterRepository.missing_revision_ids()."""
 
806
        # we want all revisions to satisfy revision_id in source.
 
807
        # but we don't want to stat every file here and there.
 
808
        # we want then, all revisions other needs to satisfy revision_id
 
809
        # checked, but not those that we have locally.
 
810
        # so the first thing is to get a subset of the revisions to
 
811
        # satisfy revision_id in source, and then eliminate those that
 
812
        # we do already have.
 
813
        # this is slow on high latency connection to self, but as this
 
814
        # disk format scales terribly for push anyway due to rewriting
 
815
        # inventory.weave, this is considered acceptable.
 
816
        # - RBC 20060209
 
817
        if revision_id is not None:
 
818
            source_ids = self.source.get_ancestry(revision_id)
 
819
            if source_ids[0] is not None:
 
820
                raise AssertionError()
 
821
            source_ids.pop(0)
 
822
        else:
 
823
            source_ids = self.source._all_possible_ids()
 
824
        source_ids_set = set(source_ids)
 
825
        # source_ids is the worst possible case we may need to pull.
 
826
        # now we want to filter source_ids against what we actually
 
827
        # have in target, but don't try to check for existence where we know
 
828
        # we do not have a revision as that would be pointless.
 
829
        target_ids = set(self.target._all_possible_ids())
 
830
        possibly_present_revisions = target_ids.intersection(source_ids_set)
 
831
        actually_present_revisions = set(
 
832
            self.target._eliminate_revisions_not_present(possibly_present_revisions))
 
833
        required_revisions = source_ids_set.difference(actually_present_revisions)
 
834
        if revision_id is not None:
 
835
            # we used get_ancestry to determine source_ids then we are assured all
 
836
            # revisions referenced are present as they are installed in topological order.
 
837
            # and the tip revision was validated by get_ancestry.
 
838
            result_set = required_revisions
 
839
        else:
 
840
            # if we just grabbed the possibly available ids, then
 
841
            # we only have an estimate of whats available and need to validate
 
842
            # that against the revision records.
 
843
            result_set = set(
 
844
                self.source._eliminate_revisions_not_present(required_revisions))
 
845
        return self.source.revision_ids_to_search_result(result_set)
 
846
 
 
847
 
741
848
_legacy_formats = [RepositoryFormat4(),
742
849
                   RepositoryFormat5(),
743
850
                   RepositoryFormat6()]
 
851
 
 
852
 
 
853
InterRepository.register_optimiser(InterWeaveRepo)