~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/fetch.py

  • Committer: Canonical.com Patch Queue Manager
  • Date: 2006-03-12 00:19:04 UTC
  • mfrom: (1551.2.37 Aaron's mergeable stuff)
  • Revision ID: pqm@pqm.ubuntu.com-20060312001904-3bcd7cbf830cc37c
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 copy it.
173
 
                # this copies all the texts, which is useful and 
174
 
                # on per-file basis quite cheap.
175
 
                self.to_weaves.copy_multi(self.from_weaves, [file_id], self.pb,
176
 
                                          self.from_repository.get_transaction(),
177
 
                                          self.to_repository.get_transaction())
178
 
        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 copy it.
 
180
                    # this copies all the texts, which is useful and 
 
181
                    # on per-file basis quite cheap.
 
182
                    child_pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
183
                    try:
 
184
                        from_repo = self.from_repository
 
185
                        from_transaction = from_repo.get_transaction()
 
186
                        to_transaction = self.to_repository.get_transaction()
 
187
                        self.to_weaves.copy_multi(self.from_weaves, [file_id],
 
188
                                                  child_pb, from_transaction,
 
189
                                                  to_transaction)
 
190
                    finally:
 
191
                        child_pb.finished()
 
192
        finally:
 
193
            pb.finished()
179
194
 
180
195
    def _fetch_inventory_weave(self, revs):
181
 
        self.pb.update("inventory fetch", 0, 2)
182
 
        to_weave = self.to_control.get_weave('inventory',
183
 
                self.to_repository.get_transaction())
 
196
        pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
197
        try:
 
198
            pb.update("inventory fetch", 0, 3)
 
199
            to_weave = self.to_control.get_weave('inventory',
 
200
                    self.to_repository.get_transaction())
184
201
 
185
 
        # just merge, this is optimisable and its means we dont
186
 
        # copy unreferenced data such as not-needed inventories.
187
 
        self.pb.update("inventory fetch", 1, 2)
188
 
        from_weave = self.from_repository.get_inventory_weave()
189
 
        self.pb.update("inventory fetch", 2, 2)
190
 
        # we fetch only the referenced inventories because we do not
191
 
        # know for unselected inventories whether all their required
192
 
        # texts are present in the other repository - it could be
193
 
        # corrupt.
194
 
        to_weave.join(from_weave, pb=self.pb, msg='merge inventory',
195
 
                      version_ids=revs)
196
 
        self.pb.clear()
 
202
            child_pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
203
            try:
 
204
                # just merge, this is optimisable and its means we dont
 
205
                # copy unreferenced data such as not-needed inventories.
 
206
                pb.update("inventory fetch", 1, 3)
 
207
                from_weave = self.from_repository.get_inventory_weave()
 
208
                pb.update("inventory fetch", 2, 3)
 
209
                # we fetch only the referenced inventories because we do not
 
210
                # know for unselected inventories whether all their required
 
211
                # texts are present in the other repository - it could be
 
212
                # corrupt.
 
213
                to_weave.join(from_weave, pb=child_pb, msg='merge inventory',
 
214
                              version_ids=revs)
 
215
            finally:
 
216
                child_pb.finished()
 
217
        finally:
 
218
            pb.finished()
197
219
 
198
220
 
199
221
class GenericRepoFetcher(RepoFetcher):
207
229
        self.to_transaction = self.to_repository.get_transaction()
208
230
        count = 0
209
231
        total = len(revs)
210
 
        for rev in revs:
211
 
            self.pb.update('copying revisions', count, total)
212
 
            try:
213
 
                sig_text = self.from_repository.get_signature_text(rev)
214
 
                self.to_repository._revision_store.add_revision_signature_text(
215
 
                    rev, sig_text, self.to_transaction)
216
 
            except errors.NoSuchRevision:
217
 
                # not signed.
218
 
                pass
219
 
            self.to_repository._revision_store.add_revision(
220
 
                self.from_repository.get_revision(rev),
221
 
                self.to_transaction)
222
 
            count += 1
223
 
        self.pb.update('copying revisions', count, total)
 
232
        pb = bzrlib.ui.ui_factory.nested_progress_bar()
 
233
        try:
 
234
            for rev in revs:
 
235
                pb.update('copying revisions', count, total)
 
236
                try:
 
237
                    sig_text = self.from_repository.get_signature_text(rev)
 
238
                    store = self.to_repository._revision_store
 
239
                    store.add_revision_signature_text(rev, sig_text,
 
240
                                                      self.to_transaction)
 
241
                except errors.NoSuchRevision:
 
242
                    # not signed.
 
243
                    pass
 
244
                self.to_repository._revision_store.add_revision(
 
245
                    self.from_repository.get_revision(rev),
 
246
                    self.to_transaction)
 
247
                count += 1
 
248
            pb.update('copying revisions', count, total)
 
249
        finally:
 
250
            pb.finished()
224
251
        # fixup inventory if needed: 
225
252
        # this is expensive because we have no inverse index to current ghosts.
226
253
        # but on local disk its a few seconds and sftp push is already insane.