~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repofmt/knitrepo.py

  • Committer: Alexander Belchenko
  • Date: 2007-10-04 05:50:44 UTC
  • mfrom: (2881 +trunk)
  • mto: This revision was merged to the branch mainline in revision 2884.
  • Revision ID: bialix@ukr.net-20071004055044-pb88kgkfayawro8n
merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
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
16
16
 
 
17
from bzrlib.lazy_import import lazy_import
 
18
lazy_import(globals(), """
 
19
from bzrlib import (
 
20
    debug,
 
21
    )
 
22
from bzrlib.store import revision
 
23
from bzrlib.store.revision.knit import KnitRevisionStore
 
24
""")
17
25
from bzrlib import (
18
26
    bzrdir,
19
27
    deprecated_graph,
36
44
    )
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
41
49
 
42
50
 
129
137
            raise errors.NoSuchRevision(self, revision_id)
130
138
 
131
139
    @needs_read_lock
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)
136
 
 
137
 
    @needs_read_lock
138
140
    def get_revision_graph(self, revision_id=None):
139
141
        """Return a dictionary containing the revision graph.
140
142
 
143
145
        operation and will be removed in the future.
144
146
        :return: a dictionary of revision_id->revision_parents_list.
145
147
        """
 
148
        if 'evil' in debug.debug_flags:
 
149
            mutter_callsite(3,
 
150
                "get_revision_graph scales with size of history.")
146
151
        # special case NULL_REVISION
147
152
        if revision_id == _mod_revision.NULL_REVISION:
148
153
            return {}
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)
155
160
        else:
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.
165
170
        """
 
171
        if 'evil' in debug.debug_flags:
 
172
            mutter_callsite(3,
 
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())
227
235
 
228
236
class KnitRepository3(KnitRepository):
229
237
 
 
238
    # knit3 repositories need a RootCommitBuilder
230
239
    _commit_builder_class = RootCommitBuilder
231
240
 
232
241
    def __init__(self, _format, a_bzrdir, control_files, _revision_store,
270
279
     - a LockDir lock
271
280
    """
272
281
 
 
282
    # Set this attribute in derived classes to control the repository class
 
283
    # created by open and initialize.
 
284
    repository_class = None
 
285
 
273
286
    def _get_control_store(self, repo_transport, control_files):
274
287
        """Return the control store for this repository."""
275
288
        return VersionedFileStore(
282
295
 
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(
287
299
            repo_transport,
288
300
            file_mode=control_files._file_mode,
318
330
                       repository.
319
331
        """
320
332
        mutter('creating repository in %s.', a_bzrdir.transport.base)
321
 
        dirs = ['revision-store', 'knits']
 
333
        dirs = ['knits']
322
334
        files = []
323
335
        utf8_files = [('format', self.get_format_string())]
324
336
        
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,
380
392
    This format was introduced in bzr 0.8.
381
393
    """
382
394
 
 
395
    repository_class = KnitRepository
 
396
 
383
397
    def __ne__(self, other):
384
398
        return self.__class__ is not other.__class__
385
399
 
439
453
        """See RepositoryFormat.get_format_description()."""
440
454
        return "Knit repository format 3"
441
455
 
442
 
    def open(self, a_bzrdir, _found=False, _override_transport=None):
443
 
        """See RepositoryFormat.open().
444
 
        
445
 
        :param _override_transport: INTERNAL USE ONLY. Allows opening the
446
 
                                    repository at a slightly different url
447
 
                                    than normal. I.e. during 'upgrade'.
448
 
        """
449
 
        if not _found:
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
454
 
        else:
455
 
            repo_transport = a_bzrdir.get_repository_transport(None)
456
 
        control_files = lockable_files.LockableFiles(repo_transport, 'lock',
457
 
                                                     lockdir.LockDir)
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,
462
 
                                     a_bzrdir=a_bzrdir,
463
 
                                     control_files=control_files,
464
 
                                     _revision_store=_revision_store,
465
 
                                     control_store=control_store,
466
 
                                     text_store=text_store)
467
 
 
468
456
 
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)
490