~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/store/__init__.py

  • Committer: John Arbash Meinel
  • Date: 2006-02-16 17:10:15 UTC
  • mto: (1185.50.81 bzr-jam-integration)
  • mto: This revision was merged to the branch mainline in revision 1554.
  • Revision ID: john@arbash-meinel.com-20060216171015-1c017977993fbe9b
Adding progress bars to copy_all and copy_multi, fixing ordering of repository.clone() to pull inventories after weaves.

Show diffs side-by-side

added added

removed removed

Lines of Context:
35
35
from bzrlib.trace import mutter
36
36
import bzrlib.transport as transport
37
37
from bzrlib.transport.local import LocalTransport
 
38
import bzrlib.ui
38
39
 
39
40
######################################################################
40
41
# stores
101
102
            followed by a list of entries which could not be copied (because they
102
103
            were missing)
103
104
        """
104
 
        if pb is None:
105
 
            pb = bzrlib.ui.ui_factory.progress_bar()
106
 
        pb.update('preparing to copy')
 
105
        if pb:
 
106
            pb.update('preparing to copy')
107
107
        failed = set()
108
108
        count = 0
109
109
        ids = list(ids) # get the list for showing a length.
118
118
                        self._copy_one(fileid, suffix, other, pb)
119
119
                    except KeyError:
120
120
                        pass
121
 
                pb.update('copy', count, len(ids))
 
121
                if pb:
 
122
                    pb.update('copy', count, len(ids))
122
123
            except KeyError:
123
124
                if permit_failure:
124
125
                    failed.add(fileid)
125
126
                else:
126
127
                    raise
127
128
        assert count == len(ids)
128
 
        pb.clear()
 
129
        if pb:
 
130
            pb.clear()
129
131
        return count, failed
130
132
 
131
133
    def _copy_one(self, fileid, suffix, other, pb):
311
313
    return bzrlib.store.text.TextStore(transport.memory.MemoryTransport())
312
314
        
313
315
 
314
 
def copy_all(store_from, store_to):
 
316
def copy_all(store_from, store_to, pb=None):
315
317
    """Copy all ids from one store to another."""
316
318
    # TODO: Optional progress indicator
317
319
    if not store_from.listable():
318
320
        raise UnlistableStore(store_from)
319
 
    ids = [f for f in store_from]
 
321
    ids = []
 
322
    for count, file_id in enumerate(store_from):
 
323
        if pb:
 
324
            pb.update('listing files', count, count)
 
325
        ids.append(file_id)
 
326
    if pb:
 
327
        pb.clear()
320
328
    mutter('copy_all ids: %r', ids)
321
 
    store_to.copy_multi(store_from, ids)
 
329
    store_to.copy_multi(store_from, ids, pb=pb)
 
330
 
322
331
 
323
332
def hash_prefix(fileid):
324
333
    return "%02x/" % (adler32(fileid) & 0xff)
325
334
 
 
335