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 |
"""TextStore based revision store.
|
|
18 |
||
19 |
This stores revisions as individual text entries in a TextStore and
|
|
20 |
requires access to a inventory weave to produce object graphs.
|
|
21 |
"""
|
|
22 |
||
23 |
||
1563.2.27
by Robert Collins
Add signature text addition to the revisionstore api. |
24 |
from cStringIO import StringIO |
25 |
||
26 |
||
2249.5.12
by John Arbash Meinel
Change the APIs for VersionedFile, Store, and some of Repository into utf-8 |
27 |
from bzrlib import ( |
28 |
cache_utf8, |
|
29 |
errors, |
|
30 |
osutils, |
|
2598.5.1
by Aaron Bentley
Start eliminating the use of None to indicate null revision |
31 |
revision as _mod_revision, |
2249.5.12
by John Arbash Meinel
Change the APIs for VersionedFile, Store, and some of Repository into utf-8 |
32 |
)
|
1563.2.21
by Robert Collins
Smoke test for RevisionStore factories creating revision stores. |
33 |
from bzrlib.store.revision import RevisionStore |
1563.2.22
by Robert Collins
Move responsibility for repository.has_revision into RevisionStore |
34 |
from bzrlib.store.text import TextStore |
1563.2.23
by Robert Collins
Add add_revision and get_revision methods to RevisionStore |
35 |
from bzrlib.store.versioned import VersionedFileStore |
1563.2.21
by Robert Collins
Smoke test for RevisionStore factories creating revision stores. |
36 |
from bzrlib.transport import get_transport |
1563.2.29
by Robert Collins
Remove all but fetch references to repository.revision_store. |
37 |
from bzrlib.tsort import topo_sort |
1563.2.21
by Robert Collins
Smoke test for RevisionStore factories creating revision stores. |
38 |
|
39 |
||
40 |
class TextRevisionStoreTestFactory(object): |
|
41 |
"""Factory to create a TextRevisionStore for testing.
|
|
42 |
||
43 |
This creates a inventory weave and hooks it into the revision store
|
|
44 |
"""
|
|
45 |
||
46 |
def create(self, url): |
|
47 |
"""Create a revision store at url."""
|
|
48 |
t = get_transport(url) |
|
1563.2.22
by Robert Collins
Move responsibility for repository.has_revision into RevisionStore |
49 |
t.mkdir('revstore') |
50 |
text_store = TextStore(t.clone('revstore')) |
|
51 |
return TextRevisionStore(text_store) |
|
1563.2.21
by Robert Collins
Smoke test for RevisionStore factories creating revision stores. |
52 |
|
53 |
def __str__(self): |
|
54 |
return "TextRevisionStore" |
|
1563.2.22
by Robert Collins
Move responsibility for repository.has_revision into RevisionStore |
55 |
|
56 |
||
57 |
class TextRevisionStore(RevisionStore): |
|
58 |
"""A RevisionStore layering on a TextStore and Inventory weave store."""
|
|
59 |
||
1563.2.28
by Robert Collins
Add total_size to the revision_store api. |
60 |
def __init__(self, text_store, serializer=None): |
1563.2.22
by Robert Collins
Move responsibility for repository.has_revision into RevisionStore |
61 |
"""Create a TextRevisionStore object.
|
62 |
||
63 |
:param text_store: the text store to put serialised revisions into.
|
|
64 |
"""
|
|
1563.2.28
by Robert Collins
Add total_size to the revision_store api. |
65 |
super(TextRevisionStore, self).__init__(serializer) |
1563.2.22
by Robert Collins
Move responsibility for repository.has_revision into RevisionStore |
66 |
self.text_store = text_store |
1563.2.27
by Robert Collins
Add signature text addition to the revisionstore api. |
67 |
self.text_store.register_suffix('sig') |
1563.2.22
by Robert Collins
Move responsibility for repository.has_revision into RevisionStore |
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."""
|
|
2309.4.8
by John Arbash Meinel
TextStores don't require Unicode file_ids anymore. test_a passes |
71 |
self.text_store.add(revision_as_file, revision.revision_id) |
1563.2.23
by Robert Collins
Add add_revision and get_revision methods to RevisionStore |
72 |
|
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. |
73 |
def add_revision_signature_text(self, revision_id, signature_text, transaction): |
74 |
"""See RevisionStore.add_revision_signature_text()."""
|
|
2309.4.8
by John Arbash Meinel
TextStores don't require Unicode file_ids anymore. test_a passes |
75 |
self.text_store.add(StringIO(signature_text), revision_id, "sig") |
1563.2.27
by Robert Collins
Add signature text addition to the revisionstore api. |
76 |
|
1563.2.29
by Robert Collins
Remove all but fetch references to repository.revision_store. |
77 |
def all_revision_ids(self, transaction): |
78 |
"""See RevisionStore.all_revision_ids()."""
|
|
79 |
# for TextRevisionStores, this is only functional
|
|
80 |
# on listable transports.
|
|
81 |
assert self.text_store.listable() |
|
82 |
result_graph = {} |
|
83 |
for rev_id in self.text_store: |
|
84 |
rev = self.get_revision(rev_id, transaction) |
|
85 |
result_graph[rev_id] = rev.parent_ids |
|
86 |
# remove ghosts
|
|
87 |
for rev_id, parents in result_graph.items(): |
|
1594.2.4
by Robert Collins
Merge in knit repository use of knits - still not a stable format, but can be experimented with. |
88 |
for parent in list(parents): |
1563.2.29
by Robert Collins
Remove all but fetch references to repository.revision_store. |
89 |
if not parent in result_graph: |
90 |
del parents[parents.index(parent)] |
|
91 |
return topo_sort(result_graph.items()) |
|
92 |
||
1756.1.2
by Aaron Bentley
Show logs using get_revisions |
93 |
def get_revisions(self, revision_ids, transaction): |
94 |
"""See RevisionStore.get_revisions()."""
|
|
95 |
revisions = [] |
|
1756.1.5
by Aaron Bentley
Test get_revisions with all repository types (and fix bug...) |
96 |
for revision_id in revision_ids: |
97 |
xml_file = self._get_revision_xml_file(revision_id) |
|
98 |
try: |
|
1756.1.2
by Aaron Bentley
Show logs using get_revisions |
99 |
r = self._serializer.read_revision(xml_file) |
1756.1.5
by Aaron Bentley
Test get_revisions with all repository types (and fix bug...) |
100 |
except SyntaxError, e: |
101 |
raise errors.BzrError('failed to unpack revision_xml', |
|
102 |
[revision_id, |
|
103 |
str(e)]) |
|
104 |
xml_file.close() |
|
1756.1.2
by Aaron Bentley
Show logs using get_revisions |
105 |
assert r.revision_id == revision_id |
106 |
revisions.append(r) |
|
2249.5.12
by John Arbash Meinel
Change the APIs for VersionedFile, Store, and some of Repository into utf-8 |
107 |
return revisions |
1563.2.23
by Robert Collins
Add add_revision and get_revision methods to RevisionStore |
108 |
|
109 |
def _get_revision_xml_file(self, revision_id): |
|
2743.1.5
by Robert Collins
Tighten the revision store implementation tests surrounding the |
110 |
_mod_revision.check_not_reserved_id(revision_id) |
1563.2.23
by Robert Collins
Add add_revision and get_revision methods to RevisionStore |
111 |
try: |
112 |
return self.text_store.get(revision_id) |
|
113 |
except (IndexError, KeyError): |
|
2094.3.5
by John Arbash Meinel
Fix imports to ensure modules are loaded before they are used |
114 |
raise errors.NoSuchRevision(self, revision_id) |
1563.2.23
by Robert Collins
Add add_revision and get_revision methods to RevisionStore |
115 |
|
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. |
116 |
def _get_signature_text(self, revision_id, transaction): |
117 |
"""See RevisionStore._get_signature_text()."""
|
|
118 |
try: |
|
119 |
return self.text_store.get(revision_id, suffix='sig').read() |
|
120 |
except (IndexError, KeyError): |
|
121 |
raise errors.NoSuchRevision(self, revision_id) |
|
122 |
||
1563.2.22
by Robert Collins
Move responsibility for repository.has_revision into RevisionStore |
123 |
def has_revision_id(self, revision_id, transaction): |
124 |
"""True if the store contains revision_id."""
|
|
2598.5.1
by Aaron Bentley
Start eliminating the use of None to indicate null revision |
125 |
return (_mod_revision.is_null(revision_id) |
1563.2.22
by Robert Collins
Move responsibility for repository.has_revision into RevisionStore |
126 |
or self.text_store.has_id(revision_id)) |
2249.5.12
by John Arbash Meinel
Change the APIs for VersionedFile, Store, and some of Repository into utf-8 |
127 |
|
1563.2.29
by Robert Collins
Remove all but fetch references to repository.revision_store. |
128 |
def _has_signature(self, revision_id, transaction): |
129 |
"""See RevisionStore._has_signature()."""
|
|
130 |
return self.text_store.has_id(revision_id, suffix='sig') |
|
131 |
||
1563.2.28
by Robert Collins
Add total_size to the revision_store api. |
132 |
def total_size(self, transaction): |
133 |
""" See RevisionStore.total_size()."""
|
|
134 |
return self.text_store.total_size() |