/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/repository.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2009-05-29 11:26:30 UTC
  • mfrom: (4343.3.39 1.15-gc-stacking)
  • Revision ID: pqm@pqm.ubuntu.com-20090529112630-p1bfpivkz3igjzn2
(jam) Fix bug #373455, allow --dev6 repos to stack.

Show diffs side-by-side

added added

removed removed

Lines of Context:
969
969
        """
970
970
        if not self._format.supports_external_lookups:
971
971
            raise errors.UnstackableRepositoryFormat(self._format, self.base)
 
972
        if self.is_locked():
 
973
            # This repository will call fallback.unlock() when we transition to
 
974
            # the unlocked state, so we make sure to increment the lock count
 
975
            repository.lock_read()
972
976
        self._check_fallback_repository(repository)
973
977
        self._fallback_repositories.append(repository)
974
978
        self.texts.add_fallback_versioned_files(repository.texts)
1240
1244
        """
1241
1245
        locked = self.is_locked()
1242
1246
        result = self.control_files.lock_write(token=token)
1243
 
        for repo in self._fallback_repositories:
1244
 
            # Writes don't affect fallback repos
1245
 
            repo.lock_read()
1246
1247
        if not locked:
 
1248
            for repo in self._fallback_repositories:
 
1249
                # Writes don't affect fallback repos
 
1250
                repo.lock_read()
1247
1251
            self._refresh_data()
1248
1252
        return result
1249
1253
 
1250
1254
    def lock_read(self):
1251
1255
        locked = self.is_locked()
1252
1256
        self.control_files.lock_read()
1253
 
        for repo in self._fallback_repositories:
1254
 
            repo.lock_read()
1255
1257
        if not locked:
 
1258
            for repo in self._fallback_repositories:
 
1259
                repo.lock_read()
1256
1260
            self._refresh_data()
1257
1261
 
1258
1262
    def get_physical_lock_status(self):
1424
1428
    def suspend_write_group(self):
1425
1429
        raise errors.UnsuspendableWriteGroup(self)
1426
1430
 
1427
 
    def get_missing_parent_inventories(self):
 
1431
    def get_missing_parent_inventories(self, check_for_missing_texts=True):
1428
1432
        """Return the keys of missing inventory parents for revisions added in
1429
1433
        this write group.
1430
1434
 
1439
1443
            return set()
1440
1444
        if not self.is_in_write_group():
1441
1445
            raise AssertionError('not in a write group')
1442
 
                
 
1446
 
1443
1447
        # XXX: We assume that every added revision already has its
1444
1448
        # corresponding inventory, so we only check for parent inventories that
1445
1449
        # might be missing, rather than all inventories.
1448
1452
        unstacked_inventories = self.inventories._index
1449
1453
        present_inventories = unstacked_inventories.get_parent_map(
1450
1454
            key[-1:] for key in parents)
1451
 
        if len(parents.difference(present_inventories)) == 0:
 
1455
        parents.difference_update(present_inventories)
 
1456
        if len(parents) == 0:
1452
1457
            # No missing parent inventories.
1453
1458
            return set()
 
1459
        if not check_for_missing_texts:
 
1460
            return set(('inventories', rev_id) for (rev_id,) in parents)
1454
1461
        # Ok, now we have a list of missing inventories.  But these only matter
1455
1462
        # if the inventories that reference them are missing some texts they
1456
1463
        # appear to introduce.
1577
1584
        self.control_files.unlock()
1578
1585
        if self.control_files._lock_count == 0:
1579
1586
            self._inventory_entry_cache.clear()
1580
 
        for repo in self._fallback_repositories:
1581
 
            repo.unlock()
 
1587
            for repo in self._fallback_repositories:
 
1588
                repo.unlock()
1582
1589
 
1583
1590
    @needs_read_lock
1584
1591
    def clone(self, a_bzrdir, revision_id=None):
4003
4010
        try:
4004
4011
            if resume_tokens:
4005
4012
                self.target_repo.resume_write_group(resume_tokens)
 
4013
                is_resume = True
4006
4014
            else:
4007
4015
                self.target_repo.start_write_group()
 
4016
                is_resume = False
4008
4017
            try:
4009
4018
                # locked_insert_stream performs a commit|suspend.
4010
 
                return self._locked_insert_stream(stream, src_format)
 
4019
                return self._locked_insert_stream(stream, src_format, is_resume)
4011
4020
            except:
4012
4021
                self.target_repo.abort_write_group(suppress_errors=True)
4013
4022
                raise
4014
4023
        finally:
4015
4024
            self.target_repo.unlock()
4016
4025
 
4017
 
    def _locked_insert_stream(self, stream, src_format):
 
4026
    def _locked_insert_stream(self, stream, src_format, is_resume):
4018
4027
        to_serializer = self.target_repo._format._serializer
4019
4028
        src_serializer = src_format._serializer
4020
4029
        new_pack = None
4070
4079
        if new_pack is not None:
4071
4080
            new_pack._write_data('', flush=True)
4072
4081
        # Find all the new revisions (including ones from resume_tokens)
4073
 
        missing_keys = self.target_repo.get_missing_parent_inventories()
 
4082
        missing_keys = self.target_repo.get_missing_parent_inventories(
 
4083
            check_for_missing_texts=is_resume)
4074
4084
        try:
4075
4085
            for prefix, versioned_file in (
4076
4086
                ('texts', self.target_repo.texts),
4077
4087
                ('inventories', self.target_repo.inventories),
4078
4088
                ('revisions', self.target_repo.revisions),
4079
4089
                ('signatures', self.target_repo.signatures),
 
4090
                ('chk_bytes', self.target_repo.chk_bytes),
4080
4091
                ):
 
4092
                if versioned_file is None:
 
4093
                    continue
4081
4094
                missing_keys.update((prefix,) + key for key in
4082
4095
                    versioned_file.get_missing_compression_parent_keys())
4083
4096
        except NotImplementedError:
4230
4243
        keys['texts'] = set()
4231
4244
        keys['revisions'] = set()
4232
4245
        keys['inventories'] = set()
 
4246
        keys['chk_bytes'] = set()
4233
4247
        keys['signatures'] = set()
4234
4248
        for key in missing_keys:
4235
4249
            keys[key[0]].add(key[1:])
4242
4256
                    keys['revisions'],))
4243
4257
        for substream_kind, keys in keys.iteritems():
4244
4258
            vf = getattr(self.from_repository, substream_kind)
 
4259
            if vf is None and keys:
 
4260
                    raise AssertionError(
 
4261
                        "cannot fill in keys for a versioned file we don't"
 
4262
                        " have: %s needs %s" % (substream_kind, keys))
 
4263
            if not keys:
 
4264
                # No need to stream something we don't have
 
4265
                continue
4245
4266
            # Ask for full texts always so that we don't need more round trips
4246
4267
            # after this stream.
4247
4268
            stream = vf.get_record_stream(keys,