~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/fetch.py

Deprecate direct use of fetch.Fetcher.

Show diffs side-by-side

added added

removed removed

Lines of Context:
60
60
 
61
61
@deprecated_function(zero_eight)
62
62
def greedy_fetch(to_branch, from_branch, revision=None, pb=None):
63
 
    """Legacy operation, see branch.fetch(from_branch, last_revision, pb)."""
 
63
    """Legacy API, please see branch.fetch(from_branch, last_revision, pb)."""
64
64
    f = Fetcher(to_branch, from_branch, revision, pb)
65
65
    return f.count_copied, f.failed_revisions
66
66
 
 
67
fetch = greedy_fetch
 
68
 
67
69
 
68
70
class RepoFetcher(object):
69
71
    """Pull revisions and texts from one repository to another.
198
200
 
199
201
 
200
202
class Fetcher(object):
201
 
    """Pull revisions and texts from one branch to another.
202
 
 
203
 
    This doesn't update the destination's history; that can be done
204
 
    separately if desired.  
205
 
 
206
 
    revision_limit
207
 
        If set, pull only up to this revision_id.
208
 
 
209
 
    After running:
210
 
 
211
 
    last_revision -- if last_revision
212
 
        is given it will be that, otherwise the last revision of
213
 
        from_branch
214
 
 
215
 
    count_copied -- number of revisions copied
216
 
    """
 
203
    """Backwards compatability glue for branch.fetch()."""
 
204
 
 
205
    @deprecated_method(zero_eight)
217
206
    def __init__(self, to_branch, from_branch, last_revision=None, pb=None):
218
 
        if to_branch.base == from_branch.base:
219
 
            raise Exception("can't fetch from a branch to itself %s, %s" % 
220
 
                            (from_branch.base, to_branch.base))
221
 
        
222
 
        self.to_branch = to_branch
223
 
        self.from_branch = from_branch
224
 
        self._last_revision = last_revision
225
 
        if pb is None:
226
 
            self.pb = bzrlib.ui.ui_factory.progress_bar()
227
 
        else:
228
 
            self.pb = pb
229
 
        self.from_branch.lock_read()
230
 
        try:
231
 
            self.to_branch.lock_write()
232
 
            try:
233
 
                self.__fetch()
234
 
            finally:
235
 
                self.to_branch.unlock()
236
 
        finally:
237
 
            self.from_branch.unlock()
238
 
 
239
 
    def __fetch(self):
240
 
        self._find_last_revision()
241
 
        repo_fetcher = RepoFetcher(to_repository=self.to_branch.repository,
242
 
                                   from_repository=self.from_branch.repository,
243
 
                                   pb=self.pb,
244
 
                                   last_revision=self._last_revision)
245
 
        self.failed_revisions = repo_fetcher.failed_revisions
246
 
        self.count_copied = repo_fetcher.count_copied
247
 
        self.count_total = repo_fetcher.count_total
248
 
 
249
 
    def _find_last_revision(self):
250
 
        """Find the limiting source revision.
251
 
 
252
 
        Every ancestor of that revision will be merged across.
253
 
 
254
 
        Returns the revision_id, or returns None if there's no history
255
 
        in the source branch."""
256
 
        if self._last_revision:
257
 
            return
258
 
        self.pb.update('get source history')
259
 
        from_history = self.from_branch.revision_history()
260
 
        if from_history:
261
 
            self._last_revision = from_history[-1]
262
 
        else:
263
 
            # no history in the source branch
264
 
            self._last_revision = NULL_REVISION
265
 
 
266
 
fetch = greedy_fetch
 
207
        """Please see branch.fetch()."""
 
208
        to_branch.fetch(from_branch, last_revision, pb)