/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar
2052.3.2 by John Arbash Meinel
Change Copyright .. by Canonical to Copyright ... Canonical
1
# Copyright (C) 2006 Canonical Ltd
1563.2.21 by Robert Collins
Smoke test for RevisionStore factories creating revision stores.
2
#
3
# This program is free software; you can redistribute it and/or modify
2052.3.1 by John Arbash Meinel
Add tests to cleanup the copyright of all source files
4
# it under the terms of the GNU General Public License as published by
5
# the Free Software Foundation; either version 2 of the License, or
6
# (at your option) any later version.
1563.2.21 by Robert Collins
Smoke test for RevisionStore factories creating revision stores.
7
#
8
# This program is distributed in the hope that it will be useful,
9
# but WITHOUT ANY WARRANTY; without even the implied warranty of
10
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11
# GNU General Public License for more details.
12
#
13
# You should have received a copy of the GNU General Public License
14
# along with this program; if not, write to the Free Software
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
17
"""VersionedFile based revision store.
18
1563.2.22 by Robert Collins
Move responsibility for repository.has_revision into RevisionStore
19
This stores revisions as individual entries in a knit, and signatures in a 
20
parallel knit.
1563.2.21 by Robert Collins
Smoke test for RevisionStore factories creating revision stores.
21
"""
22
23
2598.5.1 by Aaron Bentley
Start eliminating the use of None to indicate null revision
24
from bzrlib import (
25
    errors,
26
    osutils,
27
    revision as _mod_revision,
28
    )
1628.1.4 by Robert Collins
Change knit format to use non-delta, non-annotated revisions and signatures.
29
from bzrlib.knit import KnitVersionedFile, KnitPlainFactory
1563.2.21 by Robert Collins
Smoke test for RevisionStore factories creating revision stores.
30
from bzrlib.store.revision import RevisionStore
1563.2.22 by Robert Collins
Move responsibility for repository.has_revision into RevisionStore
31
from bzrlib.store.versioned import VersionedFileStore
1563.2.21 by Robert Collins
Smoke test for RevisionStore factories creating revision stores.
32
from bzrlib.transport import get_transport
33
34
35
class KnitRevisionStoreFactory(object):
36
    """Factory to create a KnitRevisionStore for testing."""
37
38
    def create(self, url):
39
        """Create a revision store at url."""
40
        t = get_transport(url)
1563.2.31 by Robert Collins
Convert Knit repositories to use knits.
41
        t.mkdir('revision-store')
42
        versioned_file_store = VersionedFileStore(
43
            t.clone('revision-store'),
1563.2.34 by Robert Collins
Remove the commit and rollback transaction methods as misleading, and implement a WriteTransaction
44
            precious=True,
1628.1.4 by Robert Collins
Change knit format to use non-delta, non-annotated revisions and signatures.
45
            versionedfile_class=KnitVersionedFile,
46
            versionedfile_kwargs={'delta':False, 'factory':KnitPlainFactory()})
1563.2.22 by Robert Collins
Move responsibility for repository.has_revision into RevisionStore
47
        return KnitRevisionStore(versioned_file_store)
1563.2.21 by Robert Collins
Smoke test for RevisionStore factories creating revision stores.
48
49
    def __str__(self):
50
        return "KnitRevisionStore"
1563.2.22 by Robert Collins
Move responsibility for repository.has_revision into RevisionStore
51
52
53
class KnitRevisionStore(RevisionStore):
54
    """A RevisionStore layering on a VersionedFileStore."""
55
56
    def __init__(self, versioned_file_store):
57
        """Create a KnitRevisionStore object.
58
59
        :param versioned_file_store: the text store to use for storing 
60
                                     revisions and signatures.
61
        """
1563.2.23 by Robert Collins
Add add_revision and get_revision methods to RevisionStore
62
        super(KnitRevisionStore, self).__init__()
1563.2.22 by Robert Collins
Move responsibility for repository.has_revision into RevisionStore
63
        self.versioned_file_store = versioned_file_store
64
2696.3.3 by Martin Pool
Start setting the default format to dirstate-tags
65
    def __repr__(self):
66
        return "%s(%s)" % (self.__class__.__name__,
67
                           self.versioned_file_store)
68
1563.2.23 by Robert Collins
Add add_revision and get_revision methods to RevisionStore
69
    def _add_revision(self, revision, revision_as_file, transaction):
70
        """Template method helper to store revision in this store."""
1594.2.9 by Robert Collins
Teach Knit repositories how to handle ghosts without corrupting at all.
71
        self.get_revision_file(transaction).add_lines_with_ghosts(
1563.2.23 by Robert Collins
Add add_revision and get_revision methods to RevisionStore
72
            revision.revision_id,
1594.2.9 by Robert Collins
Teach Knit repositories how to handle ghosts without corrupting at all.
73
            revision.parent_ids,
2094.3.5 by John Arbash Meinel
Fix imports to ensure modules are loaded before they are used
74
            osutils.split_lines(revision_as_file.read()))
1563.2.23 by Robert Collins
Add add_revision and get_revision methods to RevisionStore
75
1563.2.30 by Robert Collins
Remove all but fetch references to revision_store, making the repository references that are weave specific use the RevisionTextStore.text_store attribute.
76
    def add_revision_signature_text(self, revision_id, signature_text, transaction):
77
        """See RevisionStore.add_revision_signature_text()."""
2249.5.12 by John Arbash Meinel
Change the APIs for VersionedFile, Store, and some of Repository into utf-8
78
        revision_id = osutils.safe_revision_id(revision_id)
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
79
        self.get_signature_file(transaction).add_lines(
2094.3.5 by John Arbash Meinel
Fix imports to ensure modules are loaded before they are used
80
            revision_id, [], osutils.split_lines(signature_text))
1563.2.29 by Robert Collins
Remove all but fetch references to repository.revision_store.
81
82
    def all_revision_ids(self, transaction):
83
        """See RevisionStore.all_revision_ids()."""
84
        rev_file = self.get_revision_file(transaction)
85
        return rev_file.get_ancestry(rev_file.versions())
1563.2.27 by Robert Collins
Add signature text addition to the revisionstore api.
86
1756.1.2 by Aaron Bentley
Show logs using get_revisions
87
    def get_revisions(self, revision_ids, transaction):
88
        """See RevisionStore.get_revisions()."""
2249.5.12 by John Arbash Meinel
Change the APIs for VersionedFile, Store, and some of Repository into utf-8
89
        revision_ids = [osutils.safe_revision_id(r) for r in revision_ids]
1756.1.2 by Aaron Bentley
Show logs using get_revisions
90
        texts = self._get_serialized_revisions(revision_ids, transaction)
91
        revisions = []
1563.2.23 by Robert Collins
Add add_revision and get_revision methods to RevisionStore
92
        try:
1756.1.2 by Aaron Bentley
Show logs using get_revisions
93
            for text, revision_id in zip(texts, revision_ids):
94
                r = self._serializer.read_revision_from_string(text)
95
                assert r.revision_id == revision_id
96
                revisions.append(r)
1563.2.23 by Robert Collins
Add add_revision and get_revision methods to RevisionStore
97
        except SyntaxError, e:
2178.2.1 by Jelmer Vernooij
Fix exception arguments.
98
            raise errors.BzrError('failed to unpack revision_xml for %s: %s' %
99
                                   (revision_id, str(e)))
2249.5.12 by John Arbash Meinel
Change the APIs for VersionedFile, Store, and some of Repository into utf-8
100
        return revisions
1756.1.2 by Aaron Bentley
Show logs using get_revisions
101
102
    def _get_serialized_revisions(self, revision_ids, transaction):
103
        texts = []
104
        vf = self.get_revision_file(transaction)
105
        try:
1756.2.1 by Aaron Bentley
Implement get_texts
106
            return vf.get_texts(revision_ids)
107
        except (errors.RevisionNotPresent), e:
108
            raise errors.NoSuchRevision(self, e.revision_id)
1563.2.23 by Robert Collins
Add add_revision and get_revision methods to RevisionStore
109
110
    def _get_revision_xml(self, revision_id, transaction):
111
        try:
112
            return self.get_revision_file(transaction).get_text(revision_id)
113
        except (errors.RevisionNotPresent):
114
            raise errors.NoSuchRevision(self, revision_id)
115
1563.2.22 by Robert Collins
Move responsibility for repository.has_revision into RevisionStore
116
    def get_revision_file(self, transaction):
117
        """Get the revision versioned file object."""
1563.2.25 by Robert Collins
Merge in upstream.
118
        return self.versioned_file_store.get_weave_or_empty('revisions', transaction)
1563.2.22 by Robert Collins
Move responsibility for repository.has_revision into RevisionStore
119
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
120
    def get_signature_file(self, transaction):
1563.2.29 by Robert Collins
Remove all but fetch references to repository.revision_store.
121
        """Get the signature text versioned file object."""
122
        return self.versioned_file_store.get_weave_or_empty('signatures', transaction)
123
1563.2.30 by Robert Collins
Remove all but fetch references to revision_store, making the repository references that are weave specific use the RevisionTextStore.text_store attribute.
124
    def _get_signature_text(self, revision_id, transaction):
125
        """See RevisionStore._get_signature_text()."""
126
        try:
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
127
            return self.get_signature_file(transaction).get_text(revision_id)
1563.2.30 by Robert Collins
Remove all but fetch references to revision_store, making the repository references that are weave specific use the RevisionTextStore.text_store attribute.
128
        except errors.RevisionNotPresent:
129
            raise errors.NoSuchRevision(self, revision_id)
130
1563.2.22 by Robert Collins
Move responsibility for repository.has_revision into RevisionStore
131
    def has_revision_id(self, revision_id, transaction):
132
        """True if the store contains revision_id."""
2249.5.12 by John Arbash Meinel
Change the APIs for VersionedFile, Store, and some of Repository into utf-8
133
        revision_id = osutils.safe_revision_id(revision_id)
2598.5.1 by Aaron Bentley
Start eliminating the use of None to indicate null revision
134
        return (_mod_revision.is_null(revision_id)
1563.2.22 by Robert Collins
Move responsibility for repository.has_revision into RevisionStore
135
                or self.get_revision_file(transaction).has_version(revision_id))
2249.5.12 by John Arbash Meinel
Change the APIs for VersionedFile, Store, and some of Repository into utf-8
136
1563.2.29 by Robert Collins
Remove all but fetch references to repository.revision_store.
137
    def _has_signature(self, revision_id, transaction):
138
        """See RevisionStore._has_signature()."""
1563.2.35 by Robert Collins
cleanup deprecation warnings and finish conversion so the inventory is knit based too.
139
        return self.get_signature_file(transaction).has_version(revision_id)
1563.2.29 by Robert Collins
Remove all but fetch references to repository.revision_store.
140
1563.2.28 by Robert Collins
Add total_size to the revision_store api.
141
    def total_size(self, transaction):
142
        """ See RevisionStore.total_size()."""
1773.4.2 by Martin Pool
Cleanup of imports; undeprecate all_revision_ids()
143
        return (len(self.all_revision_ids(transaction)),
1666.1.6 by Robert Collins
Make knit the default format.
144
            self.versioned_file_store.total_size()[1])