~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 05:58:05 UTC
  • mfrom: (974.1.36)
  • Revision ID: mbp@sourcefrog.net-20050825055805-8c892bc3c2d75131
- merge aaron's merge improvements:

  * When merging, pull in all missing revisions from the source
    branch. 

  * Detect common ancestors by looking at the whole ancestry graph, 
    rather than just mainline history.

  Some changes to reconcile this with parallel updates to the test and
  trace code.

aaron.bentley@utoronto.ca-20050823052551-f3401a8b57d9126f

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
90
91
            
91
92
        p = self._path(fileid)
92
93
        if os.access(p, os.F_OK) or os.access(p + '.gz', os.F_OK):
 
94
            from bzrlib.errors import bailout
93
95
            raise BzrError("store %r already contains id %r" % (self._basedir, fileid))
94
96
 
95
97
        fn = p
109
111
            af.close()
110
112
 
111
113
 
112
 
    def copy_multi(self, other, ids):
 
114
    def copy_multi(self, other, ids, permit_failure=False):
113
115
        """Copy texts for ids from other into self.
114
116
 
115
117
        If an id is present in self, it is skipped.  A count of copied
116
118
        ids is returned, which may be less than len(ids).
117
119
        """
118
 
        from bzrlib.progress import ProgressBar
119
 
        pb = ProgressBar()
 
120
        pb = bzrlib.ui.ui_factory.progress_bar()
 
121
        
120
122
        pb.update('preparing to copy')
121
123
        to_copy = [id for id in ids if id not in self]
 
124
        if isinstance(other, ImmutableStore):
 
125
            return self.copy_multi_immutable(other, to_copy, pb)
122
126
        count = 0
123
127
        for id in to_copy:
124
128
            count += 1
125
129
            pb.update('copy', count, len(to_copy))
126
 
            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
                
127
140
        assert count == len(to_copy)
128
141
        pb.clear()
129
142
        return count
 
143
 
 
144
 
 
145
    def copy_multi_immutable(self, other, to_copy, pb, permit_failure=False):
 
146
        from shutil import copyfile
 
147
        count = 0
 
148
        failed = set()
 
149
        for id in to_copy:
 
150
            p = self._path(id)
 
151
            other_p = other._path(id)
 
152
            try:
 
153
                copyfile(other_p, p)
 
154
            except IOError, e:
 
155
                if e.errno == errno.ENOENT:
 
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
 
166
                else:
 
167
                    raise
 
168
            
 
169
            count += 1
 
170
            pb.update('copy', count, len(to_copy))
 
171
        assert count == len(to_copy)
 
172
        pb.clear()
 
173
        return count, failed
130
174
    
131
175
 
132
176
    def __contains__(self, fileid):
148
192
    def __len__(self):
149
193
        return len(os.listdir(self._basedir))
150
194
 
 
195
 
151
196
    def __getitem__(self, fileid):
152
197
        """Returns a file reading from a particular entry."""
153
198
        p = self._path(fileid)
154
199
        try:
155
200
            return gzip.GzipFile(p + '.gz', 'rb')
156
201
        except IOError, e:
157
 
            if e.errno == errno.ENOENT:
158
 
                return file(p, 'rb')
159
 
            else:
160
 
                raise e
 
202
            if e.errno != errno.ENOENT:
 
203
                raise
 
204
 
 
205
        try:
 
206
            return file(p, 'rb')
 
207
        except IOError, e:
 
208
            if e.errno != errno.ENOENT:
 
209
                raise
 
210
 
 
211
        raise IndexError(fileid)
 
212
 
161
213
 
162
214
    def total_size(self):
163
215
        """Return (count, bytes)