util: make buffer readonly
There is no use of writable buffers anywhere in the code, and this helps us
make sure we don't get into unsound territory when sharing memory with Rust.
This `toreadonly` method was not available in Python 3.6, but we dropped the
support for it earlier that week, so no need for any compatibility code.
--- a/mercurial/util.py Thu Sep 05 17:12:52 2024 -0400
+++ b/mercurial/util.py Tue Mar 26 15:51:31 2024 +0000
@@ -333,8 +333,10 @@
def buffer(sliceable, offset=0, length=None):
if length is not None:
- return memoryview(sliceable)[offset : offset + length]
- return memoryview(sliceable)[offset:]
+ view = memoryview(sliceable)[offset : offset + length]
+ else:
+ view = memoryview(sliceable)[offset:]
+ return view.toreadonly()
_chunksize = 4096