/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

  • Committer: Andrew Bennetts
  • Date: 2008-10-30 01:05:59 UTC
  • mto: This revision was merged to the branch mainline in revision 3813.
  • Revision ID: andrew.bennetts@canonical.com-20081030010559-tumoefnsmhg4snxo
Add contrib/bzr_ssh_path_limiter.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2007-2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2007 Canonical Ltd
2
2
#
3
3
# This program is free software; you can redistribute it and/or modify
4
4
# it under the terms of the GNU General Public License as published by
12
12
#
13
13
# You should have received a copy of the GNU General Public License
14
14
# along with this program; if not, write to the Free Software
15
 
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
 
15
# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
16
16
 
17
17
from bzrlib.lazy_import import lazy_import
18
18
lazy_import(globals(), """
24
24
    lockdir,
25
25
    osutils,
26
26
    revision as _mod_revision,
27
 
    trace,
28
27
    transactions,
29
28
    versionedfile,
30
29
    xml5,
38
37
from bzrlib.decorators import needs_read_lock, needs_write_lock
39
38
from bzrlib.repository import (
40
39
    CommitBuilder,
41
 
    IsInWriteGroupError,
42
40
    MetaDirRepository,
43
41
    MetaDirRepositoryFormat,
44
42
    RepositoryFormat,
45
43
    RootCommitBuilder,
46
44
    )
 
45
from bzrlib.trace import mutter, mutter_callsite
47
46
 
48
47
 
49
48
class _KnitParentsProvider(object):
54
53
    def __repr__(self):
55
54
        return 'KnitParentsProvider(%r)' % self._knit
56
55
 
 
56
    @symbol_versioning.deprecated_method(symbol_versioning.one_one)
 
57
    def get_parents(self, revision_ids):
 
58
        """See graph._StackedParentsProvider.get_parents"""
 
59
        parent_map = self.get_parent_map(revision_ids)
 
60
        return [parent_map.get(r, None) for r in revision_ids]
 
61
 
57
62
    def get_parent_map(self, keys):
58
 
        """See graph.StackedParentsProvider.get_parent_map"""
 
63
        """See graph._StackedParentsProvider.get_parent_map"""
59
64
        parent_map = {}
60
65
        for revision_id in keys:
61
66
            if revision_id is None:
86
91
        return 'KnitsParentsProvider(%r)' % self._knit
87
92
 
88
93
    def get_parent_map(self, keys):
89
 
        """See graph.StackedParentsProvider.get_parent_map"""
 
94
        """See graph._StackedParentsProvider.get_parent_map"""
90
95
        parent_map = self._knit.get_parent_map(
91
96
            [self._prefix + (key,) for key in keys])
92
97
        result = {}
119
124
        self._commit_builder_class = _commit_builder_class
120
125
        self._serializer = _serializer
121
126
        self._reconcile_fixes_text_parents = True
 
127
        self._fetch_uses_deltas = True
 
128
        self._fetch_order = 'topological'
122
129
 
123
130
    @needs_read_lock
124
131
    def _all_revision_ids(self):
208
215
        revision_id = osutils.safe_revision_id(revision_id)
209
216
        return self.get_revision_reconcile(revision_id)
210
217
 
211
 
    def _refresh_data(self):
212
 
        if not self.is_locked():
213
 
            return
214
 
        if self.is_in_write_group():
215
 
            raise IsInWriteGroupError(self)
216
 
        # Create a new transaction to force all knits to see the scope change.
217
 
        # This is safe because we're outside a write group.
218
 
        self.control_files._finish_transaction()
219
 
        if self.is_write_locked():
220
 
            self.control_files._set_write_transaction()
221
 
        else:
222
 
            self.control_files._set_read_transaction()
223
 
 
224
218
    @needs_write_lock
225
219
    def reconcile(self, other=None, thorough=False):
226
220
        """Reconcile this repository."""
228
222
        reconciler = KnitReconciler(self, thorough=thorough)
229
223
        reconciler.reconcile()
230
224
        return reconciler
231
 
 
 
225
    
232
226
    def _make_parents_provider(self):
233
227
        return _KnitsParentsProvider(self.revisions)
234
228
 
235
 
    def _find_inconsistent_revision_parents(self, revisions_iterator=None):
 
229
    def _find_inconsistent_revision_parents(self):
236
230
        """Find revisions with different parent lists in the revision object
237
231
        and in the index graph.
238
232
 
239
 
        :param revisions_iterator: None, or an iterator of (revid,
240
 
            Revision-or-None). This iterator controls the revisions checked.
241
233
        :returns: an iterator yielding tuples of (revison-id, parents-in-index,
242
234
            parents-in-revision).
243
235
        """
244
236
        if not self.is_locked():
245
237
            raise AssertionError()
246
238
        vf = self.revisions
247
 
        if revisions_iterator is None:
248
 
            revisions_iterator = self._iter_revisions(None)
249
 
        for revid, revision in revisions_iterator:
250
 
            if revision is None:
251
 
                pass
252
 
            parent_map = vf.get_parent_map([(revid,)])
 
239
        for index_version in vf.keys():
 
240
            parent_map = vf.get_parent_map([index_version])
253
241
            parents_according_to_index = tuple(parent[-1] for parent in
254
 
                parent_map[(revid,)])
 
242
                parent_map[index_version])
 
243
            revision = self.get_revision(index_version[-1])
255
244
            parents_according_to_revision = tuple(revision.parent_ids)
256
245
            if parents_according_to_index != parents_according_to_revision:
257
 
                yield (revid, parents_according_to_index,
 
246
                yield (index_version[-1], parents_according_to_index,
258
247
                    parents_according_to_revision)
259
248
 
260
249
    def _check_for_inconsistent_revision_parents(self):
270
259
 
271
260
 
272
261
class RepositoryFormatKnit(MetaDirRepositoryFormat):
273
 
    """Bzr repository knit format (generalized).
 
262
    """Bzr repository knit format (generalized). 
274
263
 
275
264
    This repository format has:
276
265
     - knits for file texts and inventory
299
288
    supports_ghosts = True
300
289
    # External lookups are not supported in this format.
301
290
    supports_external_lookups = False
302
 
    # No CHK support.
303
 
    supports_chks = False
304
 
    _fetch_order = 'topological'
305
 
    _fetch_uses_deltas = True
306
 
    fast_deltas = False
307
291
 
308
292
    def _get_inventories(self, repo_transport, repo, name='inventory'):
309
293
        mapper = versionedfile.ConstantMapper(name)
345
329
        :param shared: If true the repository will be initialized as a shared
346
330
                       repository.
347
331
        """
348
 
        trace.mutter('creating repository in %s.', a_bzrdir.transport.base)
 
332
        mutter('creating repository in %s.', a_bzrdir.transport.base)
349
333
        dirs = ['knits']
350
334
        files = []
351
335
        utf8_files = [('format', self.get_format_string())]
352
 
 
 
336
        
353
337
        self._upload_blank_content(a_bzrdir, dirs, files, utf8_files, shared)
354
338
        repo_transport = a_bzrdir.get_repository_transport(None)
355
339
        control_files = lockable_files.LockableFiles(repo_transport,
363
347
        result.revisions.get_parent_map([('A',)])
364
348
        result.signatures.get_parent_map([('A',)])
365
349
        result.unlock()
366
 
        self._run_post_repo_init_hooks(result, a_bzrdir, shared)
367
350
        return result
368
351
 
369
352
    def open(self, a_bzrdir, _found=False, _override_transport=None):
370
353
        """See RepositoryFormat.open().
371
 
 
 
354
        
372
355
        :param _override_transport: INTERNAL USE ONLY. Allows opening the
373
356
                                    repository at a slightly different url
374
357
                                    than normal. I.e. during 'upgrade'.
390
373
        repo.signatures = self._get_signatures(repo_transport, repo)
391
374
        repo.inventories = self._get_inventories(repo_transport, repo)
392
375
        repo.texts = self._get_texts(repo_transport, repo)
393
 
        repo.chk_bytes = None
394
376
        repo._transport = repo_transport
395
377
        return repo
396
378
 
428
410
        """See RepositoryFormat.get_format_description()."""
429
411
        return "Knit repository format 1"
430
412
 
 
413
    def check_conversion_target(self, target_format):
 
414
        pass
 
415
 
431
416
 
432
417
class RepositoryFormatKnit3(RepositoryFormatKnit):
433
418
    """Bzr repository knit format 3.
448
433
    repository_class = KnitRepository
449
434
    _commit_builder_class = RootCommitBuilder
450
435
    rich_root_data = True
451
 
    experimental = True
452
436
    supports_tree_reference = True
453
437
    @property
454
438
    def _serializer(self):
462
446
 
463
447
    _matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
464
448
 
 
449
    def check_conversion_target(self, target_format):
 
450
        if not target_format.rich_root_data:
 
451
            raise errors.BadConversionTarget(
 
452
                'Does not support rich root data.', target_format)
 
453
        if not getattr(target_format, 'supports_tree_reference', False):
 
454
            raise errors.BadConversionTarget(
 
455
                'Does not support nested trees', target_format)
 
456
            
465
457
    def get_format_string(self):
466
458
        """See RepositoryFormat.get_format_string()."""
467
459
        return "Bazaar Knit Repository Format 3 (bzr 0.15)\n"
503
495
 
504
496
    _matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
505
497
 
 
498
    def check_conversion_target(self, target_format):
 
499
        if not target_format.rich_root_data:
 
500
            raise errors.BadConversionTarget(
 
501
                'Does not support rich root data.', target_format)
 
502
 
506
503
    def get_format_string(self):
507
504
        """See RepositoryFormat.get_format_string()."""
508
505
        return 'Bazaar Knit Repository Format 4 (bzr 1.0)\n'