Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/revlog.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 | 497819817307 |
children | ee112eb69d2a |
comparison
equal
deleted
inserted
replaced
15056:8413916df816 | 15057:774da7121fc9 |
---|---|
944 self._inline = False | 944 self._inline = False |
945 for i in self: | 945 for i in self: |
946 e = self._io.packentry(self.index[i], self.node, self.version, i) | 946 e = self._io.packentry(self.index[i], self.node, self.version, i) |
947 fp.write(e) | 947 fp.write(e) |
948 | 948 |
949 # if we don't call rename, the temp file will never replace the | 949 # if we don't call close, the temp file will never replace the |
950 # real index | 950 # real index |
951 fp.rename() | 951 fp.close() |
952 | 952 |
953 tr.replace(self.indexfile, trindex * self._io.size) | 953 tr.replace(self.indexfile, trindex * self._io.size) |
954 self._chunkclear() | 954 self._chunkclear() |
955 | 955 |
956 def addrevision(self, text, transaction, link, p1, p2, cachedelta=None): | 956 def addrevision(self, text, transaction, link, p1, p2, cachedelta=None): |