comparison mercurial/localrepo.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 9dca7653b525
children cda7a87c1871
comparison
equal deleted inserted replaced
15056:8413916df816 15057:774da7121fc9
519 f = self.opener("cache/branchheads", "w", atomictemp=True) 519 f = self.opener("cache/branchheads", "w", atomictemp=True)
520 f.write("%s %s\n" % (hex(tip), tiprev)) 520 f.write("%s %s\n" % (hex(tip), tiprev))
521 for label, nodes in branches.iteritems(): 521 for label, nodes in branches.iteritems():
522 for node in nodes: 522 for node in nodes:
523 f.write("%s %s\n" % (hex(node), encoding.fromlocal(label))) 523 f.write("%s %s\n" % (hex(node), encoding.fromlocal(label)))
524 f.rename() 524 f.close()
525 except (IOError, OSError): 525 except (IOError, OSError):
526 pass 526 pass
527 527
528 def _updatebranchcache(self, partial, ctxgen): 528 def _updatebranchcache(self, partial, ctxgen):
529 # collect new branch entries 529 # collect new branch entries