/brz/remove-bazaar

To get this branch, use:
bzr branch http://gegoxaren.bato24.eu/bzr/brz/remove-bazaar

« back to all changes in this revision

Viewing changes to breezy/hashcache.py

  • Committer: Jelmer Vernooij
  • Date: 2018-08-14 21:37:46 UTC
  • mto: This revision was merged to the branch mainline in revision 7083.
  • Revision ID: jelmer@jelmer.uk-20180814213746-oxx6tcn57k8k98ed
Fix an ignore test. Make AtomicFile a contextmanager.

Show diffs side-by-side

added added

removed removed

Lines of Context:
223
223
 
224
224
    def write(self):
225
225
        """Write contents of cache to file."""
226
 
        outf = atomicfile.AtomicFile(self.cache_file_name(), 'wb',
227
 
                                     new_mode=self._mode)
228
 
        try:
 
226
        with atomicfile.AtomicFile(self.cache_file_name(), 'wb',
 
227
                new_mode=self._mode) as outf:
229
228
            outf.write(CACHE_HEADER)
230
229
 
231
230
            for path, c  in viewitems(self._cache):
233
232
                line_info.append(b'%d %d %d %d %d %d' % c[1])
234
233
                line_info.append(b'\n')
235
234
                outf.write(b''.join(line_info))
236
 
            outf.commit()
237
235
            self.needs_write = False
238
236
            ## mutter("write hash cache: %s hits=%d misses=%d stat=%d recent=%d updates=%d",
239
237
            ##        self.cache_file_name(), self.hit_count, self.miss_count,
240
238
            ##        self.stat_count,
241
239
            ##        self.danger_count, self.update_count)
242
 
        finally:
243
 
            outf.close()
244
240
 
245
241
    def read(self):
246
242
        """Reinstate cache from file.