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
68
70
class RepoFetcher(object):
69
71
"""Pull revisions and texts from one repository to another.
200
202
class Fetcher(object):
201
"""Pull revisions and texts from one branch to another.
203
This doesn't update the destination's history; that can be done
204
separately if desired.
207
If set, pull only up to this revision_id.
211
last_revision -- if last_revision
212
is given it will be that, otherwise the last revision of
215
count_copied -- number of revisions copied
203
"""Backwards compatability glue for branch.fetch()."""
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))
222
self.to_branch = to_branch
223
self.from_branch = from_branch
224
self._last_revision = last_revision
226
self.pb = bzrlib.ui.ui_factory.progress_bar()
229
self.from_branch.lock_read()
231
self.to_branch.lock_write()
235
self.to_branch.unlock()
237
self.from_branch.unlock()
240
self._find_last_revision()
241
repo_fetcher = RepoFetcher(to_repository=self.to_branch.repository,
242
from_repository=self.from_branch.repository,
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
249
def _find_last_revision(self):
250
"""Find the limiting source revision.
252
Every ancestor of that revision will be merged across.
254
Returns the revision_id, or returns None if there's no history
255
in the source branch."""
256
if self._last_revision:
258
self.pb.update('get source history')
259
from_history = self.from_branch.revision_history()
261
self._last_revision = from_history[-1]
263
# no history in the source branch
264
self._last_revision = NULL_REVISION
207
"""Please see branch.fetch()."""
208
to_branch.fetch(from_branch, last_revision, pb)