88
88
count_weaves -- number of file weaves copied
90
90
def __init__(self, to_branch, from_branch, last_revision=None, pb=None):
91
if to_branch == from_branch:
92
raise Exception("can't fetch from a branch to itself")
91
if to_branch.base == from_branch.base:
92
raise Exception("can't fetch from a branch to itself %s, %s" %
93
(from_branch.base, to_branch.base))
93
95
self.to_branch = to_branch
94
self.to_weaves = to_branch.weave_store
95
self.to_control = to_branch.control_weaves
96
96
self.from_branch = from_branch
97
self.from_weaves = from_branch.weave_store
98
self.from_control = from_branch.control_weaves
97
self._last_revision = last_revision
99
self.pb = bzrlib.ui.ui_factory.progress_bar()
102
self.from_branch.lock_read()
104
self.to_branch.lock_write()
108
self.to_branch.unlock()
110
self.from_branch.unlock()
113
"""Primary worker function.
115
This initialises all the needed variables, and then fetches the
116
requested revisions, finally clearing the progress bar.
118
self.to_repository = self.to_branch.repository
119
self.to_weaves = self.to_repository.weave_store
120
self.to_control = self.to_repository.control_weaves
121
self.from_repository = self.from_branch.repository
122
self.from_weaves = self.from_repository.weave_store
123
self.from_control = self.from_repository.control_weaves
99
124
self.failed_revisions = []
100
125
self.count_copied = 0
101
126
self.count_total = 0
102
127
self.count_weaves = 0
103
128
self.copied_file_ids = set()
104
129
self.file_ids_names = {}
106
self.pb = bzrlib.ui.ui_factory.progress_bar()
109
self.from_branch.lock_read()
111
revs = self._revids_to_fetch(last_revision)
131
revs = self._revids_to_fetch()
114
134
self._fetch_weave_texts(revs)
116
136
self._fetch_revision_texts(revs)
117
137
self.count_copied += len(revs)
119
self.from_branch.unlock()
122
def _revids_to_fetch(self, last_revision):
123
self.last_revision = self._find_last_revision(last_revision)
124
mutter('fetch up to rev {%s}', self.last_revision)
125
if (self.last_revision is not None and
126
self.to_branch.has_revision(self.last_revision)):
141
def _revids_to_fetch(self):
142
self._find_last_revision()
143
mutter('fetch up to rev {%s}', self._last_revision)
144
if (self._last_revision is not None and
145
self.to_repository.has_revision(self._last_revision)):
129
branch_from_revs = set(self.from_branch.get_ancestry(self.last_revision))
148
branch_from_revs = set(self.from_repository.get_ancestry(self._last_revision))
130
149
except WeaveError:
131
raise InstallFailed([self.last_revision])
150
raise InstallFailed([self._last_revision])
133
152
self.dest_last_rev = self.to_branch.last_revision()
134
branch_to_revs = set(self.to_branch.get_ancestry(self.dest_last_rev))
153
branch_to_revs = set(self.to_repository.get_ancestry(self.dest_last_rev))
136
155
return branch_from_revs.difference(branch_to_revs)
138
157
def _fetch_revision_texts(self, revs):
139
self.to_branch.revision_store.copy_multi(
140
self.from_branch.revision_store, revs)
158
self.to_repository.revision_store.copy_multi(
159
self.from_repository.revision_store, revs)
142
161
def _fetch_weave_texts(self, revs):
143
162
file_ids = self.from_branch.fileid_involved_by_set(revs)
169
188
def _fetch_inventory_weave(self, revs):
170
189
self.pb.update("inventory merge", 0, 1)
172
from_weave = self.from_control.get_weave('inventory',
173
self.from_branch.get_transaction())
174
to_weave = self.to_control.get_weave('inventory',
175
self.to_branch.get_transaction())
190
from_weave = self.from_repository.get_inventory_weave()
191
to_weave = self.to_repository.get_inventory_weave()
177
193
if to_weave.numversions() > 0:
178
194
# destination has contents, must merge
192
def _find_last_revision(self, last_revision):
208
def _find_last_revision(self):
193
209
"""Find the limiting source revision.
195
211
Every ancestor of that revision will be merged across.
197
213
Returns the revision_id, or returns None if there's no history
198
214
in the source branch."""
215
if self._last_revision:
201
217
self.pb.update('get source history')
202
218
from_history = self.from_branch.revision_history()
203
219
self.pb.update('get destination history')
205
return from_history[-1]
221
self._last_revision = from_history[-1]
207
return None # no history in the source branch
223
# no history in the source branch
224
self._last_revision = None