~ubuntu-branches/ubuntu/karmic/bzr/karmic-proposed

« back to all changes in this revision

Viewing changes to bzrlib/repository.py

  • Committer: Bazaar Package Importer
  • Author(s): Jelmer Vernooij
  • Date: 2008-05-12 00:14:54 UTC
  • mfrom: (1.1.42 upstream)
  • Revision ID: james.westby@ubuntu.com-20080512001454-yjpajuiocykl48p9
Tags: 1.5~rc1-1
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
95
95
        if committer is None:
96
96
            self._committer = self._config.username()
97
97
        else:
98
 
            assert isinstance(committer, basestring), type(committer)
99
98
            self._committer = committer
100
99
 
101
100
        self.new_inventory = Inventory(None)
328
327
            if kind != parent_entry.kind:
329
328
                store = True
330
329
        if kind == 'file':
331
 
            assert content_summary[2] is not None, \
332
 
                "Files must not have executable = None"
 
330
            if content_summary[2] is None:
 
331
                raise ValueError("Files must not have executable = None")
333
332
            if not store:
334
333
                if (# if the file length changed we have to store:
335
334
                    parent_entry.text_size != content_summary[1] or
501
500
        :returns: The validator(which is a sha1 digest, though what is sha'd is
502
501
            repository format specific) of the serialized inventory.
503
502
        """
504
 
        assert self.is_in_write_group()
 
503
        if not self.is_in_write_group():
 
504
            raise AssertionError("%r not in write group" % (self,))
505
505
        _mod_revision.check_not_reserved_id(revision_id)
506
 
        assert inv.revision_id is None or inv.revision_id == revision_id, \
507
 
            "Mismatch between inventory revision" \
508
 
            " id and insertion revid (%r, %r)" % (inv.revision_id, revision_id)
509
 
        assert inv.root is not None
 
506
        if not (inv.revision_id is None or inv.revision_id == revision_id):
 
507
            raise AssertionError(
 
508
                "Mismatch between inventory revision"
 
509
                " id and insertion revid (%r, %r)"
 
510
                % (inv.revision_id, revision_id))
 
511
        if inv.root is None:
 
512
            raise AssertionError()
510
513
        inv_lines = self._serialise_inventory_to_lines(inv)
511
514
        inv_vf = self.get_inventory_weave()
512
515
        return self._inventory_add_lines(inv_vf, revision_id, parents,
542
545
            plaintext = Testament(rev, inv).as_short_text()
543
546
            self.store_revision_signature(
544
547
                gpg.GPGStrategy(config), plaintext, revision_id)
545
 
        if not revision_id in self.get_inventory_weave():
 
548
        inventory_vf = self.get_inventory_weave()
 
549
        if not revision_id in inventory_vf:
546
550
            if inv is None:
547
551
                raise errors.WeaveRevisionNotPresent(revision_id,
548
 
                                                     self.get_inventory_weave())
 
552
                                                     inventory_vf)
549
553
            else:
550
554
                # yes, this is not suitable for adding with ghosts.
551
 
                rev.inventory_sha1 = self.add_inventory(revision_id, inv, 
 
555
                rev.inventory_sha1 = self.add_inventory(revision_id, inv,
552
556
                                                        rev.parent_ids)
 
557
        else:
 
558
            rev.inventory_sha1 = inventory_vf.get_sha1s([revision_id])[0]
553
559
        self._revision_store.add_revision(rev, self.get_transaction())
554
560
 
555
561
    def _add_revision_text(self, revision_id, text):
1092
1098
                raise errors.InvalidRevisionId(revision_id=rev_id, branch=self)
1093
1099
        revs = self._revision_store.get_revisions(revision_ids,
1094
1100
                                                  self.get_transaction())
1095
 
        for rev in revs:
1096
 
            assert not isinstance(rev.revision_id, unicode)
1097
 
            for parent_id in rev.parent_ids:
1098
 
                assert not isinstance(parent_id, unicode)
1099
1101
        return revs
1100
1102
 
1101
1103
    @needs_read_lock
1110
1112
        rev_tmp.seek(0)
1111
1113
        return rev_tmp.getvalue()
1112
1114
 
1113
 
    @needs_read_lock
1114
1115
    def get_deltas_for_revisions(self, revisions):
1115
1116
        """Produce a generator of revision deltas.
1116
1117
        
1445
1446
        # maybe this generator should explicitly have the contract that it
1446
1447
        # should not be iterated until the previously yielded item has been
1447
1448
        # processed?
1448
 
        self.lock_read()
1449
1449
        inv_w = self.get_inventory_weave()
1450
1450
 
1451
1451
        # file ids that changed
1474
1474
                pass
1475
1475
            else:
1476
1476
                revisions_with_signatures.add(rev_id)
1477
 
        self.unlock()
1478
1477
        yield ("signatures", None, revisions_with_signatures)
1479
1478
 
1480
1479
        # revisions
1499
1498
 
1500
1499
        :return: An iterator of inventories.
1501
1500
        """
1502
 
        assert None not in revision_ids
1503
 
        assert _mod_revision.NULL_REVISION not in revision_ids
 
1501
        if ((None in revision_ids)
 
1502
            or (_mod_revision.NULL_REVISION in revision_ids)):
 
1503
            raise ValueError('cannot get null revision inventory')
1504
1504
        return self._iter_inventories(revision_ids)
1505
1505
 
1506
1506
    def _iter_inventories(self, revision_ids):
1534
1534
    def get_inventory_xml(self, revision_id):
1535
1535
        """Get inventory XML as a file object."""
1536
1536
        try:
1537
 
            assert isinstance(revision_id, str), type(revision_id)
1538
1537
            iw = self.get_inventory_weave()
1539
1538
            return iw.get_text(revision_id)
1540
1539
        except IndexError:
1680
1679
            inv = self.get_revision_inventory(revision_id)
1681
1680
            return RevisionTree(self, inv, revision_id)
1682
1681
 
1683
 
    @needs_read_lock
1684
1682
    def revision_trees(self, revision_ids):
1685
1683
        """Return Tree for a revision on this branch.
1686
1684
 
1739
1737
    def get_transaction(self):
1740
1738
        return self.control_files.get_transaction()
1741
1739
 
 
1740
    @deprecated_method(symbol_versioning.one_five)
1742
1741
    def revision_parents(self, revision_id):
1743
1742
        return self.get_inventory_weave().parent_names(revision_id)
1744
1743
 
2382
2381
        :param revision_ids: The start point for the search.
2383
2382
        :return: A set of revision ids.
2384
2383
        """
2385
 
        graph = self.source.get_graph()
 
2384
        target_graph = self.target.get_graph()
 
2385
        revision_ids = frozenset(revision_ids)
 
2386
        if set(target_graph.get_parent_map(revision_ids)) == revision_ids:
 
2387
            return graph.SearchResult(revision_ids, set(), 0, set())
2386
2388
        missing_revs = set()
 
2389
        source_graph = self.source.get_graph()
2387
2390
        # ensure we don't pay silly lookup costs.
2388
 
        revision_ids = frozenset(revision_ids)
2389
 
        searcher = graph._make_breadth_first_searcher(revision_ids)
 
2391
        searcher = source_graph._make_breadth_first_searcher(revision_ids)
2390
2392
        null_set = frozenset([_mod_revision.NULL_REVISION])
2391
2393
        while True:
2392
2394
            try:
2397
2399
                absent_ids = set(revision_ids.intersection(ghosts))
2398
2400
                # If all absent_ids are present in target, no error is needed.
2399
2401
                absent_ids.difference_update(
2400
 
                    self.target.has_revisions(absent_ids))
 
2402
                    set(target_graph.get_parent_map(absent_ids)))
2401
2403
                if absent_ids:
2402
2404
                    raise errors.NoSuchRevision(self.source, absent_ids.pop())
2403
2405
            # we don't care about other ghosts as we can't fetch them and
2404
2406
            # haven't been asked to.
2405
2407
            next_revs = set(next_revs)
2406
2408
            # we always have NULL_REVISION present.
2407
 
            have_revs = self.target.has_revisions(next_revs).union(null_set)
 
2409
            have_revs = set(target_graph.get_parent_map(next_revs)).union(null_set)
2408
2410
            missing_revs.update(next_revs - have_revs)
2409
2411
            searcher.stop_searching_any(have_revs)
2410
2412
        return searcher.get_result()
2441
2443
        target_ids = set(self.target.all_revision_ids())
2442
2444
        if revision_id is not None:
2443
2445
            source_ids = self.source.get_ancestry(revision_id)
2444
 
            assert source_ids[0] is None
 
2446
            if source_ids[0] is not None:
 
2447
                raise AssertionError()
2445
2448
            source_ids.pop(0)
2446
2449
        else:
2447
2450
            source_ids = self.source.all_revision_ids()
2608
2611
        # - RBC 20060209
2609
2612
        if revision_id is not None:
2610
2613
            source_ids = self.source.get_ancestry(revision_id)
2611
 
            assert source_ids[0] is None
 
2614
            if source_ids[0] is not None:
 
2615
                raise AssertionError()
2612
2616
            source_ids.pop(0)
2613
2617
        else:
2614
2618
            source_ids = self.source._all_possible_ids()
2677
2681
        """See InterRepository.missing_revision_ids()."""
2678
2682
        if revision_id is not None:
2679
2683
            source_ids = self.source.get_ancestry(revision_id)
2680
 
            assert source_ids[0] is None
 
2684
            if source_ids[0] is not None:
 
2685
                raise AssertionError()
2681
2686
            source_ids.pop(0)
2682
2687
        else:
2683
2688
            source_ids = self.source.all_revision_ids()
2743
2748
            # inventory parsing etc, IFF nothing to be copied is in the target.
2744
2749
            # till then:
2745
2750
            revision_ids = self.source.all_revision_ids()
 
2751
            revision_keys = [(revid,) for revid in revision_ids]
 
2752
            index = self.target._pack_collection.revision_index.combined_index
 
2753
            present_revision_ids = set(item[1][0] for item in
 
2754
                index.iter_entries(revision_keys))
 
2755
            revision_ids = set(revision_ids) - present_revision_ids
2746
2756
            # implementing the TODO will involve:
2747
2757
            # - detecting when all of a pack is selected
2748
2758
            # - avoiding as much as possible pre-selection, so the
2759
2769
                    find_ghosts=find_ghosts).get_keys()
2760
2770
            except errors.NoSuchRevision:
2761
2771
                raise errors.InstallFailed([revision_id])
 
2772
            if len(revision_ids) == 0:
 
2773
                return (0, [])
2762
2774
        packs = self.source._pack_collection.all_packs()
2763
2775
        pack = Packer(self.target._pack_collection, packs, '.fetch',
2764
2776
            revision_ids).pack()
2783
2795
            return self._walk_to_common_revisions([revision_id])
2784
2796
        elif revision_id is not None:
2785
2797
            source_ids = self.source.get_ancestry(revision_id)
2786
 
            assert source_ids[0] is None
 
2798
            if source_ids[0] is not None:
 
2799
                raise AssertionError()
2787
2800
            source_ids.pop(0)
2788
2801
        else:
2789
2802
            source_ids = self.source.all_revision_ids()
2950
2963
        # Is source's model compatible with target's model?
2951
2964
        source._ensure_real()
2952
2965
        real_source = source._real_repository
2953
 
        assert not isinstance(real_source, remote.RemoteRepository), (
2954
 
            "We don't support remote repos backed by remote repos yet.")
 
2966
        if isinstance(real_source, remote.RemoteRepository):
 
2967
            raise NotImplementedError(
 
2968
                "We don't support remote repos backed by remote repos yet.")
2955
2969
        return InterRepository._same_model(real_source, target)
2956
2970
 
2957
2971
    @needs_write_lock