17
17
from bzrlib import (
27
from bzrlib.decorators import needs_read_lock, needs_write_lock
24
28
from bzrlib.repository import (
30
MetaDirRepositoryFormat,
34
import bzrlib.revision as _mod_revision
35
from bzrlib.store.versioned import VersionedFileStore
36
from bzrlib.trace import mutter, note, warning
39
class KnitRepository(MetaDirRepository):
40
"""Knit format repository."""
42
def _warn_if_deprecated(self):
43
# This class isn't deprecated
46
def _inventory_add_lines(self, inv_vf, revid, parents, lines):
47
inv_vf.add_lines_with_ghosts(revid, parents, lines)
50
def _all_revision_ids(self):
51
"""See Repository.all_revision_ids()."""
52
# Knits get the revision graph from the index of the revision knit, so
53
# it's always possible even if they're on an unlistable transport.
54
return self._revision_store.all_revision_ids(self.get_transaction())
56
def fileid_involved_between_revs(self, from_revid, to_revid):
57
"""Find file_id(s) which are involved in the changes between revisions.
59
This determines the set of revisions which are involved, and then
60
finds all file ids affected by those revisions.
62
vf = self._get_revision_vf()
63
from_set = set(vf.get_ancestry(from_revid))
64
to_set = set(vf.get_ancestry(to_revid))
65
changed = to_set.difference(from_set)
66
return self._fileid_involved_by_set(changed)
68
def fileid_involved(self, last_revid=None):
69
"""Find all file_ids modified in the ancestry of last_revid.
71
:param last_revid: If None, last_revision() will be used.
74
changed = set(self.all_revision_ids())
76
changed = set(self.get_ancestry(last_revid))
79
return self._fileid_involved_by_set(changed)
82
def get_ancestry(self, revision_id):
83
"""Return a list of revision-ids integrated by a revision.
85
This is topologically sorted.
87
if revision_id is None:
89
vf = self._get_revision_vf()
91
return [None] + vf.get_ancestry(revision_id)
92
except errors.RevisionNotPresent:
93
raise errors.NoSuchRevision(self, revision_id)
96
def get_revision(self, revision_id):
97
"""Return the Revision object for a named revision"""
98
return self.get_revision_reconcile(revision_id)
101
def get_revision_graph(self, revision_id=None):
102
"""Return a dictionary containing the revision graph.
104
:param revision_id: The revision_id to get a graph from. If None, then
105
the entire revision graph is returned. This is a deprecated mode of
106
operation and will be removed in the future.
107
:return: a dictionary of revision_id->revision_parents_list.
109
# special case NULL_REVISION
110
if revision_id == _mod_revision.NULL_REVISION:
112
a_weave = self._get_revision_vf()
113
entire_graph = a_weave.get_graph()
114
if revision_id is None:
115
return a_weave.get_graph()
116
elif revision_id not in a_weave:
117
raise errors.NoSuchRevision(self, revision_id)
119
# add what can be reached from revision_id
121
pending = set([revision_id])
122
while len(pending) > 0:
124
result[node] = a_weave.get_parents(node)
125
for revision_id in result[node]:
126
if revision_id not in result:
127
pending.add(revision_id)
131
def get_revision_graph_with_ghosts(self, revision_ids=None):
132
"""Return a graph of the revisions with ghosts marked as applicable.
134
:param revision_ids: an iterable of revisions to graph or None for all.
135
:return: a Graph object with the graph reachable from revision_ids.
137
result = graph.Graph()
138
vf = self._get_revision_vf()
139
versions = set(vf.versions())
141
pending = set(self.all_revision_ids())
144
pending = set(revision_ids)
145
# special case NULL_REVISION
146
if _mod_revision.NULL_REVISION in pending:
147
pending.remove(_mod_revision.NULL_REVISION)
148
required = set(pending)
151
revision_id = pending.pop()
152
if not revision_id in versions:
153
if revision_id in required:
154
raise errors.NoSuchRevision(self, revision_id)
156
result.add_ghost(revision_id)
157
# mark it as done so we don't try for it again.
158
done.add(revision_id)
160
parent_ids = vf.get_parents_with_ghosts(revision_id)
161
for parent_id in parent_ids:
162
# is this queued or done ?
163
if (parent_id not in pending and
164
parent_id not in done):
166
pending.add(parent_id)
167
result.add_node(revision_id, parent_ids)
168
done.add(revision_id)
171
def _get_revision_vf(self):
172
""":return: a versioned file containing the revisions."""
173
vf = self._revision_store.get_revision_file(self.get_transaction())
177
def reconcile(self, other=None, thorough=False):
178
"""Reconcile this repository."""
179
from bzrlib.reconcile import KnitReconciler
180
reconciler = KnitReconciler(self, thorough=thorough)
181
reconciler.reconcile()
184
def revision_parents(self, revision_id):
185
return self._get_revision_vf().get_parents(revision_id)
32
188
class KnitRepository2(KnitRepository):
75
231
committer, revprops, revision_id)
234
class RepositoryFormatKnit(MetaDirRepositoryFormat):
235
"""Bzr repository knit format (generalized).
237
This repository format has:
238
- knits for file texts and inventory
239
- hash subdirectory based stores.
240
- knits for revisions and signatures
241
- TextStores for revisions and signatures.
242
- a format marker of its own
243
- an optional 'shared-storage' flag
244
- an optional 'no-working-trees' flag
248
def _get_control_store(self, repo_transport, control_files):
249
"""Return the control store for this repository."""
250
return VersionedFileStore(
253
file_mode=control_files._file_mode,
254
versionedfile_class=knit.KnitVersionedFile,
255
versionedfile_kwargs={'factory':knit.KnitPlainFactory()},
258
def _get_revision_store(self, repo_transport, control_files):
259
"""See RepositoryFormat._get_revision_store()."""
260
from bzrlib.store.revision.knit import KnitRevisionStore
261
versioned_file_store = VersionedFileStore(
263
file_mode=control_files._file_mode,
266
versionedfile_class=knit.KnitVersionedFile,
267
versionedfile_kwargs={'delta':False,
268
'factory':knit.KnitPlainFactory(),
272
return KnitRevisionStore(versioned_file_store)
274
def _get_text_store(self, transport, control_files):
275
"""See RepositoryFormat._get_text_store()."""
276
return self._get_versioned_file_store('knits',
279
versionedfile_class=knit.KnitVersionedFile,
280
versionedfile_kwargs={
281
'create_parent_dir':True,
283
'dir_mode':control_files._dir_mode,
287
def initialize(self, a_bzrdir, shared=False):
288
"""Create a knit format 1 repository.
290
:param a_bzrdir: bzrdir to contain the new repository; must already
292
:param shared: If true the repository will be initialized as a shared
295
mutter('creating repository in %s.', a_bzrdir.transport.base)
296
dirs = ['revision-store', 'knits']
298
utf8_files = [('format', self.get_format_string())]
300
self._upload_blank_content(a_bzrdir, dirs, files, utf8_files, shared)
301
repo_transport = a_bzrdir.get_repository_transport(None)
302
control_files = lockable_files.LockableFiles(repo_transport,
303
'lock', lockdir.LockDir)
304
control_store = self._get_control_store(repo_transport, control_files)
305
transaction = transactions.WriteTransaction()
306
# trigger a write of the inventory store.
307
control_store.get_weave_or_empty('inventory', transaction)
308
_revision_store = self._get_revision_store(repo_transport, control_files)
309
# the revision id here is irrelevant: it will not be stored, and cannot
311
_revision_store.has_revision_id('A', transaction)
312
_revision_store.get_signature_file(transaction)
313
return self.open(a_bzrdir=a_bzrdir, _found=True)
315
def open(self, a_bzrdir, _found=False, _override_transport=None):
316
"""See RepositoryFormat.open().
318
:param _override_transport: INTERNAL USE ONLY. Allows opening the
319
repository at a slightly different url
320
than normal. I.e. during 'upgrade'.
323
format = RepositoryFormat.find_format(a_bzrdir)
324
assert format.__class__ == self.__class__
325
if _override_transport is not None:
326
repo_transport = _override_transport
328
repo_transport = a_bzrdir.get_repository_transport(None)
329
control_files = lockable_files.LockableFiles(repo_transport,
330
'lock', lockdir.LockDir)
331
text_store = self._get_text_store(repo_transport, control_files)
332
control_store = self._get_control_store(repo_transport, control_files)
333
_revision_store = self._get_revision_store(repo_transport, control_files)
334
return KnitRepository(_format=self,
336
control_files=control_files,
337
_revision_store=_revision_store,
338
control_store=control_store,
339
text_store=text_store)
342
class RepositoryFormatKnit1(RepositoryFormatKnit):
343
"""Bzr repository knit format 1.
345
This repository format has:
346
- knits for file texts and inventory
347
- hash subdirectory based stores.
348
- knits for revisions and signatures
349
- TextStores for revisions and signatures.
350
- a format marker of its own
351
- an optional 'shared-storage' flag
352
- an optional 'no-working-trees' flag
355
This format was introduced in bzr 0.8.
357
def get_format_string(self):
358
"""See RepositoryFormat.get_format_string()."""
359
return "Bazaar-NG Knit Repository Format 1"
361
def get_format_description(self):
362
"""See RepositoryFormat.get_format_description()."""
363
return "Knit repository format 1"
365
def check_conversion_target(self, target_format):
78
369
class RepositoryFormatKnit2(RepositoryFormatKnit):
79
370
"""Bzr repository knit format 2.