90
90
def __init__(self, to_branch, from_branch, last_revision=None, pb=None):
91
91
if to_branch == from_branch:
92
92
raise Exception("can't fetch from a branch to itself")
93
94
self.to_branch = to_branch
94
self.to_repository = to_branch.repository
95
self.from_branch = from_branch
96
self._last_revision = last_revision
98
self.pb = bzrlib.ui.ui_factory.progress_bar()
101
self.from_branch.lock_read()
103
self.to_branch.lock_write()
107
self.to_branch.unlock()
109
self.from_branch.unlock()
112
"""Primary worker function.
114
This initialises all the needed variables, and then fetches the
115
requested revisions, finally clearing the progress bar.
117
self.to_repository = self.to_branch.repository
95
118
self.to_weaves = self.to_repository.weave_store
96
119
self.to_control = self.to_repository.control_weaves
97
self.from_branch = from_branch
98
self.from_repository = from_branch.repository
120
self.from_repository = self.from_branch.repository
99
121
self.from_weaves = self.from_repository.weave_store
100
122
self.from_control = self.from_repository.control_weaves
101
123
self.failed_revisions = []
104
126
self.count_weaves = 0
105
127
self.copied_file_ids = set()
106
128
self.file_ids_names = {}
108
self.pb = bzrlib.ui.ui_factory.progress_bar()
111
self.from_branch.lock_read()
113
self._fetch_revisions(last_revision)
130
self._fetch_revisions()
115
self.from_branch.unlock()
118
def _fetch_revisions(self, last_revision):
119
self.last_revision = self._find_last_revision(last_revision)
120
mutter('fetch up to rev {%s}', self.last_revision)
121
if (self.last_revision is not None and
122
self.to_repository.has_revision(self.last_revision)):
134
def _fetch_revisions(self):
135
self._find_last_revision()
136
mutter('fetch up to rev {%s}', self._last_revision)
137
if (self._last_revision is not None and
138
self.to_repository.has_revision(self._last_revision)):
125
141
revs_to_fetch = self._compare_ancestries()
126
142
except WeaveError:
127
raise InstallFailed([self.last_revision])
143
raise InstallFailed([self._last_revision])
128
144
self._copy_revisions(revs_to_fetch)
129
145
self.new_ancestry = revs_to_fetch
131
def _find_last_revision(self, last_revision):
147
def _find_last_revision(self):
132
148
"""Find the limiting source revision.
134
150
Every ancestor of that revision will be merged across.
136
152
Returns the revision_id, or returns None if there's no history
137
153
in the source branch."""
154
if self._last_revision:
140
156
self.pb.update('get source history')
141
157
from_history = self.from_branch.revision_history()
142
158
self.pb.update('get destination history')
144
return from_history[-1]
160
self._last_revision = from_history[-1]
146
return None # no history in the source branch
162
# no history in the source branch
163
self._last_revision = None
149
165
def _compare_ancestries(self):
150
166
"""Get a list of revisions that must be copied.
153
169
branch and not in the destination branch."""
154
170
self.pb.update('get source ancestry')
155
171
from_repository = self.from_branch.repository
156
self.from_ancestry = from_repository.get_ancestry(self.last_revision)
172
self.from_ancestry = from_repository.get_ancestry(self._last_revision)
158
174
dest_last_rev = self.to_branch.last_revision()
159
175
self.pb.update('get destination ancestry')