~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/fetch.py

  • Committer: Andrew Bennetts
  • Date: 2010-02-12 04:33:05 UTC
  • mfrom: (5031 +trunk)
  • mto: This revision was merged to the branch mainline in revision 5032.
  • Revision ID: andrew.bennetts@canonical.com-20100212043305-ujdbsdoviql2t7i3
MergeĀ lp:bzr

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005, 2006, 2008, 2009 Canonical Ltd
 
1
# Copyright (C) 2005-2010 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
28
28
from bzrlib.lazy_import import lazy_import
29
29
lazy_import(globals(), """
30
30
from bzrlib import (
 
31
    graph as _mod_graph,
 
32
    static_tuple,
31
33
    tsort,
32
34
    versionedfile,
33
35
    )
36
38
from bzrlib import (
37
39
    errors,
38
40
    symbol_versioning,
 
41
    ui,
39
42
    )
40
43
from bzrlib.revision import NULL_REVISION
41
44
from bzrlib.trace import mutter
42
 
import bzrlib.ui
43
45
 
44
46
 
45
47
class RepoFetcher(object):
50
52
    """
51
53
 
52
54
    def __init__(self, to_repository, from_repository, last_revision=None,
53
 
        pb=None, find_ghosts=True, fetch_spec=None):
 
55
        find_ghosts=True, fetch_spec=None):
54
56
        """Create a repo fetcher.
55
57
 
56
58
        :param last_revision: If set, try to limit to the data this revision
57
59
            references.
58
60
        :param find_ghosts: If True search the entire history for ghosts.
59
 
        :param pb: ProgressBar object to use; deprecated and ignored.
60
 
            This method will just create one on top of the stack.
61
61
        """
62
 
        if pb is not None:
63
 
            symbol_versioning.warn(
64
 
                symbol_versioning.deprecated_in((1, 14, 0))
65
 
                % "pb parameter to RepoFetcher.__init__")
66
 
            # and for simplicity it is in fact ignored
67
62
        # repository.fetch has the responsibility for short-circuiting
68
63
        # attempts to copy between a repository and itself.
69
64
        self.to_repository = to_repository
96
91
        # assert not missing
97
92
        self.count_total = 0
98
93
        self.file_ids_names = {}
99
 
        pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
94
        pb = ui.ui_factory.nested_progress_bar()
100
95
        pb.show_pct = pb.show_count = False
101
96
        try:
102
97
            pb.update("Finding revisions", 0, 2)
123
118
            raise errors.IncompatibleRepositories(
124
119
                self.from_repository, self.to_repository,
125
120
                "different rich-root support")
126
 
        pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
121
        pb = ui.ui_factory.nested_progress_bar()
127
122
        try:
128
123
            pb.update("Get stream source")
129
124
            source = self.from_repository._get_source(
251
246
        # yet, and are unlikely to in non-rich-root environments anyway.
252
247
        root_id_order.sort(key=operator.itemgetter(0))
253
248
        # Create a record stream containing the roots to create.
254
 
        from bzrlib.graph import FrozenHeadsCache
255
 
        graph = FrozenHeadsCache(graph)
 
249
        if len(revs) > 100:
 
250
            # XXX: not covered by tests, should have a flag to always run
 
251
            # this. -- mbp 20100129
 
252
            graph = _get_rich_root_heads_graph(self.source, revs)
256
253
        new_roots_stream = _new_root_data_stream(
257
254
            root_id_order, rev_id_to_root_id, parent_map, self.source, graph)
258
255
        return [('texts', new_roots_stream)]
259
256
 
260
257
 
 
258
def _get_rich_root_heads_graph(source_repo, revision_ids):
 
259
    """Get a Graph object suitable for asking heads() for new rich roots."""
 
260
    st = static_tuple.StaticTuple
 
261
    revision_keys = [st(r_id).intern() for r_id in revision_ids]
 
262
    known_graph = source_repo.revisions.get_known_graph_ancestry(
 
263
                    revision_keys)
 
264
    return _mod_graph.GraphThunkIdsToKeys(known_graph)
 
265
 
 
266
 
261
267
def _new_root_data_stream(
262
268
    root_keys_to_create, rev_id_to_root_id_map, parent_map, repo, graph=None):
263
269
    """Generate a texts substream of synthesised root entries.