14
14
# along with this program; if not, write to the Free Software
15
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
17
from bzrlib.lazy_import import lazy_import
18
lazy_import(globals(), """
22
from bzrlib.store import revision
23
from bzrlib.store.revision.knit import KnitRevisionStore
17
25
from bzrlib import (
37
45
import bzrlib.revision as _mod_revision
38
46
from bzrlib.store.versioned import VersionedFileStore
39
from bzrlib.trace import mutter, note, warning
47
from bzrlib.trace import mutter, mutter_callsite
40
48
from bzrlib.util import bencode
129
137
raise errors.NoSuchRevision(self, revision_id)
132
def get_revision(self, revision_id):
133
"""Return the Revision object for a named revision"""
134
revision_id = osutils.safe_revision_id(revision_id)
135
return self.get_revision_reconcile(revision_id)
138
140
def get_revision_graph(self, revision_id=None):
139
141
"""Return a dictionary containing the revision graph.
143
145
operation and will be removed in the future.
144
146
:return: a dictionary of revision_id->revision_parents_list.
148
if 'evil' in debug.debug_flags:
150
"get_revision_graph scales with size of history.")
146
151
# special case NULL_REVISION
147
152
if revision_id == _mod_revision.NULL_REVISION:
150
155
a_weave = self._get_revision_vf()
151
156
if revision_id is None:
152
157
return a_weave.get_graph()
153
elif revision_id not in a_weave:
158
if revision_id not in a_weave:
154
159
raise errors.NoSuchRevision(self, revision_id)
156
161
# add what can be reached from revision_id
163
168
:param revision_ids: an iterable of revisions to graph or None for all.
164
169
:return: a Graph object with the graph reachable from revision_ids.
171
if 'evil' in debug.debug_flags:
173
"get_revision_graph_with_ghosts scales with size of history.")
166
174
result = deprecated_graph.Graph()
167
175
vf = self._get_revision_vf()
168
176
versions = set(vf.versions())
228
236
class KnitRepository3(KnitRepository):
238
# knit3 repositories need a RootCommitBuilder
230
239
_commit_builder_class = RootCommitBuilder
232
241
def __init__(self, _format, a_bzrdir, control_files, _revision_store,
282
# Set this attribute in derived classes to control the repository class
283
# created by open and initialize.
284
repository_class = None
273
286
def _get_control_store(self, repo_transport, control_files):
274
287
"""Return the control store for this repository."""
275
288
return VersionedFileStore(
283
296
def _get_revision_store(self, repo_transport, control_files):
284
297
"""See RepositoryFormat._get_revision_store()."""
285
from bzrlib.store.revision.knit import KnitRevisionStore
286
298
versioned_file_store = VersionedFileStore(
288
300
file_mode=control_files._file_mode,
320
332
mutter('creating repository in %s.', a_bzrdir.transport.base)
321
dirs = ['revision-store', 'knits']
323
335
utf8_files = [('format', self.get_format_string())]
356
368
text_store = self._get_text_store(repo_transport, control_files)
357
369
control_store = self._get_control_store(repo_transport, control_files)
358
370
_revision_store = self._get_revision_store(repo_transport, control_files)
359
return KnitRepository(_format=self,
371
return self.repository_class(_format=self,
360
372
a_bzrdir=a_bzrdir,
361
373
control_files=control_files,
362
374
_revision_store=_revision_store,
439
453
"""See RepositoryFormat.get_format_description()."""
440
454
return "Knit repository format 3"
442
def open(self, a_bzrdir, _found=False, _override_transport=None):
443
"""See RepositoryFormat.open().
445
:param _override_transport: INTERNAL USE ONLY. Allows opening the
446
repository at a slightly different url
447
than normal. I.e. during 'upgrade'.
450
format = RepositoryFormat.find_format(a_bzrdir)
451
assert format.__class__ == self.__class__
452
if _override_transport is not None:
453
repo_transport = _override_transport
455
repo_transport = a_bzrdir.get_repository_transport(None)
456
control_files = lockable_files.LockableFiles(repo_transport, 'lock',
458
text_store = self._get_text_store(repo_transport, control_files)
459
control_store = self._get_control_store(repo_transport, control_files)
460
_revision_store = self._get_revision_store(repo_transport, control_files)
461
return self.repository_class(_format=self,
463
control_files=control_files,
464
_revision_store=_revision_store,
465
control_store=control_store,
466
text_store=text_store)
469
457
def _get_stream_as_bytes(knit, required_versions):
470
458
"""Generate a serialised data stream.
487
475
for version, options, length, parents in data_list:
488
476
data.append([version, options, parents, callable(length)])
489
477
return bencode.bencode(data)