Mercurial > public > mercurial-scm > hg-stable
comparison mercurial/context.py @ 48694:576040155dba
arbitraryfilectx: use our existing helpers for reading and writing files
Differential Revision: https://phab.mercurial-scm.org/D12090
author | Martin von Zweigbergk <martinvonz@google.com> |
---|---|
date | Wed, 26 Jan 2022 15:32:18 -0800 |
parents | 9ae0353c9f5d |
children | d5121df04808 |
comparison
equal
deleted
inserted
replaced
48693:657e490756e6 | 48694:576040155dba |
---|---|
18 nullrev, | 18 nullrev, |
19 short, | 19 short, |
20 ) | 20 ) |
21 from .pycompat import ( | 21 from .pycompat import ( |
22 getattr, | 22 getattr, |
23 open, | |
24 ) | 23 ) |
25 from . import ( | 24 from . import ( |
26 dagop, | 25 dagop, |
27 encoding, | 26 encoding, |
28 error, | 27 error, |
3127 | 3126 |
3128 def data(self): | 3127 def data(self): |
3129 return util.readfile(self._path) | 3128 return util.readfile(self._path) |
3130 | 3129 |
3131 def decodeddata(self): | 3130 def decodeddata(self): |
3132 with open(self._path, b"rb") as f: | 3131 return util.readfile(self._path) |
3133 return f.read() | |
3134 | 3132 |
3135 def remove(self): | 3133 def remove(self): |
3136 util.unlink(self._path) | 3134 util.unlink(self._path) |
3137 | 3135 |
3138 def write(self, data, flags, **kwargs): | 3136 def write(self, data, flags, **kwargs): |
3139 assert not flags | 3137 assert not flags |
3140 with open(self._path, b"wb") as f: | 3138 util.writefile(self._path, data) |
3141 f.write(data) |