~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/store/__init__.py

  • Committer: Martin Pool
  • Date: 2006-03-06 11:20:10 UTC
  • mfrom: (1593 +trunk)
  • mto: This revision was merged to the branch mainline in revision 1611.
  • Revision ID: mbp@sourcefrog.net-20060306112010-17c0170dde5d1eea
[merge] large merge to sync with bzr.dev

Show diffs side-by-side

added added

removed removed

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