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

  • Committer: John Arbash Meinel
  • Date: 2011-04-20 09:46:28 UTC
  • mfrom: (5609.33.4 2.3)
  • mto: (5609.33.5 2.3)
  • mto: This revision was merged to the branch mainline in revision 5811.
  • Revision ID: john@arbash-meinel.com-20110420094628-l0bafq1lwb6ib1v2
Merge lp:bzr/2.3 @ 5640 so we can update the release notes (aka NEWS)

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005-2011 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,
33
31
    tsort,
34
32
    versionedfile,
35
33
    )
37
35
import bzrlib
38
36
from bzrlib import (
39
37
    errors,
40
 
    symbol_versioning,
41
38
    ui,
42
39
    )
43
40
from bzrlib.revision import NULL_REVISION
52
49
    """
53
50
 
54
51
    def __init__(self, to_repository, from_repository, last_revision=None,
55
 
        pb=None, find_ghosts=True, fetch_spec=None):
 
52
        find_ghosts=True, fetch_spec=None):
56
53
        """Create a repo fetcher.
57
54
 
58
55
        :param last_revision: If set, try to limit to the data this revision
59
56
            references.
60
57
        :param find_ghosts: If True search the entire history for ghosts.
61
 
        :param pb: ProgressBar object to use; deprecated and ignored.
62
 
            This method will just create one on top of the stack.
63
58
        """
64
 
        if pb is not None:
65
 
            symbol_versioning.warn(
66
 
                symbol_versioning.deprecated_in((1, 14, 0))
67
 
                % "pb parameter to RepoFetcher.__init__")
68
 
            # and for simplicity it is in fact ignored
69
59
        # repository.fetch has the responsibility for short-circuiting
70
60
        # attempts to copy between a repository and itself.
71
61
        self.to_repository = to_repository
135
125
            pb.update("Inserting stream")
136
126
            resume_tokens, missing_keys = self.sink.insert_stream(
137
127
                stream, from_format, [])
138
 
            if self.to_repository._fallback_repositories:
139
 
                missing_keys.update(
140
 
                    self._parent_inventories(search.get_keys()))
141
128
            if missing_keys:
142
129
                pb.update("Missing keys")
143
130
                stream = source.get_stream_for_missing_keys(missing_keys)
173
160
            self.from_repository, self._last_revision,
174
161
            find_ghosts=self.find_ghosts)
175
162
 
176
 
    def _parent_inventories(self, revision_ids):
177
 
        # Find all the parent revisions referenced by the stream, but
178
 
        # not present in the stream, and make sure we send their
179
 
        # inventories.
180
 
        parent_maps = self.to_repository.get_parent_map(revision_ids)
181
 
        parents = set()
182
 
        map(parents.update, parent_maps.itervalues())
183
 
        parents.discard(NULL_REVISION)
184
 
        parents.difference_update(revision_ids)
185
 
        missing_keys = set(('inventories', rev_id) for rev_id in parents)
186
 
        return missing_keys
187
 
 
188
163
 
189
164
class Inter1and2Helper(object):
190
165
    """Helper for operations that convert data from model 1 and 2
192
167
    This is for use by fetchers and converters.
193
168
    """
194
169
 
 
170
    # This is a class variable so that the test suite can override it.
 
171
    known_graph_threshold = 100
 
172
 
195
173
    def __init__(self, source):
196
174
        """Constructor.
197
175
 
253
231
        # yet, and are unlikely to in non-rich-root environments anyway.
254
232
        root_id_order.sort(key=operator.itemgetter(0))
255
233
        # Create a record stream containing the roots to create.
256
 
        if len(revs) > 100:
257
 
            # XXX: not covered by tests, should have a flag to always run
258
 
            # this. -- mbp 20100129
259
 
            graph = _get_rich_root_heads_graph(self.source, revs)
 
234
        if len(revs) > self.known_graph_threshold:
 
235
            graph = self.source.get_known_graph_ancestry(revs)
260
236
        new_roots_stream = _new_root_data_stream(
261
237
            root_id_order, rev_id_to_root_id, parent_map, self.source, graph)
262
238
        return [('texts', new_roots_stream)]
263
239
 
264
240
 
265
 
def _get_rich_root_heads_graph(source_repo, revision_ids):
266
 
    """Get a Graph object suitable for asking heads() for new rich roots."""
267
 
    st = static_tuple.StaticTuple
268
 
    revision_keys = [st(r_id).intern() for r_id in revision_ids]
269
 
    known_graph = source_repo.revisions.get_known_graph_ancestry(
270
 
                    revision_keys)
271
 
    return _mod_graph.GraphThunkIdsToKeys(known_graph)
272
 
 
273
 
 
274
241
def _new_root_data_stream(
275
242
    root_keys_to_create, rev_id_to_root_id_map, parent_map, repo, graph=None):
276
243
    """Generate a texts substream of synthesised root entries.