~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/store.py

  • Committer: Martin Pool
  • Date: 2005-08-25 08:54:29 UTC
  • Revision ID: mbp@sourcefrog.net-20050825085429-d815c4dcf7cc2067
- fix bad method declaration

Show diffs side-by-side

added added

removed removed

Lines of Context:
24
24
import os, tempfile, types, osutils, gzip, errno
25
25
from stat import ST_SIZE
26
26
from StringIO import StringIO
27
 
from trace import mutter
 
27
from bzrlib.trace import mutter
 
28
import bzrlib.ui
28
29
 
29
30
######################################################################
30
31
# stores
110
111
            af.close()
111
112
 
112
113
 
113
 
    def copy_multi(self, other, ids):
 
114
    def copy_multi(self, other, ids, permit_failure=False):
114
115
        """Copy texts for ids from other into self.
115
116
 
116
117
        If an id is present in self, it is skipped.  A count of copied
117
118
        ids is returned, which may be less than len(ids).
118
119
        """
119
 
        from bzrlib.progress import ProgressBar
120
 
        pb = ProgressBar()
 
120
        pb = bzrlib.ui.ui_factory.progress_bar()
 
121
        
121
122
        pb.update('preparing to copy')
122
123
        to_copy = [id for id in ids if id not in self]
123
124
        if isinstance(other, ImmutableStore):
126
127
        for id in to_copy:
127
128
            count += 1
128
129
            pb.update('copy', count, len(to_copy))
129
 
            self.add(other[id], id)
 
130
            if not permit_failure:
 
131
                self.add(other[id], id)
 
132
            else:
 
133
                try:
 
134
                    entry = other[id]
 
135
                except IndexError:
 
136
                    failures.add(id)
 
137
                    continue
 
138
                self.add(entry, id)
 
139
                
130
140
        assert count == len(to_copy)
131
141
        pb.clear()
132
142
        return count
133
143
 
134
144
 
135
 
    def copy_multi_immutable(self, other, to_copy, pb):
 
145
    def copy_multi_immutable(self, other, to_copy, pb, permit_failure=False):
136
146
        from shutil import copyfile
137
147
        count = 0
 
148
        failed = set()
138
149
        for id in to_copy:
139
150
            p = self._path(id)
140
151
            other_p = other._path(id)
142
153
                copyfile(other_p, p)
143
154
            except IOError, e:
144
155
                if e.errno == errno.ENOENT:
145
 
                    copyfile(other_p+".gz", p+".gz")
 
156
                    if not permit_failure:
 
157
                        copyfile(other_p+".gz", p+".gz")
 
158
                    else:
 
159
                        try:
 
160
                            copyfile(other_p+".gz", p+".gz")
 
161
                        except IOError, e:
 
162
                            if e.errno == errno.ENOENT:
 
163
                                failed.add(id)
 
164
                            else:
 
165
                                raise
146
166
                else:
147
167
                    raise
148
168
            
150
170
            pb.update('copy', count, len(to_copy))
151
171
        assert count == len(to_copy)
152
172
        pb.clear()
153
 
        return count
 
173
        return count, failed
154
174
    
155
175
 
156
176
    def __contains__(self, fileid):