~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/fetch.py

  • Committer: Aaron Bentley
  • Date: 2008-02-24 16:42:13 UTC
  • mfrom: (3234 +trunk)
  • mto: This revision was merged to the branch mainline in revision 3235.
  • Revision ID: aaron@aaronbentley.com-20080224164213-eza1lzru5bwuwmmj
Merge with bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
33
33
 
34
34
import bzrlib
35
35
import bzrlib.errors as errors
36
 
from bzrlib.errors import (InstallFailed,
37
 
                           )
 
36
from bzrlib.errors import InstallFailed
38
37
from bzrlib.progress import ProgressPhase
39
38
from bzrlib.revision import is_null, NULL_REVISION
40
39
from bzrlib.symbol_versioning import (deprecated_function,
75
74
    This should not be used directly, it's essential a object to encapsulate
76
75
    the logic in InterRepository.fetch().
77
76
    """
78
 
    def __init__(self, to_repository, from_repository, last_revision=None, pb=None):
 
77
 
 
78
    def __init__(self, to_repository, from_repository, last_revision=None, pb=None,
 
79
        find_ghosts=True):
 
80
        """Create a repo fetcher.
 
81
 
 
82
        :param find_ghosts: If True search the entire history for ghosts.
 
83
        """
79
84
        # result variables.
80
85
        self.failed_revisions = []
81
86
        self.count_copied = 0
88
93
        self.from_repository = from_repository
89
94
        # must not mutate self._last_revision as its potentially a shared instance
90
95
        self._last_revision = last_revision
 
96
        self.find_ghosts = find_ghosts
91
97
        if pb is None:
92
98
            self.pb = bzrlib.ui.ui_factory.nested_progress_bar()
93
99
            self.nested_pb = self.pb
126
132
        pp = ProgressPhase('Transferring', 4, self.pb)
127
133
        try:
128
134
            pp.next_phase()
129
 
            revs = self._revids_to_fetch()
130
 
            if revs is None:
 
135
            search = self._revids_to_fetch()
 
136
            if search is None:
131
137
                return
132
 
            self._fetch_everything_for_revisions(revs, pp)
 
138
            if getattr(self, '_fetch_everything_for_search', None) is not None:
 
139
                self._fetch_everything_for_search(search, pp)
 
140
            else:
 
141
                # backward compatibility
 
142
                self._fetch_everything_for_revisions(search.get_keys, pp)
133
143
        finally:
134
144
            self.pb.clear()
135
145
 
136
 
    def _fetch_everything_for_revisions(self, revs, pp):
 
146
    def _fetch_everything_for_search(self, search, pp):
137
147
        """Fetch all data for the given set of revisions."""
138
148
        # The first phase is "file".  We pass the progress bar for it directly
139
149
        # into item_keys_introduced_by, which has more information about how
146
156
        phase = 'file'
147
157
        pb = bzrlib.ui.ui_factory.nested_progress_bar()
148
158
        try:
 
159
            revs = search.get_keys()
149
160
            data_to_fetch = self.from_repository.item_keys_introduced_by(revs, pb)
150
161
            for knit_kind, file_id, revisions in data_to_fetch:
151
162
                if knit_kind != phase:
191
202
        if (self._last_revision is not None and
192
203
            self.to_repository.has_revision(self._last_revision)):
193
204
            return None
194
 
            
195
205
        try:
196
 
            # XXX: this gets the full graph on both sides, and will make sure
197
 
            # that ghosts are filled whether or not you care about them.
198
 
            return self.to_repository.missing_revision_ids(self.from_repository,
199
 
                                                           self._last_revision)
 
206
            return self.to_repository.search_missing_revision_ids(
 
207
                self.from_repository, self._last_revision,
 
208
                find_ghosts=self.find_ghosts)
200
209
        except errors.NoSuchRevision:
201
210
            raise InstallFailed([self._last_revision])
202
211
 
329
338
 
330
339
        :param revs: A list of revision ids
331
340
        """
 
341
        # In case that revs is not a list.
 
342
        revs = list(revs)
332
343
        while revs:
333
344
            for tree in self.source.revision_trees(revs[:100]):
334
345
                if tree.inventory.revision_id is None:
362
373
        stored in the target (reserializing it in a different format).
363
374
        :param revs: The revisions to include
364
375
        """
365
 
        inventory_weave = self.source.get_inventory_weave()
366
376
        for tree in self.iter_rev_trees(revs):
367
 
            parents = inventory_weave.get_parents(tree.get_revision_id())
 
377
            parents = tree.get_parent_ids()
368
378
            self.target.add_inventory(tree.get_revision_id(), tree.inventory,
369
379
                                      parents)
370
380
 
372
382
class Model1toKnit2Fetcher(GenericRepoFetcher):
373
383
    """Fetch from a Model1 repository into a Knit2 repository
374
384
    """
375
 
    def __init__(self, to_repository, from_repository, last_revision=None, 
376
 
                 pb=None):
 
385
    def __init__(self, to_repository, from_repository, last_revision=None,
 
386
                 pb=None, find_ghosts=True):
377
387
        self.helper = Inter1and2Helper(from_repository, to_repository)
378
388
        GenericRepoFetcher.__init__(self, to_repository, from_repository,
379
 
                                    last_revision, pb)
 
389
            last_revision, pb, find_ghosts)
380
390
 
381
391
    def _generate_root_texts(self, revs):
382
392
        self.helper.generate_root_texts(revs)
389
399
    """Fetch from a Knit1 repository into a Knit2 repository"""
390
400
 
391
401
    def __init__(self, to_repository, from_repository, last_revision=None, 
392
 
                 pb=None):
 
402
                 pb=None, find_ghosts=True):
393
403
        self.helper = Inter1and2Helper(from_repository, to_repository)
394
404
        KnitRepoFetcher.__init__(self, to_repository, from_repository,
395
 
                                 last_revision, pb)
 
405
            last_revision, pb, find_ghosts)
396
406
 
397
407
    def _generate_root_texts(self, revs):
398
408
        self.helper.generate_root_texts(revs)
403
413
 
404
414
class RemoteToOtherFetcher(GenericRepoFetcher):
405
415
 
406
 
    def _fetch_everything_for_revisions(self, revs, pp):
407
 
        data_stream = self.from_repository.get_data_stream(revs)
 
416
    def _fetch_everything_for_search(self, search, pp):
 
417
        data_stream = self.from_repository.get_data_stream_for_search(search)
408
418
        self.to_repository.insert_data_stream(data_stream)
409
419
 
410
420