~bzr-pqm/bzr/bzr.dev

« back to all changes in this revision

Viewing changes to bzrlib/hashcache.py

Merge bzr.dev

Show diffs side-by-side

added added

removed removed

Lines of Context:
203
203
        """Write contents of cache to file."""
204
204
        outf = AtomicFile(self.cache_file_name(), 'wb', new_mode=self._mode)
205
205
        try:
206
 
            print >>outf, CACHE_HEADER,
 
206
            outf.write(CACHE_HEADER)
207
207
 
208
208
            for path, c  in self._cache.iteritems():
209
209
                assert '//' not in path, path
210
 
                outf.write(path.encode('utf-8'))
211
 
                outf.write('// ')
212
 
                print >>outf, c[0],     # hex sha1
213
 
                for fld in c[1]:
214
 
                    print >>outf, "%d" % fld,
215
 
                print >>outf
 
210
                line_info = [path.encode('utf-8'), '// ', c[0], ' ']
 
211
                line_info.append(' '.join([str(fld) for fld in c[1]]))
 
212
                line_info.append('\n')
 
213
                outf.write(''.join(line_info))
216
214
            outf.commit()
217
215
            self.needs_write = False
218
216
            ## mutter("write hash cache: %s hits=%d misses=%d stat=%d recent=%d updates=%d",
220
218
            ##        self.stat_count,
221
219
            ##        self.danger_count, self.update_count)
222
220
        finally:
223
 
            if not outf.closed:
224
 
                outf.abort()
 
221
            outf.close()
225
222
 
226
223
    def read(self):
227
224
        """Reinstate cache from file.