~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repofmt/weaverepo.py

(vila) Make it clearer that 'bzr st' can be used to determine which files
 changed in a particular revision (John C Barstow)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2011 Canonical Ltd
 
1
# Copyright (C) 2007-2010 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
24
23
import os
25
24
from cStringIO import StringIO
26
25
import urllib
27
26
 
28
27
from bzrlib.lazy_import import lazy_import
29
28
lazy_import(globals(), """
30
 
import itertools
31
 
 
32
29
from bzrlib import (
33
30
    xml5,
34
31
    graph as _mod_graph,
35
 
    ui,
36
32
    )
37
33
""")
38
34
from bzrlib import (
 
35
    bzrdir,
39
36
    debug,
40
37
    errors,
41
38
    lockable_files,
42
39
    lockdir,
43
40
    osutils,
44
 
    symbol_versioning,
 
41
    revision as _mod_revision,
45
42
    trace,
46
 
    tuned_gzip,
47
43
    urlutils,
48
44
    versionedfile,
49
45
    weave,
51
47
    )
52
48
from bzrlib.decorators import needs_read_lock, needs_write_lock
53
49
from bzrlib.repository import (
54
 
    InterRepository,
 
50
    CommitBuilder,
 
51
    MetaDirVersionedFileRepository,
 
52
    MetaDirRepositoryFormat,
 
53
    Repository,
55
54
    RepositoryFormat,
56
55
    )
57
56
from bzrlib.store.text import TextStore
 
57
from bzrlib.tuned_gzip import GzipFile, bytes_to_gzip
58
58
from bzrlib.versionedfile import (
59
59
    AbsentContentFactory,
60
60
    FulltextContentFactory,
61
61
    VersionedFiles,
62
62
    )
63
 
from bzrlib.vf_repository import (
64
 
    InterSameDataRepository,
65
 
    VersionedFileCommitBuilder,
66
 
    VersionedFileRepository,
67
 
    VersionedFileRepositoryFormat,
68
 
    MetaDirVersionedFileRepository,
69
 
    MetaDirVersionedFileRepositoryFormat,
70
 
    )
71
 
 
72
 
from bzrlib.plugins.weave_fmt import bzrdir as weave_bzrdir
73
 
 
74
 
 
75
 
class AllInOneRepository(VersionedFileRepository):
 
63
 
 
64
 
 
65
class AllInOneRepository(Repository):
76
66
    """Legacy support - the repository behaviour for all-in-one branches."""
77
67
 
78
68
    @property
150
140
 
151
141
    def get_commit_builder(self, branch, parents, config, timestamp=None,
152
142
                           timezone=None, committer=None, revprops=None,
153
 
                           revision_id=None, lossy=False):
 
143
                           revision_id=None):
154
144
        self._check_ascii_revisionid(revision_id, self.get_commit_builder)
155
 
        result = VersionedFileCommitBuilder(self, parents, config, timestamp,
156
 
            timezone, committer, revprops, revision_id, lossy=lossy)
 
145
        result = CommitBuilder(self, parents, config, timestamp, timezone,
 
146
                              committer, revprops, revision_id)
157
147
        self.start_write_group()
158
148
        return result
159
149
 
193
183
        """Returns the policy for making working trees on new branches."""
194
184
        return True
195
185
 
 
186
    def revision_graph_can_have_wrong_parents(self):
 
187
        # XXX: This is an old format that we don't support full checking on, so
 
188
        # just claim that checking for this inconsistency is not required.
 
189
        return False
 
190
 
196
191
 
197
192
class WeaveMetaDirRepository(MetaDirVersionedFileRepository):
198
193
    """A subclass of MetaDirRepository to set weave specific policy."""
239
234
 
240
235
    def get_commit_builder(self, branch, parents, config, timestamp=None,
241
236
                           timezone=None, committer=None, revprops=None,
242
 
                           revision_id=None, lossy=False):
 
237
                           revision_id=None):
243
238
        self._check_ascii_revisionid(revision_id, self.get_commit_builder)
244
 
        result = VersionedFileCommitBuilder(self, parents, config, timestamp,
245
 
            timezone, committer, revprops, revision_id, lossy=lossy)
 
239
        result = CommitBuilder(self, parents, config, timestamp, timezone,
 
240
                              committer, revprops, revision_id)
246
241
        self.start_write_group()
247
242
        return result
248
243
 
263
258
        return self.inventories.add_lines((revision_id,), final_parents, lines,
264
259
            check_content=check_content)[0]
265
260
 
266
 
 
267
 
class PreSplitOutRepositoryFormat(VersionedFileRepositoryFormat):
 
261
    def revision_graph_can_have_wrong_parents(self):
 
262
        return False
 
263
 
 
264
 
 
265
class PreSplitOutRepositoryFormat(RepositoryFormat):
268
266
    """Base class for the pre split out repository formats."""
269
267
 
270
268
    rich_root_data = False
272
270
    supports_ghosts = False
273
271
    supports_external_lookups = False
274
272
    supports_chks = False
275
 
    supports_nesting_repositories = True
276
273
    _fetch_order = 'topological'
277
274
    _fetch_reconcile = True
278
275
    fast_deltas = False
279
 
    supports_leaving_lock = False
280
 
    # XXX: This is an old format that we don't support full checking on, so
281
 
    # just claim that checking for this inconsistency is not required.
282
 
    revision_graph_can_have_wrong_parents = False
283
276
 
284
277
    def initialize(self, a_bzrdir, shared=False, _internal=False):
285
278
        """Create a weave repository."""
322
315
            raise NotImplementedError
323
316
 
324
317
        repo_transport = a_bzrdir.get_repository_transport(None)
 
318
        control_files = a_bzrdir._control_files
325
319
        result = AllInOneRepository(_format=self, a_bzrdir=a_bzrdir)
326
320
        result.revisions = self._get_revisions(repo_transport, result)
327
321
        result.signatures = self._get_signatures(repo_transport, result)
330
324
        result.chk_bytes = None
331
325
        return result
332
326
 
333
 
    def is_deprecated(self):
334
 
        return True
335
 
 
336
327
 
337
328
class RepositoryFormat4(PreSplitOutRepositoryFormat):
338
329
    """Bzr repository format 4.
346
337
    has been removed.
347
338
    """
348
339
 
349
 
    supports_funky_characters = False
350
 
 
351
 
    _matchingbzrdir = weave_bzrdir.BzrDirFormat4()
 
340
    _matchingbzrdir = bzrdir.BzrDirFormat4()
352
341
 
353
342
    def get_format_description(self):
354
343
        """See RepositoryFormat.get_format_description()."""
372
361
        return None
373
362
 
374
363
    def _get_revisions(self, repo_transport, repo):
375
 
        from bzrlib.plugins.weave_fmt.xml4 import serializer_v4
 
364
        from bzrlib.xml4 import serializer_v4
376
365
        return RevisionTextStore(repo_transport.clone('revision-store'),
377
366
            serializer_v4, True, versionedfile.PrefixMapper(),
378
367
            repo.is_locked, repo.is_write_locked)
396
385
    """
397
386
 
398
387
    _versionedfile_class = weave.WeaveFile
399
 
    _matchingbzrdir = weave_bzrdir.BzrDirFormat5()
400
 
    supports_funky_characters = False
401
 
 
 
388
    _matchingbzrdir = bzrdir.BzrDirFormat5()
402
389
    @property
403
390
    def _serializer(self):
404
391
        return xml5.serializer_v5
443
430
    """
444
431
 
445
432
    _versionedfile_class = weave.WeaveFile
446
 
    _matchingbzrdir = weave_bzrdir.BzrDirFormat6()
447
 
    supports_funky_characters = False
 
433
    _matchingbzrdir = bzrdir.BzrDirFormat6()
448
434
    @property
449
435
    def _serializer(self):
450
436
        return xml5.serializer_v5
479
465
            weave.WeaveFile, mapper, repo.is_locked)
480
466
 
481
467
 
482
 
class RepositoryFormat7(MetaDirVersionedFileRepositoryFormat):
 
468
class RepositoryFormat7(MetaDirRepositoryFormat):
483
469
    """Bzr repository 7.
484
470
 
485
471
    This repository format has:
494
480
    _versionedfile_class = weave.WeaveFile
495
481
    supports_ghosts = False
496
482
    supports_chks = False
497
 
    supports_funky_characters = False
498
 
    revision_graph_can_have_wrong_parents = False
499
483
 
500
484
    _fetch_order = 'topological'
501
485
    _fetch_reconcile = True
578
562
        result._transport = repo_transport
579
563
        return result
580
564
 
581
 
    def is_deprecated(self):
582
 
        return True
583
 
 
584
565
 
585
566
class TextVersionedFiles(VersionedFiles):
586
567
    """Just-a-bunch-of-files based VersionedFile stores."""
606
587
            raise ValueError('bad idea to put / in %r' % (key,))
607
588
        text = ''.join(lines)
608
589
        if self._compressed:
609
 
            text = tuned_gzip.bytes_to_gzip(text)
 
590
            text = bytes_to_gzip(text)
610
591
        path = self._map(key)
611
592
        self._transport.put_bytes_non_atomic(path, text, create_parent_dir=True)
612
593
 
632
613
                    record, record.get_bytes_as(record.storage_kind)))
633
614
                try:
634
615
                    self.add_lines(record.key, None, lines)
635
 
                except errors.RevisionAlreadyPresent:
 
616
                except RevisionAlreadyPresent:
636
617
                    pass
637
618
 
638
619
    def _load_text(self, key):
654
635
            else:
655
636
                return None
656
637
        if compressed:
657
 
            text = gzip.GzipFile(mode='rb', fileobj=StringIO(text)).read()
 
638
            text = GzipFile(mode='rb', fileobj=StringIO(text)).read()
658
639
        return text
659
640
 
660
641
    def _map(self, key):
757
738
        paths = list(relpaths)
758
739
        return set([self._mapper.unmap(path) for path in paths])
759
740
 
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
 
            limit=None):
824
 
        """See InterRepository.search_missing_revision_ids()."""
825
 
        # we want all revisions to satisfy revision_id in source.
826
 
        # but we don't want to stat every file here and there.
827
 
        # we want then, all revisions other needs to satisfy revision_id
828
 
        # checked, but not those that we have locally.
829
 
        # so the first thing is to get a subset of the revisions to
830
 
        # satisfy revision_id in source, and then eliminate those that
831
 
        # we do already have.
832
 
        # this is slow on high latency connection to self, but as this
833
 
        # disk format scales terribly for push anyway due to rewriting
834
 
        # inventory.weave, this is considered acceptable.
835
 
        # - RBC 20060209
836
 
        if symbol_versioning.deprecated_passed(revision_id):
837
 
            symbol_versioning.warn(
838
 
                'search_missing_revision_ids(revision_id=...) was '
839
 
                'deprecated in 2.4.  Use revision_ids=[...] instead.',
840
 
                DeprecationWarning, stacklevel=2)
841
 
            if revision_ids is not None:
842
 
                raise AssertionError(
843
 
                    'revision_ids is mutually exclusive with revision_id')
844
 
            if revision_id is not None:
845
 
                revision_ids = [revision_id]
846
 
        del revision_id
847
 
        source_ids_set = self._present_source_revisions_for(
848
 
            revision_ids, if_present_ids)
849
 
        # source_ids is the worst possible case we may need to pull.
850
 
        # now we want to filter source_ids against what we actually
851
 
        # have in target, but don't try to check for existence where we know
852
 
        # we do not have a revision as that would be pointless.
853
 
        target_ids = set(self.target._all_possible_ids())
854
 
        possibly_present_revisions = target_ids.intersection(source_ids_set)
855
 
        actually_present_revisions = set(
856
 
            self.target._eliminate_revisions_not_present(possibly_present_revisions))
857
 
        required_revisions = source_ids_set.difference(actually_present_revisions)
858
 
        if revision_ids is not None:
859
 
            # we used get_ancestry to determine source_ids then we are assured all
860
 
            # revisions referenced are present as they are installed in topological order.
861
 
            # and the tip revision was validated by get_ancestry.
862
 
            result_set = required_revisions
863
 
        else:
864
 
            # if we just grabbed the possibly available ids, then
865
 
            # we only have an estimate of whats available and need to validate
866
 
            # that against the revision records.
867
 
            result_set = set(
868
 
                self.source._eliminate_revisions_not_present(required_revisions))
869
 
        if limit is not None:
870
 
            topo_ordered = self.get_graph().iter_topo_order(result_set)
871
 
            result_set = set(itertools.islice(topo_ordered, limit))
872
 
        return self.source.revision_ids_to_search_result(result_set)
873
 
 
874
 
 
875
 
InterRepository.register_optimiser(InterWeaveRepo)
876
 
 
877
 
 
878
 
def get_extra_interrepo_test_combinations():
879
 
    from bzrlib.repofmt import knitrepo
880
 
    return [(InterRepository, RepositoryFormat5(),
881
 
        knitrepo.RepositoryFormatKnit3())]
 
741
_legacy_formats = [RepositoryFormat4(),
 
742
                   RepositoryFormat5(),
 
743
                   RepositoryFormat6()]