~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/store.py

  • Committer: Martin Pool
  • Date: 2005-08-26 02:31:37 UTC
  • Revision ID: mbp@sourcefrog.net-20050826023137-eb4b101cc92f9792
- ignore tags files

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
 
        If an id is present in self, it is skipped.  A count of copied
117
 
        ids is returned, which may be less than len(ids).
 
117
        If an id is present in self, it is skipped.
 
118
 
 
119
        Returns (count_copied, failed), where failed is a collection of ids
 
120
        that could not be copied.
118
121
        """
119
 
        from bzrlib.progress import ProgressBar
120
 
        pb = ProgressBar()
 
122
        pb = bzrlib.ui.ui_factory.progress_bar()
 
123
        
121
124
        pb.update('preparing to copy')
122
125
        to_copy = [id for id in ids if id not in self]
123
126
        if isinstance(other, ImmutableStore):
126
129
        for id in to_copy:
127
130
            count += 1
128
131
            pb.update('copy', count, len(to_copy))
129
 
            self.add(other[id], id)
 
132
            if not permit_failure:
 
133
                self.add(other[id], id)
 
134
            else:
 
135
                try:
 
136
                    entry = other[id]
 
137
                except IndexError:
 
138
                    failures.add(id)
 
139
                    continue
 
140
                self.add(entry, id)
 
141
                
130
142
        assert count == len(to_copy)
131
143
        pb.clear()
132
 
        return count
133
 
 
134
 
 
135
 
    def copy_multi_immutable(self, other, to_copy, pb):
 
144
        return count, []
 
145
 
 
146
 
 
147
    def copy_multi_immutable(self, other, to_copy, pb, permit_failure=False):
136
148
        from shutil import copyfile
137
149
        count = 0
 
150
        failed = set()
138
151
        for id in to_copy:
139
152
            p = self._path(id)
140
153
            other_p = other._path(id)
142
155
                copyfile(other_p, p)
143
156
            except IOError, e:
144
157
                if e.errno == errno.ENOENT:
145
 
                    copyfile(other_p+".gz", p+".gz")
 
158
                    if not permit_failure:
 
159
                        copyfile(other_p+".gz", p+".gz")
 
160
                    else:
 
161
                        try:
 
162
                            copyfile(other_p+".gz", p+".gz")
 
163
                        except IOError, e:
 
164
                            if e.errno == errno.ENOENT:
 
165
                                failed.add(id)
 
166
                            else:
 
167
                                raise
146
168
                else:
147
169
                    raise
148
170
            
150
172
            pb.update('copy', count, len(to_copy))
151
173
        assert count == len(to_copy)
152
174
        pb.clear()
153
 
        return count
 
175
        return count, failed
154
176
    
155
177
 
156
178
    def __contains__(self, fileid):