~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/repository.py

  • Committer: John Arbash Meinel
  • Date: 2009-11-30 03:29:36 UTC
  • mto: This revision was merged to the branch mainline in revision 4835.
  • Revision ID: john@arbash-meinel.com-20091130032936-bla411rbg7c2ey4k
Factor out the common code into a helper so that smart streaming also benefits.

Show diffs side-by-side

added added

removed removed

Lines of Context:
26
26
    chk_map,
27
27
    debug,
28
28
    errors,
 
29
    fetch as _mod_fetch,
29
30
    fifo_cache,
30
31
    generate_ids,
31
32
    gpg,
38
39
    lru_cache,
39
40
    osutils,
40
41
    revision as _mod_revision,
41
 
    static_tuple,
42
42
    symbol_versioning,
43
43
    tsort,
44
44
    ui,
3413
3413
                   provided a default one will be created.
3414
3414
        :return: None.
3415
3415
        """
3416
 
        from bzrlib.fetch import RepoFetcher
3417
 
        f = RepoFetcher(to_repository=self.target,
 
3416
        f = _mod_fetch.RepoFetcher(to_repository=self.target,
3418
3417
                               from_repository=self.source,
3419
3418
                               last_revision=revision_id,
3420
3419
                               fetch_spec=fetch_spec,
3820
3819
                basis_id, delta, current_revision_id, parents_parents)
3821
3820
            cache[current_revision_id] = parent_tree
3822
3821
 
3823
 
    def _fetch_batch(self, revision_ids, basis_id, cache, graph=None):
 
3822
    def _fetch_batch(self, revision_ids, basis_id, cache, a_graph=None):
3824
3823
        """Fetch across a few revisions.
3825
3824
 
3826
3825
        :param revision_ids: The revisions to copy
3827
3826
        :param basis_id: The revision_id of a tree that must be in cache, used
3828
3827
            as a basis for delta when no other base is available
3829
3828
        :param cache: A cache of RevisionTrees that we can use.
 
3829
        :param a_graph: A Graph object to determine the heads() of the
 
3830
            rich-root data stream.
3830
3831
        :return: The revision_id of the last converted tree. The RevisionTree
3831
3832
            for it will be in cache
3832
3833
        """
3896
3897
        from_texts = self.source.texts
3897
3898
        to_texts = self.target.texts
3898
3899
        if root_keys_to_create:
3899
 
            from bzrlib.fetch import _new_root_data_stream
3900
 
            root_stream = _new_root_data_stream(
 
3900
            root_stream = _mod_fetch._new_root_data_stream(
3901
3901
                root_keys_to_create, self._revision_id_to_root_id, parent_map,
3902
 
                self.source, graph=graph)
 
3902
                self.source, graph=a_graph)
3903
3903
            to_texts.insert_record_stream(root_stream)
3904
3904
        to_texts.insert_record_stream(from_texts.get_record_stream(
3905
3905
            text_keys, self.target._format._fetch_order,
3962
3962
        cache[basis_id] = basis_tree
3963
3963
        del basis_tree # We don't want to hang on to it here
3964
3964
        hints = []
3965
 
        if self._converting_to_rich_root:
3966
 
            st = static_tuple.StaticTuple
3967
 
            revision_keys = [st(r_id).intern() for r_id in revision_ids]
3968
 
            known_graph = self.source.revisions.get_known_graph_ancestry(
3969
 
                            revision_keys)
3970
 
            class ThunkIdsToKeysHeads(object):
3971
 
                def __init__(self, kg):
3972
 
                    self.kg = kg
3973
 
                def heads(self, revision_ids):
3974
 
                    revision_keys = [(r,) for r in revision_ids]
3975
 
                    heads = self.kg.heads(revision_keys)
3976
 
                    return set([h[0] for h in heads])
3977
 
            graph = ThunkIdsToKeysHeads(known_graph)
 
3965
        if self._converting_to_rich_root and len(revision_ids) > 100:
 
3966
            a_graph = _mod_fetch._get_rich_root_heads_graph(self.source,
 
3967
                                                            revision_ids)
3978
3968
        else:
3979
 
            graph = None
 
3969
            a_graph = None
3980
3970
 
3981
3971
        for offset in range(0, len(revision_ids), batch_size):
3982
3972
            self.target.start_write_group()
3985
3975
                          len(revision_ids))
3986
3976
                batch = revision_ids[offset:offset+batch_size]
3987
3977
                basis_id = self._fetch_batch(batch, basis_id, cache,
3988
 
                                             graph=graph)
 
3978
                                             a_graph=the_graph)
3989
3979
            except:
3990
3980
                self.target.abort_write_group()
3991
3981
                raise
4464
4454
        fetching the inventory weave.
4465
4455
        """
4466
4456
        if self._rich_root_upgrade():
4467
 
            import bzrlib.fetch
4468
 
            return bzrlib.fetch.Inter1and2Helper(
 
4457
            return _mod_fetch.Inter1and2Helper(
4469
4458
                self.from_repository).generate_root_texts(revs)
4470
4459
        else:
4471
4460
            return []