/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: Andrew Bennetts
  • Date: 2009-07-15 06:39:26 UTC
  • mto: (4476.3.44 inventory-delta)
  • mto: This revision was merged to the branch mainline in revision 4608.
  • Revision ID: andrew.bennetts@canonical.com-20090715063926-9ccc4llj7bsjifdh
Fix trivial bug in xml5 error path.

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
 
# Copyright (C) 2005-2010 Canonical Ltd
 
1
# Copyright (C) 2005, 2006, 2008, 2009 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
35
35
import bzrlib
36
36
from bzrlib import (
37
37
    errors,
38
 
    ui,
 
38
    symbol_versioning,
39
39
    )
40
40
from bzrlib.revision import NULL_REVISION
41
41
from bzrlib.trace import mutter
 
42
import bzrlib.ui
42
43
 
43
44
 
44
45
class RepoFetcher(object):
49
50
    """
50
51
 
51
52
    def __init__(self, to_repository, from_repository, last_revision=None,
52
 
        find_ghosts=True, fetch_spec=None):
 
53
        pb=None, find_ghosts=True, fetch_spec=None):
53
54
        """Create a repo fetcher.
54
55
 
55
56
        :param last_revision: If set, try to limit to the data this revision
56
57
            references.
57
58
        :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.
58
61
        """
59
 
        # repository.fetch has the responsibility for short-circuiting
60
 
        # attempts to copy between a repository and itself.
 
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
        if to_repository.has_same_location(from_repository):
 
68
            # repository.fetch should be taking care of this case.
 
69
            raise errors.BzrError('RepoFetcher run '
 
70
                    'between two objects at the same location: '
 
71
                    '%r and %r' % (to_repository, from_repository))
61
72
        self.to_repository = to_repository
62
73
        self.from_repository = from_repository
63
74
        self.sink = to_repository._get_sink()
88
99
        # assert not missing
89
100
        self.count_total = 0
90
101
        self.file_ids_names = {}
91
 
        pb = ui.ui_factory.nested_progress_bar()
 
102
        pb = bzrlib.ui.ui_factory.nested_progress_bar()
92
103
        pb.show_pct = pb.show_count = False
93
104
        try:
94
105
            pb.update("Finding revisions", 0, 2)
115
126
            raise errors.IncompatibleRepositories(
116
127
                self.from_repository, self.to_repository,
117
128
                "different rich-root support")
118
 
        pb = ui.ui_factory.nested_progress_bar()
 
129
        pb = bzrlib.ui.ui_factory.nested_progress_bar()
119
130
        try:
120
131
            pb.update("Get stream source")
121
132
            source = self.from_repository._get_source(
243
254
        # yet, and are unlikely to in non-rich-root environments anyway.
244
255
        root_id_order.sort(key=operator.itemgetter(0))
245
256
        # Create a record stream containing the roots to create.
246
 
        if len(revs) > 100:
247
 
            # XXX: not covered by tests, should have a flag to always run
248
 
            # this. -- mbp 20100129
249
 
            graph = self.source_repo.get_known_graph_ancestry(revs)
250
257
        new_roots_stream = _new_root_data_stream(
251
 
            root_id_order, rev_id_to_root_id, parent_map, self.source, graph)
 
258
            root_id_order, rev_id_to_root_id, parent_map, self.source)
252
259
        return [('texts', new_roots_stream)]
253
260
 
254
261
 
255
 
def _get_rich_root_heads_graph(source_repo, revision_ids):
256
 
    """Get a Graph object suitable for asking heads() for new rich roots."""
257
 
    return 
258
 
 
259
 
 
260
262
def _new_root_data_stream(
261
 
    root_keys_to_create, rev_id_to_root_id_map, parent_map, repo, graph=None):
262
 
    """Generate a texts substream of synthesised root entries.
263
 
 
264
 
    Used in fetches that do rich-root upgrades.
265
 
    
266
 
    :param root_keys_to_create: iterable of (root_id, rev_id) pairs describing
267
 
        the root entries to create.
268
 
    :param rev_id_to_root_id_map: dict of known rev_id -> root_id mappings for
269
 
        calculating the parents.  If a parent rev_id is not found here then it
270
 
        will be recalculated.
271
 
    :param parent_map: a parent map for all the revisions in
272
 
        root_keys_to_create.
273
 
    :param graph: a graph to use instead of repo.get_graph().
274
 
    """
 
263
    root_keys_to_create, rev_id_to_root_id_map, parent_map, repo):
275
264
    for root_key in root_keys_to_create:
276
265
        root_id, rev_id = root_key
277
266
        parent_keys = _parent_keys_for_root_version(
278
 
            root_id, rev_id, rev_id_to_root_id_map, parent_map, repo, graph)
 
267
            root_id, rev_id, rev_id_to_root_id_map, parent_map, repo)
279
268
        yield versionedfile.FulltextContentFactory(
280
269
            root_key, parent_keys, None, '')
281
270
 
282
271
 
283
272
def _parent_keys_for_root_version(
284
 
    root_id, rev_id, rev_id_to_root_id_map, parent_map, repo, graph=None):
285
 
    """Get the parent keys for a given root id.
286
 
    
287
 
    A helper function for _new_root_data_stream.
288
 
    """
 
273
    root_id, rev_id, rev_id_to_root_id_map, parent_map, repo):
 
274
    """Get the parent keys for a given root id."""
289
275
    # Include direct parents of the revision, but only if they used the same
290
276
    # root_id and are heads.
291
277
    rev_parents = parent_map[rev_id]
331
317
                    # not in the tree
332
318
                    pass
333
319
    # Drop non-head parents
334
 
    if graph is None:
335
 
        graph = repo.get_graph()
336
 
    heads = graph.heads(parent_ids)
 
320
    heads = repo.get_graph().heads(parent_ids)
337
321
    selected_ids = []
338
322
    for parent_id in parent_ids:
339
323
        if parent_id in heads and parent_id not in selected_ids: