~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repofmt/weaverepo.py

  • Committer: Andrew Bennetts
  • Date: 2010-10-08 08:15:14 UTC
  • mto: This revision was merged to the branch mainline in revision 5498.
  • Revision ID: andrew.bennetts@canonical.com-20101008081514-dviqzrdfwyzsqbz2
Split NEWS into per-release doc/en/release-notes/bzr-*.txt

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
 
from __future__ import absolute_import
24
 
 
25
 
import gzip
26
23
import os
27
24
from cStringIO import StringIO
 
25
import urllib
28
26
 
29
27
from bzrlib.lazy_import import lazy_import
30
28
lazy_import(globals(), """
31
 
import itertools
32
 
 
33
29
from bzrlib import (
34
30
    xml5,
35
31
    graph as _mod_graph,
36
 
    ui,
37
32
    )
38
33
""")
39
34
from bzrlib import (
 
35
    bzrdir,
40
36
    debug,
41
37
    errors,
42
38
    lockable_files,
43
39
    lockdir,
44
40
    osutils,
45
 
    symbol_versioning,
 
41
    revision as _mod_revision,
46
42
    trace,
47
 
    tuned_gzip,
48
43
    urlutils,
49
44
    versionedfile,
50
45
    weave,
52
47
    )
53
48
from bzrlib.decorators import needs_read_lock, needs_write_lock
54
49
from bzrlib.repository import (
55
 
    InterRepository,
56
 
    RepositoryFormatMetaDir,
 
50
    CommitBuilder,
 
51
    MetaDirVersionedFileRepository,
 
52
    MetaDirRepositoryFormat,
 
53
    Repository,
 
54
    RepositoryFormat,
57
55
    )
58
56
from bzrlib.store.text import TextStore
 
57
from bzrlib.tuned_gzip import GzipFile, bytes_to_gzip
59
58
from bzrlib.versionedfile import (
60
59
    AbsentContentFactory,
61
60
    FulltextContentFactory,
62
61
    VersionedFiles,
63
62
    )
64
 
from bzrlib.vf_repository import (
65
 
    InterSameDataRepository,
66
 
    VersionedFileCommitBuilder,
67
 
    VersionedFileRepository,
68
 
    VersionedFileRepositoryFormat,
69
 
    MetaDirVersionedFileRepository,
70
 
    MetaDirVersionedFileRepositoryFormat,
71
 
    )
72
 
 
73
 
from bzrlib.plugins.weave_fmt import bzrdir as weave_bzrdir
74
 
 
75
 
 
76
 
class AllInOneRepository(VersionedFileRepository):
 
63
 
 
64
 
 
65
class AllInOneRepository(Repository):
77
66
    """Legacy support - the repository behaviour for all-in-one branches."""
78
67
 
79
68
    @property
151
140
 
152
141
    def get_commit_builder(self, branch, parents, config, timestamp=None,
153
142
                           timezone=None, committer=None, revprops=None,
154
 
                           revision_id=None, lossy=False):
 
143
                           revision_id=None):
155
144
        self._check_ascii_revisionid(revision_id, self.get_commit_builder)
156
 
        result = VersionedFileCommitBuilder(self, parents, config, timestamp,
157
 
            timezone, committer, revprops, revision_id, lossy=lossy)
 
145
        result = CommitBuilder(self, parents, config, timestamp, timezone,
 
146
                              committer, revprops, revision_id)
158
147
        self.start_write_group()
159
148
        return result
160
149
 
194
183
        """Returns the policy for making working trees on new branches."""
195
184
        return True
196
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
 
197
191
 
198
192
class WeaveMetaDirRepository(MetaDirVersionedFileRepository):
199
193
    """A subclass of MetaDirRepository to set weave specific policy."""
240
234
 
241
235
    def get_commit_builder(self, branch, parents, config, timestamp=None,
242
236
                           timezone=None, committer=None, revprops=None,
243
 
                           revision_id=None, lossy=False):
 
237
                           revision_id=None):
244
238
        self._check_ascii_revisionid(revision_id, self.get_commit_builder)
245
 
        result = VersionedFileCommitBuilder(self, parents, config, timestamp,
246
 
            timezone, committer, revprops, revision_id, lossy=lossy)
 
239
        result = CommitBuilder(self, parents, config, timestamp, timezone,
 
240
                              committer, revprops, revision_id)
247
241
        self.start_write_group()
248
242
        return result
249
243
 
264
258
        return self.inventories.add_lines((revision_id,), final_parents, lines,
265
259
            check_content=check_content)[0]
266
260
 
267
 
 
268
 
class PreSplitOutRepositoryFormat(VersionedFileRepositoryFormat):
 
261
    def revision_graph_can_have_wrong_parents(self):
 
262
        return False
 
263
 
 
264
 
 
265
class PreSplitOutRepositoryFormat(RepositoryFormat):
269
266
    """Base class for the pre split out repository formats."""
270
267
 
271
268
    rich_root_data = False
273
270
    supports_ghosts = False
274
271
    supports_external_lookups = False
275
272
    supports_chks = False
276
 
    supports_nesting_repositories = True
277
273
    _fetch_order = 'topological'
278
274
    _fetch_reconcile = True
279
275
    fast_deltas = False
280
 
    supports_leaving_lock = False
281
 
    # XXX: This is an old format that we don't support full checking on, so
282
 
    # just claim that checking for this inconsistency is not required.
283
 
    revision_graph_can_have_wrong_parents = False
284
276
 
285
277
    def initialize(self, a_bzrdir, shared=False, _internal=False):
286
278
        """Create a weave repository."""
323
315
            raise NotImplementedError
324
316
 
325
317
        repo_transport = a_bzrdir.get_repository_transport(None)
 
318
        control_files = a_bzrdir._control_files
326
319
        result = AllInOneRepository(_format=self, a_bzrdir=a_bzrdir)
327
320
        result.revisions = self._get_revisions(repo_transport, result)
328
321
        result.signatures = self._get_signatures(repo_transport, result)
331
324
        result.chk_bytes = None
332
325
        return result
333
326
 
334
 
    def is_deprecated(self):
335
 
        return True
336
 
 
337
327
 
338
328
class RepositoryFormat4(PreSplitOutRepositoryFormat):
339
329
    """Bzr repository format 4.
347
337
    has been removed.
348
338
    """
349
339
 
350
 
    supports_funky_characters = False
351
 
 
352
 
    _matchingbzrdir = weave_bzrdir.BzrDirFormat4()
 
340
    _matchingbzrdir = bzrdir.BzrDirFormat4()
353
341
 
354
342
    def get_format_description(self):
355
343
        """See RepositoryFormat.get_format_description()."""
373
361
        return None
374
362
 
375
363
    def _get_revisions(self, repo_transport, repo):
376
 
        from bzrlib.plugins.weave_fmt.xml4 import serializer_v4
 
364
        from bzrlib.xml4 import serializer_v4
377
365
        return RevisionTextStore(repo_transport.clone('revision-store'),
378
366
            serializer_v4, True, versionedfile.PrefixMapper(),
379
367
            repo.is_locked, repo.is_write_locked)
397
385
    """
398
386
 
399
387
    _versionedfile_class = weave.WeaveFile
400
 
    _matchingbzrdir = weave_bzrdir.BzrDirFormat5()
401
 
    supports_funky_characters = False
402
 
 
 
388
    _matchingbzrdir = bzrdir.BzrDirFormat5()
403
389
    @property
404
390
    def _serializer(self):
405
391
        return xml5.serializer_v5
444
430
    """
445
431
 
446
432
    _versionedfile_class = weave.WeaveFile
447
 
    _matchingbzrdir = weave_bzrdir.BzrDirFormat6()
448
 
    supports_funky_characters = False
 
433
    _matchingbzrdir = bzrdir.BzrDirFormat6()
449
434
    @property
450
435
    def _serializer(self):
451
436
        return xml5.serializer_v5
480
465
            weave.WeaveFile, mapper, repo.is_locked)
481
466
 
482
467
 
483
 
class RepositoryFormat7(MetaDirVersionedFileRepositoryFormat):
 
468
class RepositoryFormat7(MetaDirRepositoryFormat):
484
469
    """Bzr repository 7.
485
470
 
486
471
    This repository format has:
495
480
    _versionedfile_class = weave.WeaveFile
496
481
    supports_ghosts = False
497
482
    supports_chks = False
498
 
    supports_funky_characters = False
499
 
    revision_graph_can_have_wrong_parents = False
500
483
 
501
484
    _fetch_order = 'topological'
502
485
    _fetch_reconcile = True
505
488
    def _serializer(self):
506
489
        return xml5.serializer_v5
507
490
 
508
 
    @classmethod
509
 
    def get_format_string(cls):
 
491
    def get_format_string(self):
510
492
        """See RepositoryFormat.get_format_string()."""
511
493
        return "Bazaar-NG Repository format 7"
512
494
 
563
545
                                    than normal. I.e. during 'upgrade'.
564
546
        """
565
547
        if not _found:
566
 
            format = RepositoryFormatMetaDir.find_format(a_bzrdir)
 
548
            format = RepositoryFormat.find_format(a_bzrdir)
567
549
        if _override_transport is not None:
568
550
            repo_transport = _override_transport
569
551
        else:
580
562
        result._transport = repo_transport
581
563
        return result
582
564
 
583
 
    def is_deprecated(self):
584
 
        return True
585
 
 
586
565
 
587
566
class TextVersionedFiles(VersionedFiles):
588
567
    """Just-a-bunch-of-files based VersionedFile stores."""
608
587
            raise ValueError('bad idea to put / in %r' % (key,))
609
588
        text = ''.join(lines)
610
589
        if self._compressed:
611
 
            text = tuned_gzip.bytes_to_gzip(text)
 
590
            text = bytes_to_gzip(text)
612
591
        path = self._map(key)
613
592
        self._transport.put_bytes_non_atomic(path, text, create_parent_dir=True)
614
593
 
634
613
                    record, record.get_bytes_as(record.storage_kind)))
635
614
                try:
636
615
                    self.add_lines(record.key, None, lines)
637
 
                except errors.RevisionAlreadyPresent:
 
616
                except RevisionAlreadyPresent:
638
617
                    pass
639
618
 
640
619
    def _load_text(self, key):
656
635
            else:
657
636
                return None
658
637
        if compressed:
659
 
            text = gzip.GzipFile(mode='rb', fileobj=StringIO(text)).read()
 
638
            text = GzipFile(mode='rb', fileobj=StringIO(text)).read()
660
639
        return text
661
640
 
662
641
    def _map(self, key):
709
688
            raise errors.ObjectNotLocked(self)
710
689
        relpaths = set()
711
690
        for quoted_relpath in self._transport.iter_files_recursive():
712
 
            relpath = urlutils.unquote(quoted_relpath)
 
691
            relpath = urllib.unquote(quoted_relpath)
713
692
            path, ext = os.path.splitext(relpath)
714
693
            if ext == '.gz':
715
694
                relpath = path
749
728
            raise errors.ObjectNotLocked(self)
750
729
        relpaths = set()
751
730
        for quoted_relpath in self._transport.iter_files_recursive():
752
 
            relpath = urlutils.unquote(quoted_relpath)
 
731
            relpath = urllib.unquote(quoted_relpath)
753
732
            path, ext = os.path.splitext(relpath)
754
733
            if ext == '.gz':
755
734
                relpath = path
759
738
        paths = list(relpaths)
760
739
        return set([self._mapper.unmap(path) for path in paths])
761
740
 
762
 
 
763
 
class InterWeaveRepo(InterSameDataRepository):
764
 
    """Optimised code paths between Weave based repositories.
765
 
    """
766
 
 
767
 
    @classmethod
768
 
    def _get_repo_format_to_test(self):
769
 
        return RepositoryFormat7()
770
 
 
771
 
    @staticmethod
772
 
    def is_compatible(source, target):
773
 
        """Be compatible with known Weave formats.
774
 
 
775
 
        We don't test for the stores being of specific types because that
776
 
        could lead to confusing results, and there is no need to be
777
 
        overly general.
778
 
        """
779
 
        try:
780
 
            return (isinstance(source._format, (RepositoryFormat5,
781
 
                                                RepositoryFormat6,
782
 
                                                RepositoryFormat7)) and
783
 
                    isinstance(target._format, (RepositoryFormat5,
784
 
                                                RepositoryFormat6,
785
 
                                                RepositoryFormat7)))
786
 
        except AttributeError:
787
 
            return False
788
 
 
789
 
    @needs_write_lock
790
 
    def copy_content(self, revision_id=None):
791
 
        """See InterRepository.copy_content()."""
792
 
        # weave specific optimised path:
793
 
        try:
794
 
            self.target.set_make_working_trees(self.source.make_working_trees())
795
 
        except (errors.RepositoryUpgradeRequired, NotImplemented):
796
 
            pass
797
 
        # FIXME do not peek!
798
 
        if self.source._transport.listable():
799
 
            pb = ui.ui_factory.nested_progress_bar()
800
 
            try:
801
 
                self.target.texts.insert_record_stream(
802
 
                    self.source.texts.get_record_stream(
803
 
                        self.source.texts.keys(), 'topological', False))
804
 
                pb.update('Copying inventory', 0, 1)
805
 
                self.target.inventories.insert_record_stream(
806
 
                    self.source.inventories.get_record_stream(
807
 
                        self.source.inventories.keys(), 'topological', False))
808
 
                self.target.signatures.insert_record_stream(
809
 
                    self.source.signatures.get_record_stream(
810
 
                        self.source.signatures.keys(),
811
 
                        'unordered', True))
812
 
                self.target.revisions.insert_record_stream(
813
 
                    self.source.revisions.get_record_stream(
814
 
                        self.source.revisions.keys(),
815
 
                        'topological', True))
816
 
            finally:
817
 
                pb.finished()
818
 
        else:
819
 
            self.target.fetch(self.source, revision_id=revision_id)
820
 
 
821
 
    @needs_read_lock
822
 
    def search_missing_revision_ids(self,
823
 
            revision_id=symbol_versioning.DEPRECATED_PARAMETER,
824
 
            find_ghosts=True, revision_ids=None, if_present_ids=None,
825
 
            limit=None):
826
 
        """See InterRepository.search_missing_revision_ids()."""
827
 
        # we want all revisions to satisfy revision_id in source.
828
 
        # but we don't want to stat every file here and there.
829
 
        # we want then, all revisions other needs to satisfy revision_id
830
 
        # checked, but not those that we have locally.
831
 
        # so the first thing is to get a subset of the revisions to
832
 
        # satisfy revision_id in source, and then eliminate those that
833
 
        # we do already have.
834
 
        # this is slow on high latency connection to self, but as this
835
 
        # disk format scales terribly for push anyway due to rewriting
836
 
        # inventory.weave, this is considered acceptable.
837
 
        # - RBC 20060209
838
 
        if symbol_versioning.deprecated_passed(revision_id):
839
 
            symbol_versioning.warn(
840
 
                'search_missing_revision_ids(revision_id=...) was '
841
 
                'deprecated in 2.4.  Use revision_ids=[...] instead.',
842
 
                DeprecationWarning, stacklevel=2)
843
 
            if revision_ids is not None:
844
 
                raise AssertionError(
845
 
                    'revision_ids is mutually exclusive with revision_id')
846
 
            if revision_id is not None:
847
 
                revision_ids = [revision_id]
848
 
        del revision_id
849
 
        source_ids_set = self._present_source_revisions_for(
850
 
            revision_ids, if_present_ids)
851
 
        # source_ids is the worst possible case we may need to pull.
852
 
        # now we want to filter source_ids against what we actually
853
 
        # have in target, but don't try to check for existence where we know
854
 
        # we do not have a revision as that would be pointless.
855
 
        target_ids = set(self.target._all_possible_ids())
856
 
        possibly_present_revisions = target_ids.intersection(source_ids_set)
857
 
        actually_present_revisions = set(
858
 
            self.target._eliminate_revisions_not_present(possibly_present_revisions))
859
 
        required_revisions = source_ids_set.difference(actually_present_revisions)
860
 
        if revision_ids is not None:
861
 
            # we used get_ancestry to determine source_ids then we are assured all
862
 
            # revisions referenced are present as they are installed in topological order.
863
 
            # and the tip revision was validated by get_ancestry.
864
 
            result_set = required_revisions
865
 
        else:
866
 
            # if we just grabbed the possibly available ids, then
867
 
            # we only have an estimate of whats available and need to validate
868
 
            # that against the revision records.
869
 
            result_set = set(
870
 
                self.source._eliminate_revisions_not_present(required_revisions))
871
 
        if limit is not None:
872
 
            topo_ordered = self.get_graph().iter_topo_order(result_set)
873
 
            result_set = set(itertools.islice(topo_ordered, limit))
874
 
        return self.source.revision_ids_to_search_result(result_set)
875
 
 
876
 
 
877
 
InterRepository.register_optimiser(InterWeaveRepo)
878
 
 
879
 
 
880
 
def get_extra_interrepo_test_combinations():
881
 
    from bzrlib.repofmt import knitrepo
882
 
    return [(InterRepository, RepositoryFormat5(),
883
 
        knitrepo.RepositoryFormatKnit3())]
 
741
_legacy_formats = [RepositoryFormat4(),
 
742
                   RepositoryFormat5(),
 
743
                   RepositoryFormat6()]