Mercurial > public > mercurial-scm > hg
comparison tests/test-filecache.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 | 4c01478991a3 |
children | d01e08ea459d |
comparison
equal
deleted
inserted
replaced
15056:8413916df816 | 15057:774da7121fc9 |
---|---|
57 # atomic replace file, size doesn't change | 57 # atomic replace file, size doesn't change |
58 # hopefully st_mtime doesn't change as well so this doesn't use the cache | 58 # hopefully st_mtime doesn't change as well so this doesn't use the cache |
59 # because of inode change | 59 # because of inode change |
60 f = scmutil.opener('.')('x', 'w', atomictemp=True) | 60 f = scmutil.opener('.')('x', 'w', atomictemp=True) |
61 f.write('b') | 61 f.write('b') |
62 f.rename() | 62 f.close() |
63 | 63 |
64 repo.invalidate() | 64 repo.invalidate() |
65 repo.cached | 65 repo.cached |
66 | 66 |
67 def fakeuncacheable(): | 67 def fakeuncacheable(): |