Mercurial > hg-stable
diff mercurial/bookmarks.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 | 28762bf809d8 |
children | 7196ed7a1505 |
line wrap: on
line diff
--- a/mercurial/bookmarks.py Wed Aug 24 05:42:41 2011 -0400 +++ b/mercurial/bookmarks.py Thu Aug 25 20:21:04 2011 -0400 @@ -90,7 +90,7 @@ file = repo.opener('bookmarks', 'w', atomictemp=True) for refspec, node in refs.iteritems(): file.write("%s %s\n" % (hex(node), encoding.fromlocal(refspec))) - file.rename() + file.close() # touch 00changelog.i so hgweb reloads bookmarks (no lock needed) try: @@ -121,7 +121,7 @@ try: file = repo.opener('bookmarks.current', 'w', atomictemp=True) file.write(encoding.fromlocal(mark)) - file.rename() + file.close() finally: wlock.release() repo._bookmarkcurrent = mark