~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repofmt/weaverepo.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2011-01-11 19:11:29 UTC
  • mfrom: (5555.3.1 local_work)
  • Revision ID: pqm@pqm.ubuntu.com-20110111191129-qxzw738fmkm0run9
(vila) Add icons for tbzrcommand (iwata)

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,
36
33
    )
37
34
""")
38
35
from bzrlib import (
 
36
    bzrdir,
39
37
    debug,
40
38
    errors,
41
39
    lockable_files,
42
40
    lockdir,
43
41
    osutils,
44
 
    symbol_versioning,
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 (
 
50
    CommitBuilder,
54
51
    InterRepository,
 
52
    InterSameDataRepository,
 
53
    MetaDirVersionedFileRepository,
 
54
    MetaDirRepositoryFormat,
 
55
    Repository,
55
56
    RepositoryFormat,
56
57
    )
57
58
from bzrlib.store.text import TextStore
 
59
from bzrlib.tuned_gzip import GzipFile, bytes_to_gzip
58
60
from bzrlib.versionedfile import (
59
61
    AbsentContentFactory,
60
62
    FulltextContentFactory,
61
63
    VersionedFiles,
62
64
    )
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):
 
65
 
 
66
 
 
67
class AllInOneRepository(Repository):
76
68
    """Legacy support - the repository behaviour for all-in-one branches."""
77
69
 
78
70
    @property
150
142
 
151
143
    def get_commit_builder(self, branch, parents, config, timestamp=None,
152
144
                           timezone=None, committer=None, revprops=None,
153
 
                           revision_id=None, lossy=False):
 
145
                           revision_id=None):
154
146
        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)
 
147
        result = CommitBuilder(self, parents, config, timestamp, timezone,
 
148
                              committer, revprops, revision_id)
157
149
        self.start_write_group()
158
150
        return result
159
151
 
193
185
        """Returns the policy for making working trees on new branches."""
194
186
        return True
195
187
 
 
188
    def revision_graph_can_have_wrong_parents(self):
 
189
        # XXX: This is an old format that we don't support full checking on, so
 
190
        # just claim that checking for this inconsistency is not required.
 
191
        return False
 
192
 
196
193
 
197
194
class WeaveMetaDirRepository(MetaDirVersionedFileRepository):
198
195
    """A subclass of MetaDirRepository to set weave specific policy."""
239
236
 
240
237
    def get_commit_builder(self, branch, parents, config, timestamp=None,
241
238
                           timezone=None, committer=None, revprops=None,
242
 
                           revision_id=None, lossy=False):
 
239
                           revision_id=None):
243
240
        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)
 
241
        result = CommitBuilder(self, parents, config, timestamp, timezone,
 
242
                              committer, revprops, revision_id)
246
243
        self.start_write_group()
247
244
        return result
248
245
 
263
260
        return self.inventories.add_lines((revision_id,), final_parents, lines,
264
261
            check_content=check_content)[0]
265
262
 
266
 
 
267
 
class PreSplitOutRepositoryFormat(VersionedFileRepositoryFormat):
 
263
    def revision_graph_can_have_wrong_parents(self):
 
264
        return False
 
265
 
 
266
 
 
267
class PreSplitOutRepositoryFormat(RepositoryFormat):
268
268
    """Base class for the pre split out repository formats."""
269
269
 
270
270
    rich_root_data = False
275
275
    _fetch_order = 'topological'
276
276
    _fetch_reconcile = True
277
277
    fast_deltas = False
278
 
    supports_leaving_lock = False
279
 
    # XXX: This is an old format that we don't support full checking on, so
280
 
    # just claim that checking for this inconsistency is not required.
281
 
    revision_graph_can_have_wrong_parents = False
282
278
 
283
279
    def initialize(self, a_bzrdir, shared=False, _internal=False):
284
280
        """Create a weave repository."""
330
326
        result.chk_bytes = None
331
327
        return result
332
328
 
333
 
    def is_deprecated(self):
334
 
        return True
335
 
 
336
329
 
337
330
class RepositoryFormat4(PreSplitOutRepositoryFormat):
338
331
    """Bzr repository format 4.
346
339
    has been removed.
347
340
    """
348
341
 
349
 
    supports_funky_characters = False
350
 
 
351
 
    _matchingbzrdir = weave_bzrdir.BzrDirFormat4()
 
342
    _matchingbzrdir = bzrdir.BzrDirFormat4()
352
343
 
353
344
    def get_format_description(self):
354
345
        """See RepositoryFormat.get_format_description()."""
372
363
        return None
373
364
 
374
365
    def _get_revisions(self, repo_transport, repo):
375
 
        from bzrlib.plugins.weave_fmt.xml4 import serializer_v4
 
366
        from bzrlib.xml4 import serializer_v4
376
367
        return RevisionTextStore(repo_transport.clone('revision-store'),
377
368
            serializer_v4, True, versionedfile.PrefixMapper(),
378
369
            repo.is_locked, repo.is_write_locked)
396
387
    """
397
388
 
398
389
    _versionedfile_class = weave.WeaveFile
399
 
    _matchingbzrdir = weave_bzrdir.BzrDirFormat5()
400
 
    supports_funky_characters = False
401
 
 
 
390
    _matchingbzrdir = bzrdir.BzrDirFormat5()
402
391
    @property
403
392
    def _serializer(self):
404
393
        return xml5.serializer_v5
443
432
    """
444
433
 
445
434
    _versionedfile_class = weave.WeaveFile
446
 
    _matchingbzrdir = weave_bzrdir.BzrDirFormat6()
447
 
    supports_funky_characters = False
 
435
    _matchingbzrdir = bzrdir.BzrDirFormat6()
448
436
    @property
449
437
    def _serializer(self):
450
438
        return xml5.serializer_v5
479
467
            weave.WeaveFile, mapper, repo.is_locked)
480
468
 
481
469
 
482
 
class RepositoryFormat7(MetaDirVersionedFileRepositoryFormat):
 
470
class RepositoryFormat7(MetaDirRepositoryFormat):
483
471
    """Bzr repository 7.
484
472
 
485
473
    This repository format has:
494
482
    _versionedfile_class = weave.WeaveFile
495
483
    supports_ghosts = False
496
484
    supports_chks = False
497
 
    supports_funky_characters = False
498
 
    revision_graph_can_have_wrong_parents = False
499
485
 
500
486
    _fetch_order = 'topological'
501
487
    _fetch_reconcile = True
578
564
        result._transport = repo_transport
579
565
        return result
580
566
 
581
 
    def is_deprecated(self):
582
 
        return True
583
 
 
584
567
 
585
568
class TextVersionedFiles(VersionedFiles):
586
569
    """Just-a-bunch-of-files based VersionedFile stores."""
606
589
            raise ValueError('bad idea to put / in %r' % (key,))
607
590
        text = ''.join(lines)
608
591
        if self._compressed:
609
 
            text = tuned_gzip.bytes_to_gzip(text)
 
592
            text = bytes_to_gzip(text)
610
593
        path = self._map(key)
611
594
        self._transport.put_bytes_non_atomic(path, text, create_parent_dir=True)
612
595
 
632
615
                    record, record.get_bytes_as(record.storage_kind)))
633
616
                try:
634
617
                    self.add_lines(record.key, None, lines)
635
 
                except errors.RevisionAlreadyPresent:
 
618
                except RevisionAlreadyPresent:
636
619
                    pass
637
620
 
638
621
    def _load_text(self, key):
654
637
            else:
655
638
                return None
656
639
        if compressed:
657
 
            text = gzip.GzipFile(mode='rb', fileobj=StringIO(text)).read()
 
640
            text = GzipFile(mode='rb', fileobj=StringIO(text)).read()
658
641
        return text
659
642
 
660
643
    def _map(self, key):
760
743
 
761
744
class InterWeaveRepo(InterSameDataRepository):
762
745
    """Optimised code paths between Weave based repositories.
 
746
 
 
747
    This should be in bzrlib/repofmt/weaverepo.py but we have not yet
 
748
    implemented lazy inter-object optimisation.
763
749
    """
764
750
 
765
751
    @classmethod
817
803
            self.target.fetch(self.source, revision_id=revision_id)
818
804
 
819
805
    @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()."""
 
806
    def search_missing_revision_ids(self, revision_id=None, find_ghosts=True):
 
807
        """See InterRepository.missing_revision_ids()."""
825
808
        # we want all revisions to satisfy revision_id in source.
826
809
        # but we don't want to stat every file here and there.
827
810
        # we want then, all revisions other needs to satisfy revision_id
833
816
        # disk format scales terribly for push anyway due to rewriting
834
817
        # inventory.weave, this is considered acceptable.
835
818
        # - 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)
 
819
        if revision_id is not None:
 
820
            source_ids = self.source.get_ancestry(revision_id)
 
821
            if source_ids[0] is not None:
 
822
                raise AssertionError()
 
823
            source_ids.pop(0)
 
824
        else:
 
825
            source_ids = self.source._all_possible_ids()
 
826
        source_ids_set = set(source_ids)
849
827
        # source_ids is the worst possible case we may need to pull.
850
828
        # now we want to filter source_ids against what we actually
851
829
        # have in target, but don't try to check for existence where we know
855
833
        actually_present_revisions = set(
856
834
            self.target._eliminate_revisions_not_present(possibly_present_revisions))
857
835
        required_revisions = source_ids_set.difference(actually_present_revisions)
858
 
        if revision_ids is not None:
 
836
        if revision_id is not None:
859
837
            # we used get_ancestry to determine source_ids then we are assured all
860
838
            # revisions referenced are present as they are installed in topological order.
861
839
            # and the tip revision was validated by get_ancestry.
866
844
            # that against the revision records.
867
845
            result_set = set(
868
846
                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
847
        return self.source.revision_ids_to_search_result(result_set)
873
848
 
874
849
 
 
850
_legacy_formats = [RepositoryFormat4(),
 
851
                   RepositoryFormat5(),
 
852
                   RepositoryFormat6()]
 
853
 
 
854
 
875
855
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())]