~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/fetch.py

Make pull update the progress bar more nicely

Show diffs side-by-side

added added

removed removed

Lines of Context:
36
36
from bzrlib.errors import (InstallFailed, NoSuchRevision,
37
37
                           MissingText)
38
38
from bzrlib.trace import mutter
39
 
from bzrlib.progress import ProgressBar
 
39
from bzrlib.progress import ProgressBar, ProgressPhase
40
40
from bzrlib.reconcile import RepoReconciler
41
41
from bzrlib.revision import NULL_REVISION
42
42
from bzrlib.symbol_versioning import *
 
43
import bzrlib.ui
43
44
 
44
45
 
45
46
# TODO: Avoid repeatedly opening weaves so many times.
124
125
        self.from_control = self.from_repository.control_weaves
125
126
        self.count_total = 0
126
127
        self.file_ids_names = {}
 
128
        pp = ProgressPhase('fetch phase', 4, self.pb)
127
129
        try:
 
130
            pp.next_phase()
128
131
            revs = self._revids_to_fetch()
129
132
            # nothing to do
130
133
            if revs: 
 
134
                pp.next_phase()
131
135
                self._fetch_weave_texts(revs)
 
136
                pp.next_phase()
132
137
                self._fetch_inventory_weave(revs)
 
138
                pp.next_phase()
133
139
                self._fetch_revision_texts(revs)
134
140
                self.count_copied += len(revs)
135
141
        finally:
136
142
            self.pb.clear()
137
143
 
138
144
    def _revids_to_fetch(self):
139
 
        self.pb.update('get destination history')
140
145
        mutter('fetch up to rev {%s}', self._last_revision)
141
146
        if self._last_revision is NULL_REVISION:
142
147
            # explicit limit of no revisions needed
155
160
        file_ids = self.from_repository.fileid_involved_by_set(revs)
156
161
        count = 0
157
162
        num_file_ids = len(file_ids)
158
 
        for file_id in file_ids:
159
 
            self.pb.update("merge weaves", count, num_file_ids)
160
 
            count +=1
161
 
            to_weave = self.to_weaves.get_weave_or_empty(file_id,
162
 
                self.to_repository.get_transaction())
 
163
        pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
164
        try:
 
165
            for file_id in file_ids:
 
166
                pb.update("merge weaves", count, num_file_ids)
 
167
                count +=1
 
168
                to_weave = self.to_weaves.get_weave_or_empty(file_id,
 
169
                    self.to_repository.get_transaction())
163
170
 
164
 
            if to_weave.num_versions() > 0:
165
 
                # destination has contents, must merge
166
 
                from_weave = self.from_weaves.get_weave(file_id,
167
 
                    self.from_repository.get_transaction())
168
 
                # we fetch all the texts, because texts do
169
 
                # not reference anything, and its cheap enough
170
 
                to_weave.join(from_weave)
171
 
            else:
172
 
                # destination is empty, just replace it
173
 
                self.to_weaves.copy_multi(self.from_weaves, [file_id], self.pb,
174
 
                                          self.from_repository.get_transaction(),
175
 
                                          self.to_repository.get_transaction())
176
 
        self.pb.clear()
 
171
                if to_weave.num_versions() > 0:
 
172
                    # destination has contents, must merge
 
173
                    from_weave = self.from_weaves.get_weave(file_id,
 
174
                        self.from_repository.get_transaction())
 
175
                    # we fetch all the texts, because texts do
 
176
                    # not reference anything, and its cheap enough
 
177
                    to_weave.join(from_weave)
 
178
                else:
 
179
                    # destination is empty, just replace it
 
180
                    try:
 
181
                        child_pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
182
                        from_repo = self.from_repository
 
183
                        from_transaction = from_repo.get_transaction()
 
184
                        to_transaction = self.to_repository.get_transaction()
 
185
                        self.to_weaves.copy_multi(self.from_weaves, [file_id],
 
186
                                                  child_pb, from_transaction,
 
187
                                                  to_transaction)
 
188
                    finally:
 
189
                        child_pb.finished()
 
190
        finally:
 
191
            pb.finished()
177
192
 
178
193
    def _fetch_inventory_weave(self, revs):
179
 
        self.pb.update("inventory fetch", 0, 2)
180
 
        to_weave = self.to_control.get_weave('inventory',
181
 
                self.to_repository.get_transaction())
182
 
 
183
 
        if to_weave.num_versions() > 0:
184
 
            # destination has contents, must merge
185
 
            self.pb.update("inventory fetch", 1, 2)
186
 
            from_weave = self.from_repository.get_inventory_weave()
187
 
            self.pb.update("inventory fetch", 2, 2)
188
 
            # we fetch only the referenced inventories because we do not
189
 
            # know for unselected inventories whether all their required
190
 
            # texts are present in the other repository - it could be
191
 
            # corrupt.
192
 
            to_weave.join(from_weave, pb=self.pb, msg='merge inventory',
193
 
                          version_ids=revs)
194
 
        else:
195
 
            # destination is empty, just replace it
196
 
            self.to_control.copy_multi(self.from_control,
197
 
                                       ['inventory'],
198
 
                                       self.pb,
199
 
                                       self.from_repository.get_transaction(),
200
 
                                       self.to_repository.get_transaction())
201
 
 
202
 
        self.pb.clear()
 
194
        pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
195
        try:
 
196
            pb.update("inventory fetch", 0, 3)
 
197
            to_weave = self.to_control.get_weave('inventory',
 
198
                    self.to_repository.get_transaction())
 
199
 
 
200
            child_pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
201
            try:
 
202
                if to_weave.num_versions() > 0:
 
203
                    # destination has contents, must merge
 
204
                    pb.update("inventory fetch", 1, 3)
 
205
                    from_weave = self.from_repository.get_inventory_weave()
 
206
                    pb.update("inventory fetch", 2, 3)
 
207
                    # we fetch only the referenced inventories because we do not
 
208
                    # know for unselected inventories whether all their required
 
209
                    # texts are present in the other repository - it could be
 
210
                    # corrupt.
 
211
                    to_weave.join(from_weave, pb=child_pb, 
 
212
                                  msg='merge inventory', version_ids=revs)
 
213
                else:
 
214
                    # destination is empty, just replace it
 
215
                    from_transaction = self.from_repository.get_transaction()
 
216
                    to_transaction = self.to_repository.get_transaction()
 
217
                    self.to_control.copy_multi(self.from_control,
 
218
                                               ['inventory'],
 
219
                                               child_pb,
 
220
                                               from_transaction,
 
221
                                               to_transaction)
 
222
            finally:
 
223
                child_pb.finished()
 
224
        finally:
 
225
            pb.finished()
203
226
 
204
227
 
205
228
class GenericRepoFetcher(RepoFetcher):
213
236
        self.to_transaction = self.to_repository.get_transaction()
214
237
        count = 0
215
238
        total = len(revs)
216
 
        for rev in revs:
217
 
            self.pb.update('copying revisions', count, total)
218
 
            try:
219
 
                sig_text = self.from_repository.get_signature_text(rev)
220
 
                self.to_repository._revision_store.add_revision_signature_text(
221
 
                    rev, sig_text, self.to_transaction)
222
 
            except errors.NoSuchRevision:
223
 
                # not signed.
224
 
                pass
225
 
            self.to_repository._revision_store.add_revision(
226
 
                self.from_repository.get_revision(rev),
227
 
                self.to_transaction)
228
 
            count += 1
229
 
        self.pb.update('copying revisions', count, total)
 
239
        pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
240
        try:
 
241
            for rev in revs:
 
242
                pb.update('copying revisions', count, total)
 
243
                try:
 
244
                    sig_text = self.from_repository.get_signature_text(rev)
 
245
                    store = self.to_repository._revision_store
 
246
                    store.add_revision_signature_text(rev, sig_text,
 
247
                                                      self.to_transaction)
 
248
                except errors.NoSuchRevision:
 
249
                    # not signed.
 
250
                    pass
 
251
                self.to_repository._revision_store.add_revision(
 
252
                    self.from_repository.get_revision(rev),
 
253
                    self.to_transaction)
 
254
                count += 1
 
255
            pb.update('copying revisions', count, total)
 
256
        finally:
 
257
            pb.finished()
230
258
        # fixup inventory if needed: 
231
259
        # this is expensive because we have no inverse index to current ghosts.
232
260
        # but on local disk its a few seconds and sftp push is already insane.