/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: Richard Wilbur
  • Date: 2016-02-04 19:07:28 UTC
  • mto: This revision was merged to the branch mainline in revision 6618.
  • Revision ID: richard.wilbur@gmail.com-20160204190728-p0zvfii6zase0fw7
Update COPYING.txt from the original http://www.gnu.org/licenses/gpl-2.0.txt  (Only differences were in whitespace.)  Thanks to Petr Stodulka for pointing out the discrepancy.

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., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
16
16
 
17
 
from ..lazy_import import lazy_import
 
17
from __future__ import absolute_import
 
18
 
 
19
from bzrlib.lazy_import import lazy_import
18
20
lazy_import(globals(), """
19
21
import itertools
20
22
 
21
 
from breezy import (
 
23
from bzrlib import (
22
24
    controldir,
 
25
    errors,
 
26
    knit as _mod_knit,
23
27
    lockable_files,
24
28
    lockdir,
25
29
    osutils,
26
30
    revision as _mod_revision,
27
31
    trace,
28
32
    transactions,
29
 
    )
30
 
from breezy.bzr import (
31
 
    knit as _mod_knit,
32
33
    versionedfile,
33
34
    xml5,
34
35
    xml6,
35
36
    xml7,
36
37
    )
37
38
""")
38
 
from .. import (
39
 
    errors,
40
 
    )
41
 
from ..repository import (
 
39
from bzrlib.decorators import needs_read_lock, needs_write_lock
 
40
from bzrlib.repository import (
42
41
    InterRepository,
43
42
    IsInWriteGroupError,
44
 
    )
45
 
from ..bzr.repository import (
46
43
    RepositoryFormatMetaDir,
47
44
    )
48
 
from ..bzr.vf_repository import (
 
45
from bzrlib.vf_repository import (
49
46
    InterSameDataRepository,
50
47
    MetaDirVersionedFileRepository,
51
48
    MetaDirVersionedFileRepositoryFormat,
52
49
    VersionedFileCommitBuilder,
 
50
    VersionedFileRootCommitBuilder,
53
51
    )
 
52
from bzrlib import symbol_versioning
54
53
 
55
54
 
56
55
class _KnitParentsProvider(object):
120
119
    _commit_builder_class = None
121
120
    _serializer = None
122
121
 
123
 
    def __init__(self, _format, a_controldir, control_files, _commit_builder_class,
124
 
                 _serializer):
125
 
        super(KnitRepository, self).__init__(
126
 
            _format, a_controldir, control_files)
 
122
    def __init__(self, _format, a_bzrdir, control_files, _commit_builder_class,
 
123
        _serializer):
 
124
        super(KnitRepository, self).__init__(_format, a_bzrdir, control_files)
127
125
        self._commit_builder_class = _commit_builder_class
128
126
        self._serializer = _serializer
129
127
        self._reconcile_fixes_text_parents = True
130
128
 
 
129
    @needs_read_lock
131
130
    def _all_revision_ids(self):
132
131
        """See Repository.all_revision_ids()."""
133
 
        with self.lock_read():
134
 
            return [key[0] for key in self.revisions.keys()]
 
132
        return [key[0] for key in self.revisions.keys()]
135
133
 
136
134
    def _activate_new_inventory(self):
137
135
        """Put a replacement inventory.new into use as inventories."""
178
176
 
179
177
    def _temp_inventories(self):
180
178
        result = self._format._get_inventories(self._transport, self,
181
 
                                               'inventory.new')
 
179
            'inventory.new')
182
180
        # Reconciling when the output has no revisions would result in no
183
181
        # writes - but we want to ensure there is an inventory for
184
182
        # compatibility with older clients that don't lazy-load.
185
 
        result.get_parent_map([(b'A',)])
 
183
        result.get_parent_map([('A',)])
186
184
        return result
187
185
 
 
186
    @needs_read_lock
188
187
    def get_revision(self, revision_id):
189
188
        """Return the Revision object for a named revision"""
190
 
        with self.lock_read():
191
 
            return self.get_revision_reconcile(revision_id)
 
189
        revision_id = osutils.safe_revision_id(revision_id)
 
190
        return self.get_revision_reconcile(revision_id)
192
191
 
193
192
    def _refresh_data(self):
194
193
        if not self.is_locked():
203
202
        else:
204
203
            self.control_files._set_read_transaction()
205
204
 
 
205
    @needs_write_lock
206
206
    def reconcile(self, other=None, thorough=False):
207
207
        """Reconcile this repository."""
208
 
        from .reconcile import KnitReconciler
209
 
        with self.lock_write():
210
 
            reconciler = KnitReconciler(self, thorough=thorough)
211
 
            return reconciler.reconcile()
 
208
        from bzrlib.reconcile import KnitReconciler
 
209
        reconciler = KnitReconciler(self, thorough=thorough)
 
210
        reconciler.reconcile()
 
211
        return reconciler
212
212
 
213
213
    def _make_parents_provider(self):
214
214
        return _KnitsParentsProvider(self.revisions)
237
237
    _commit_builder_class = None
238
238
    # Set this attribute in derived clases to control the _serializer that the
239
239
    # repository objects will have passed to their constructor.
240
 
 
241
240
    @property
242
241
    def _serializer(self):
243
242
        return xml5.serializer_v5
258
257
    def _get_inventories(self, repo_transport, repo, name='inventory'):
259
258
        mapper = versionedfile.ConstantMapper(name)
260
259
        index = _mod_knit._KndxIndex(repo_transport, mapper,
261
 
                                     repo.get_transaction, repo.is_write_locked, repo.is_locked)
 
260
            repo.get_transaction, repo.is_write_locked, repo.is_locked)
262
261
        access = _mod_knit._KnitKeyAccess(repo_transport, mapper)
263
262
        return _mod_knit.KnitVersionedFiles(index, access, annotated=False)
264
263
 
265
264
    def _get_revisions(self, repo_transport, repo):
266
265
        mapper = versionedfile.ConstantMapper('revisions')
267
266
        index = _mod_knit._KndxIndex(repo_transport, mapper,
268
 
                                     repo.get_transaction, repo.is_write_locked, repo.is_locked)
 
267
            repo.get_transaction, repo.is_write_locked, repo.is_locked)
269
268
        access = _mod_knit._KnitKeyAccess(repo_transport, mapper)
270
269
        return _mod_knit.KnitVersionedFiles(index, access, max_delta_chain=0,
271
 
                                            annotated=False)
 
270
            annotated=False)
272
271
 
273
272
    def _get_signatures(self, repo_transport, repo):
274
273
        mapper = versionedfile.ConstantMapper('signatures')
275
274
        index = _mod_knit._KndxIndex(repo_transport, mapper,
276
 
                                     repo.get_transaction, repo.is_write_locked, repo.is_locked)
 
275
            repo.get_transaction, repo.is_write_locked, repo.is_locked)
277
276
        access = _mod_knit._KnitKeyAccess(repo_transport, mapper)
278
277
        return _mod_knit.KnitVersionedFiles(index, access, max_delta_chain=0,
279
 
                                            annotated=False)
 
278
            annotated=False)
280
279
 
281
280
    def _get_texts(self, repo_transport, repo):
282
281
        mapper = versionedfile.HashEscapedPrefixMapper()
283
282
        base_transport = repo_transport.clone('knits')
284
283
        index = _mod_knit._KndxIndex(base_transport, mapper,
285
 
                                     repo.get_transaction, repo.is_write_locked, repo.is_locked)
 
284
            repo.get_transaction, repo.is_write_locked, repo.is_locked)
286
285
        access = _mod_knit._KnitKeyAccess(base_transport, mapper)
287
286
        return _mod_knit.KnitVersionedFiles(index, access, max_delta_chain=200,
288
 
                                            annotated=True)
 
287
            annotated=True)
289
288
 
290
 
    def initialize(self, a_controldir, shared=False):
 
289
    def initialize(self, a_bzrdir, shared=False):
291
290
        """Create a knit format 1 repository.
292
291
 
293
 
        :param a_controldir: bzrdir to contain the new repository; must already
 
292
        :param a_bzrdir: bzrdir to contain the new repository; must already
294
293
            be initialized.
295
294
        :param shared: If true the repository will be initialized as a shared
296
295
                       repository.
297
296
        """
298
 
        trace.mutter('creating repository in %s.', a_controldir.transport.base)
 
297
        trace.mutter('creating repository in %s.', a_bzrdir.transport.base)
299
298
        dirs = ['knits']
300
299
        files = []
301
300
        utf8_files = [('format', self.get_format_string())]
302
301
 
303
 
        self._upload_blank_content(
304
 
            a_controldir, dirs, files, utf8_files, shared)
305
 
        repo_transport = a_controldir.get_repository_transport(None)
 
302
        self._upload_blank_content(a_bzrdir, dirs, files, utf8_files, shared)
 
303
        repo_transport = a_bzrdir.get_repository_transport(None)
306
304
        control_files = lockable_files.LockableFiles(repo_transport,
307
 
                                                     'lock', lockdir.LockDir)
 
305
                                'lock', lockdir.LockDir)
308
306
        transaction = transactions.WriteTransaction()
309
 
        result = self.open(a_controldir=a_controldir, _found=True)
 
307
        result = self.open(a_bzrdir=a_bzrdir, _found=True)
310
308
        result.lock_write()
311
309
        # the revision id here is irrelevant: it will not be stored, and cannot
312
310
        # already exist, we do this to create files on disk for older clients.
313
 
        result.inventories.get_parent_map([(b'A',)])
314
 
        result.revisions.get_parent_map([(b'A',)])
315
 
        result.signatures.get_parent_map([(b'A',)])
 
311
        result.inventories.get_parent_map([('A',)])
 
312
        result.revisions.get_parent_map([('A',)])
 
313
        result.signatures.get_parent_map([('A',)])
316
314
        result.unlock()
317
 
        self._run_post_repo_init_hooks(result, a_controldir, shared)
 
315
        self._run_post_repo_init_hooks(result, a_bzrdir, shared)
318
316
        return result
319
317
 
320
 
    def open(self, a_controldir, _found=False, _override_transport=None):
 
318
    def open(self, a_bzrdir, _found=False, _override_transport=None):
321
319
        """See RepositoryFormat.open().
322
320
 
323
321
        :param _override_transport: INTERNAL USE ONLY. Allows opening the
325
323
                                    than normal. I.e. during 'upgrade'.
326
324
        """
327
325
        if not _found:
328
 
            format = RepositoryFormatMetaDir.find_format(a_controldir)
 
326
            format = RepositoryFormatMetaDir.find_format(a_bzrdir)
329
327
        if _override_transport is not None:
330
328
            repo_transport = _override_transport
331
329
        else:
332
 
            repo_transport = a_controldir.get_repository_transport(None)
 
330
            repo_transport = a_bzrdir.get_repository_transport(None)
333
331
        control_files = lockable_files.LockableFiles(repo_transport,
334
 
                                                     'lock', lockdir.LockDir)
 
332
                                'lock', lockdir.LockDir)
335
333
        repo = self.repository_class(_format=self,
336
 
                                     a_controldir=a_controldir,
337
 
                                     control_files=control_files,
338
 
                                     _commit_builder_class=self._commit_builder_class,
339
 
                                     _serializer=self._serializer)
 
334
                              a_bzrdir=a_bzrdir,
 
335
                              control_files=control_files,
 
336
                              _commit_builder_class=self._commit_builder_class,
 
337
                              _serializer=self._serializer)
340
338
        repo.revisions = self._get_revisions(repo_transport, repo)
341
339
        repo.signatures = self._get_signatures(repo_transport, repo)
342
340
        repo.inventories = self._get_inventories(repo_transport, repo)
364
362
 
365
363
    repository_class = KnitRepository
366
364
    _commit_builder_class = VersionedFileCommitBuilder
367
 
 
368
365
    @property
369
366
    def _serializer(self):
370
367
        return xml5.serializer_v5
375
372
    @classmethod
376
373
    def get_format_string(cls):
377
374
        """See RepositoryFormat.get_format_string()."""
378
 
        return b"Bazaar-NG Knit Repository Format 1"
 
375
        return "Bazaar-NG Knit Repository Format 1"
379
376
 
380
377
    def get_format_description(self):
381
378
        """See RepositoryFormat.get_format_description()."""
399
396
    """
400
397
 
401
398
    repository_class = KnitRepository
402
 
    _commit_builder_class = VersionedFileCommitBuilder
 
399
    _commit_builder_class = VersionedFileRootCommitBuilder
403
400
    rich_root_data = True
404
401
    experimental = True
405
402
    supports_tree_reference = True
406
 
 
407
403
    @property
408
404
    def _serializer(self):
409
405
        return xml7.serializer_v7
410
406
 
411
407
    def _get_matching_bzrdir(self):
412
 
        return controldir.format_registry.make_controldir('dirstate-with-subtree')
 
408
        return controldir.format_registry.make_bzrdir('dirstate-with-subtree')
413
409
 
414
410
    def _ignore_setting_bzrdir(self, format):
415
411
        pass
416
412
 
417
 
    _matchingcontroldir = property(
418
 
        _get_matching_bzrdir, _ignore_setting_bzrdir)
 
413
    _matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
419
414
 
420
415
    @classmethod
421
416
    def get_format_string(cls):
422
417
        """See RepositoryFormat.get_format_string()."""
423
 
        return b"Bazaar Knit Repository Format 3 (bzr 0.15)\n"
 
418
        return "Bazaar Knit Repository Format 3 (bzr 0.15)\n"
424
419
 
425
420
    def get_format_description(self):
426
421
        """See RepositoryFormat.get_format_description()."""
444
439
    """
445
440
 
446
441
    repository_class = KnitRepository
447
 
    _commit_builder_class = VersionedFileCommitBuilder
 
442
    _commit_builder_class = VersionedFileRootCommitBuilder
448
443
    rich_root_data = True
449
444
    supports_tree_reference = False
450
 
 
451
445
    @property
452
446
    def _serializer(self):
453
447
        return xml6.serializer_v6
454
448
 
455
449
    def _get_matching_bzrdir(self):
456
 
        return controldir.format_registry.make_controldir('rich-root')
 
450
        return controldir.format_registry.make_bzrdir('rich-root')
457
451
 
458
452
    def _ignore_setting_bzrdir(self, format):
459
453
        pass
460
454
 
461
 
    _matchingcontroldir = property(
462
 
        _get_matching_bzrdir, _ignore_setting_bzrdir)
 
455
    _matchingbzrdir = property(_get_matching_bzrdir, _ignore_setting_bzrdir)
463
456
 
464
457
    @classmethod
465
458
    def get_format_string(cls):
466
459
        """See RepositoryFormat.get_format_string()."""
467
 
        return b'Bazaar Knit Repository Format 4 (bzr 1.0)\n'
 
460
        return 'Bazaar Knit Repository Format 4 (bzr 1.0)\n'
468
461
 
469
462
    def get_format_description(self):
470
463
        """See RepositoryFormat.get_format_description()."""
487
480
        overly general.
488
481
        """
489
482
        try:
490
 
            are_knits = (isinstance(source._format, RepositoryFormatKnit)
491
 
                         and isinstance(target._format, RepositoryFormatKnit))
 
483
            are_knits = (isinstance(source._format, RepositoryFormatKnit) and
 
484
                isinstance(target._format, RepositoryFormatKnit))
492
485
        except AttributeError:
493
486
            return False
494
487
        return are_knits and InterRepository._same_model(source, target)
495
488
 
 
489
    @needs_read_lock
496
490
    def search_missing_revision_ids(self,
497
 
                                    find_ghosts=True, revision_ids=None, if_present_ids=None,
498
 
                                    limit=None):
 
491
            find_ghosts=True, revision_ids=None, if_present_ids=None,
 
492
            limit=None):
499
493
        """See InterRepository.search_missing_revision_ids()."""
500
 
        with self.lock_read():
501
 
            source_ids_set = self._present_source_revisions_for(
502
 
                revision_ids, if_present_ids)
503
 
            # source_ids is the worst possible case we may need to pull.
504
 
            # now we want to filter source_ids against what we actually
505
 
            # have in target, but don't try to check for existence where we know
506
 
            # we do not have a revision as that would be pointless.
507
 
            target_ids = set(self.target.all_revision_ids())
508
 
            possibly_present_revisions = target_ids.intersection(
509
 
                source_ids_set)
510
 
            actually_present_revisions = set(
511
 
                self.target._eliminate_revisions_not_present(possibly_present_revisions))
512
 
            required_revisions = source_ids_set.difference(
513
 
                actually_present_revisions)
514
 
            if revision_ids is not None:
515
 
                # we used get_ancestry to determine source_ids then we are assured all
516
 
                # revisions referenced are present as they are installed in topological order.
517
 
                # and the tip revision was validated by get_ancestry.
518
 
                result_set = required_revisions
519
 
            else:
520
 
                # if we just grabbed the possibly available ids, then
521
 
                # we only have an estimate of whats available and need to validate
522
 
                # that against the revision records.
523
 
                result_set = set(
524
 
                    self.source._eliminate_revisions_not_present(required_revisions))
525
 
            if limit is not None:
526
 
                topo_ordered = self.source.get_graph().iter_topo_order(result_set)
527
 
                result_set = set(itertools.islice(topo_ordered, limit))
528
 
            return self.source.revision_ids_to_search_result(result_set)
 
494
        source_ids_set = self._present_source_revisions_for(
 
495
            revision_ids, if_present_ids)
 
496
        # source_ids is the worst possible case we may need to pull.
 
497
        # now we want to filter source_ids against what we actually
 
498
        # have in target, but don't try to check for existence where we know
 
499
        # we do not have a revision as that would be pointless.
 
500
        target_ids = set(self.target.all_revision_ids())
 
501
        possibly_present_revisions = target_ids.intersection(source_ids_set)
 
502
        actually_present_revisions = set(
 
503
            self.target._eliminate_revisions_not_present(possibly_present_revisions))
 
504
        required_revisions = source_ids_set.difference(actually_present_revisions)
 
505
        if revision_ids is not None:
 
506
            # we used get_ancestry to determine source_ids then we are assured all
 
507
            # revisions referenced are present as they are installed in topological order.
 
508
            # and the tip revision was validated by get_ancestry.
 
509
            result_set = required_revisions
 
510
        else:
 
511
            # if we just grabbed the possibly available ids, then
 
512
            # we only have an estimate of whats available and need to validate
 
513
            # that against the revision records.
 
514
            result_set = set(
 
515
                self.source._eliminate_revisions_not_present(required_revisions))
 
516
        if limit is not None:
 
517
            topo_ordered = self.source.get_graph().iter_topo_order(result_set)
 
518
            result_set = set(itertools.islice(topo_ordered, limit))
 
519
        return self.source.revision_ids_to_search_result(result_set)
529
520
 
530
521
 
531
522
InterRepository.register_optimiser(InterKnitRepo)