comparison mercurial/store.py @ 15057:774da7121fc9

atomictempfile: make close() consistent with other file-like objects. The usual contract is that close() makes your writes permanent, so atomictempfile's use of close() to *discard* writes (and rename() to keep them) is rather unexpected. Thus, change it so close() makes things permanent and add a new discard() method to throw them away. discard() is only used internally, in __del__(), to ensure that writes are discarded when an atomictempfile object goes out of scope. I audited mercurial.*, hgext.*, and ~80 third-party extensions, and found no one using the existing semantics of close() to discard writes, so this should be safe.
author Greg Ward <greg@gerg.ca>
date Thu, 25 Aug 2011 20:21:04 -0400
parents 00a0ab08f986
children 62aa9305399d
comparison
equal deleted inserted replaced
15056:8413916df816 15057:774da7121fc9
343 if not self._dirty: 343 if not self._dirty:
344 return 344 return
345 fp = self.opener('fncache', mode='wb', atomictemp=True) 345 fp = self.opener('fncache', mode='wb', atomictemp=True)
346 for p in self.entries: 346 for p in self.entries:
347 fp.write(encodedir(p) + '\n') 347 fp.write(encodedir(p) + '\n')
348 fp.rename() 348 fp.close()
349 self._dirty = False 349 self._dirty = False
350 350
351 def add(self, fn): 351 def add(self, fn):
352 if self.entries is None: 352 if self.entries is None:
353 self._load() 353 self._load()