78
73
text_store = get_store('text-store')
79
74
super(AllInOneRepository, self).__init__(_format, a_bzrdir, a_bzrdir._control_files, _revision_store, control_store, text_store)
82
def _all_possible_ids(self):
83
"""Return all the possible revisions that we could find."""
84
if 'evil' in debug.debug_flags:
85
mutter_callsite(3, "_all_possible_ids scales with size of history.")
86
return self.get_inventory_weave().versions()
89
def _all_revision_ids(self):
90
"""Returns a list of all the revision ids in the repository.
92
These are in as much topological order as the underlying store can
93
present: for weaves ghosts may lead to a lack of correctness until
94
the reweave updates the parents list.
96
if self._revision_store.text_store.listable():
97
return self._revision_store.all_revision_ids(self.get_transaction())
98
result = self._all_possible_ids()
99
# TODO: jam 20070210 Ensure that _all_possible_ids returns non-unicode
100
# ids. (It should, since _revision_store's API should change to
101
# return utf8 revision_ids)
102
return self._eliminate_revisions_not_present(result)
104
def _check_revision_parents(self, revision, inventory):
105
"""Private to Repository and Fetch.
107
This checks the parentage of revision in an inventory weave for
108
consistency and is only applicable to inventory-weave-for-ancestry
109
using repository formats & fetchers.
111
weave_parents = inventory.get_parent_map(
112
[revision.revision_id])[revision.revision_id]
113
parent_map = inventory.get_parent_map(revision.parent_ids)
114
for parent_id in revision.parent_ids:
115
if parent_id in parent_map:
116
# this parent must not be a ghost.
117
if not parent_id in weave_parents:
119
raise errors.CorruptRepository(self)
121
76
def get_commit_builder(self, branch, parents, config, timestamp=None,
122
77
timezone=None, committer=None, revprops=None,
123
78
revision_id=None):
124
79
self._check_ascii_revisionid(revision_id, self.get_commit_builder)
125
result = WeaveCommitBuilder(self, parents, config, timestamp, timezone,
126
committer, revprops, revision_id)
127
self.start_write_group()
131
def get_revisions(self, revision_ids):
132
revs = self._get_revisions(revision_ids)
133
# weave corruption can lead to absent revision markers that should be
135
# the following test is reasonably cheap (it needs a single weave read)
136
# and the weave is cached in read transactions. In write transactions
137
# it is not cached but typically we only read a small number of
138
# revisions. For knits when they are introduced we will probably want
139
# to ensure that caching write transactions are in use.
140
inv = self.get_inventory_weave()
142
self._check_revision_parents(rev, inv)
145
@deprecated_method(one_four)
147
def get_revision_graph(self, revision_id=None):
148
"""Return a dictionary containing the revision graph.
150
:param revision_id: The revision_id to get a graph from. If None, then
151
the entire revision graph is returned. This is a deprecated mode of
152
operation and will be removed in the future.
153
:return: a dictionary of revision_id->revision_parents_list.
155
if 'evil' in debug.debug_flags:
157
"get_revision_graph scales with size of history.")
158
# special case NULL_REVISION
159
if revision_id == _mod_revision.NULL_REVISION:
161
a_weave = self.get_inventory_weave()
162
all_revisions = self._eliminate_revisions_not_present(
164
entire_graph = a_weave.get_parent_map(all_revisions)
165
if revision_id is None:
167
elif revision_id not in entire_graph:
168
raise errors.NoSuchRevision(self, revision_id)
170
# add what can be reached from revision_id
172
pending = set([revision_id])
173
while len(pending) > 0:
175
result[node] = entire_graph[node]
176
for revision_id in result[node]:
177
if revision_id not in result:
178
pending.add(revision_id)
181
def has_revisions(self, revision_ids):
182
"""See Repository.has_revisions()."""
184
transaction = self.get_transaction()
185
for revision_id in revision_ids:
186
if self._revision_store.has_revision_id(revision_id, transaction):
187
result.add(revision_id)
80
return Repository.get_commit_builder(self, branch, parents, config,
81
timestamp, timezone, committer, revprops, revision_id)
191
84
def is_shared(self):
208
101
"""Returns the policy for making working trees on new branches."""
211
def revision_graph_can_have_wrong_parents(self):
212
# XXX: This is an old format that we don't support full checking on, so
213
# just claim that checking for this inconsistency is not required.
217
105
class WeaveMetaDirRepository(MetaDirRepository):
218
106
"""A subclass of MetaDirRepository to set weave specific policy."""
220
108
_serializer = xml5.serializer_v5
223
def _all_possible_ids(self):
224
"""Return all the possible revisions that we could find."""
225
if 'evil' in debug.debug_flags:
226
mutter_callsite(3, "_all_possible_ids scales with size of history.")
227
return self.get_inventory_weave().versions()
230
def _all_revision_ids(self):
231
"""Returns a list of all the revision ids in the repository.
233
These are in as much topological order as the underlying store can
234
present: for weaves ghosts may lead to a lack of correctness until
235
the reweave updates the parents list.
237
if self._revision_store.text_store.listable():
238
return self._revision_store.all_revision_ids(self.get_transaction())
239
result = self._all_possible_ids()
240
# TODO: jam 20070210 Ensure that _all_possible_ids returns non-unicode
241
# ids. (It should, since _revision_store's API should change to
242
# return utf8 revision_ids)
243
return self._eliminate_revisions_not_present(result)
245
def _check_revision_parents(self, revision, inventory):
246
"""Private to Repository and Fetch.
248
This checks the parentage of revision in an inventory weave for
249
consistency and is only applicable to inventory-weave-for-ancestry
250
using repository formats & fetchers.
252
weave_parents = inventory.get_parent_map(
253
[revision.revision_id])[revision.revision_id]
254
parent_map = inventory.get_parent_map(revision.parent_ids)
255
for parent_id in revision.parent_ids:
256
if parent_id in parent_map:
257
# this parent must not be a ghost.
258
if not parent_id in weave_parents:
260
raise errors.CorruptRepository(self)
262
110
def get_commit_builder(self, branch, parents, config, timestamp=None,
263
111
timezone=None, committer=None, revprops=None,
264
112
revision_id=None):
265
113
self._check_ascii_revisionid(revision_id, self.get_commit_builder)
266
result = WeaveCommitBuilder(self, parents, config, timestamp, timezone,
267
committer, revprops, revision_id)
268
self.start_write_group()
272
def get_revision(self, revision_id):
273
"""Return the Revision object for a named revision"""
274
# TODO: jam 20070210 get_revision_reconcile should do this for us
275
r = self.get_revision_reconcile(revision_id)
276
# weave corruption can lead to absent revision markers that should be
278
# the following test is reasonably cheap (it needs a single weave read)
279
# and the weave is cached in read transactions. In write transactions
280
# it is not cached but typically we only read a small number of
281
# revisions. For knits when they are introduced we will probably want
282
# to ensure that caching write transactions are in use.
283
inv = self.get_inventory_weave()
284
self._check_revision_parents(r, inv)
287
@deprecated_method(one_four)
289
def get_revision_graph(self, revision_id=None):
290
"""Return a dictionary containing the revision graph.
292
:param revision_id: The revision_id to get a graph from. If None, then
293
the entire revision graph is returned. This is a deprecated mode of
294
operation and will be removed in the future.
295
:return: a dictionary of revision_id->revision_parents_list.
297
if 'evil' in debug.debug_flags:
299
"get_revision_graph scales with size of history.")
300
# special case NULL_REVISION
301
if revision_id == _mod_revision.NULL_REVISION:
303
a_weave = self.get_inventory_weave()
304
all_revisions = self._eliminate_revisions_not_present(
306
entire_graph = a_weave.get_parent_map(all_revisions)
307
if revision_id is None:
309
elif revision_id not in entire_graph:
310
raise errors.NoSuchRevision(self, revision_id)
312
# add what can be reached from revision_id
314
pending = set([revision_id])
315
while len(pending) > 0:
317
result[node] = entire_graph[node]
318
for revision_id in result[node]:
319
if revision_id not in result:
320
pending.add(revision_id)
323
def has_revisions(self, revision_ids):
324
"""See Repository.has_revisions()."""
326
transaction = self.get_transaction()
327
for revision_id in revision_ids:
328
if self._revision_store.has_revision_id(revision_id, transaction):
329
result.add(revision_id)
332
def revision_graph_can_have_wrong_parents(self):
333
# XXX: This is an old format that we don't support full checking on, so
334
# just claim that checking for this inconsistency is not required.
114
return MetaDirRepository.get_commit_builder(self, branch, parents,
115
config, timestamp, timezone, committer, revprops, revision_id)
338
118
class PreSplitOutRepositoryFormat(RepositoryFormat):