/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to bzrlib/repofmt/knitrepo.py

Merge from 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
 
74
82
        # This class isn't deprecated
75
83
        pass
76
84
 
77
 
    def _inventory_add_lines(self, inv_vf, revid, parents, lines):
78
 
        inv_vf.add_lines_with_ghosts(revid, parents, lines)
 
85
    def _inventory_add_lines(self, inv_vf, revid, parents, lines, check_content):
 
86
        return inv_vf.add_lines_with_ghosts(revid, parents, lines,
 
87
            check_content=check_content)[0]
79
88
 
80
89
    @needs_read_lock
81
90
    def _all_revision_ids(self):
164
173
        operation and will be removed in the future.
165
174
        :return: a dictionary of revision_id->revision_parents_list.
166
175
        """
 
176
        if 'evil' in debug.debug_flags:
 
177
            mutter_callsite(3,
 
178
                "get_revision_graph scales with size of history.")
167
179
        # special case NULL_REVISION
168
180
        if revision_id == _mod_revision.NULL_REVISION:
169
181
            return {}
171
183
        a_weave = self._get_revision_vf()
172
184
        if revision_id is None:
173
185
            return a_weave.get_graph()
174
 
        elif revision_id not in a_weave:
 
186
        if revision_id not in a_weave:
175
187
            raise errors.NoSuchRevision(self, revision_id)
176
188
        else:
177
189
            # add what can be reached from revision_id
184
196
        :param revision_ids: an iterable of revisions to graph or None for all.
185
197
        :return: a Graph object with the graph reachable from revision_ids.
186
198
        """
 
199
        if 'evil' in debug.debug_flags:
 
200
            mutter_callsite(3,
 
201
                "get_revision_graph_with_ghosts scales with size of history.")
187
202
        result = deprecated_graph.Graph()
188
203
        vf = self._get_revision_vf()
189
204
        versions = set(vf.versions())
248
263
 
249
264
class KnitRepository3(KnitRepository):
250
265
 
 
266
    # knit3 repositories need a RootCommitBuilder
 
267
    _commit_builder_class = RootCommitBuilder
 
268
 
251
269
    def __init__(self, _format, a_bzrdir, control_files, _revision_store,
252
270
                 control_store, text_store):
253
271
        KnitRepository.__init__(self, _format, a_bzrdir, control_files,
274
292
        assert inv.root.revision is not None
275
293
        return KnitRepository.serialise_inventory(self, inv)
276
294
 
277
 
    def get_commit_builder(self, branch, parents, config, timestamp=None,
278
 
                           timezone=None, committer=None, revprops=None,
279
 
                           revision_id=None):
280
 
        """Obtain a CommitBuilder for this repository.
281
 
        
282
 
        :param branch: Branch to commit to.
283
 
        :param parents: Revision ids of the parents of the new revision.
284
 
        :param config: Configuration to use.
285
 
        :param timestamp: Optional timestamp recorded for commit.
286
 
        :param timezone: Optional timezone for timestamp.
287
 
        :param committer: Optional committer to set for commit.
288
 
        :param revprops: Optional dictionary of revision properties.
289
 
        :param revision_id: Optional revision id.
290
 
        """
291
 
        revision_id = osutils.safe_revision_id(revision_id)
292
 
        result = RootCommitBuilder(self, parents, config, timestamp, timezone,
293
 
                                 committer, revprops, revision_id)
294
 
        self.start_write_group()
295
 
        return result
296
 
 
297
295
 
298
296
class RepositoryFormatKnit(MetaDirRepositoryFormat):
299
297
    """Bzr repository knit format (generalized). 
309
307
     - a LockDir lock
310
308
    """
311
309
 
 
310
    # Set this attribute in derived classes to control the repository class
 
311
    # created by open and initialize.
 
312
    repository_class = None
 
313
 
312
314
    def _get_control_store(self, repo_transport, control_files):
313
315
        """Return the control store for this repository."""
314
316
        return VersionedFileStore(
321
323
 
322
324
    def _get_revision_store(self, repo_transport, control_files):
323
325
        """See RepositoryFormat._get_revision_store()."""
324
 
        from bzrlib.store.revision.knit import KnitRevisionStore
325
326
        versioned_file_store = VersionedFileStore(
326
327
            repo_transport,
327
328
            file_mode=control_files._file_mode,
357
358
                       repository.
358
359
        """
359
360
        mutter('creating repository in %s.', a_bzrdir.transport.base)
360
 
        dirs = ['revision-store', 'knits']
 
361
        dirs = ['knits']
361
362
        files = []
362
363
        utf8_files = [('format', self.get_format_string())]
363
364
        
395
396
        text_store = self._get_text_store(repo_transport, control_files)
396
397
        control_store = self._get_control_store(repo_transport, control_files)
397
398
        _revision_store = self._get_revision_store(repo_transport, control_files)
398
 
        return KnitRepository(_format=self,
 
399
        return self.repository_class(_format=self,
399
400
                              a_bzrdir=a_bzrdir,
400
401
                              control_files=control_files,
401
402
                              _revision_store=_revision_store,
419
420
    This format was introduced in bzr 0.8.
420
421
    """
421
422
 
 
423
    repository_class = KnitRepository
 
424
 
422
425
    def __ne__(self, other):
423
426
        return self.__class__ is not other.__class__
424
427
 
478
481
        """See RepositoryFormat.get_format_description()."""
479
482
        return "Knit repository format 3"
480
483
 
481
 
    def open(self, a_bzrdir, _found=False, _override_transport=None):
482
 
        """See RepositoryFormat.open().
483
 
        
484
 
        :param _override_transport: INTERNAL USE ONLY. Allows opening the
485
 
                                    repository at a slightly different url
486
 
                                    than normal. I.e. during 'upgrade'.
487
 
        """
488
 
        if not _found:
489
 
            format = RepositoryFormat.find_format(a_bzrdir)
490
 
            assert format.__class__ ==  self.__class__
491
 
        if _override_transport is not None:
492
 
            repo_transport = _override_transport
493
 
        else:
494
 
            repo_transport = a_bzrdir.get_repository_transport(None)
495
 
        control_files = lockable_files.LockableFiles(repo_transport, 'lock',
496
 
                                                     lockdir.LockDir)
497
 
        text_store = self._get_text_store(repo_transport, control_files)
498
 
        control_store = self._get_control_store(repo_transport, control_files)
499
 
        _revision_store = self._get_revision_store(repo_transport, control_files)
500
 
        return self.repository_class(_format=self,
501
 
                                     a_bzrdir=a_bzrdir,
502
 
                                     control_files=control_files,
503
 
                                     _revision_store=_revision_store,
504
 
                                     control_store=control_store,
505
 
                                     text_store=text_store)
506
 
 
507
484
 
508
485
def _get_stream_as_bytes(knit, required_versions):
509
486
    """Generate a serialised data stream.
526
503
    for version, options, length, parents in data_list:
527
504
        data.append([version, options, parents, callable(length)])
528
505
    return bencode.bencode(data)
529