D7808: mmap: add a size argument to mmapread

marmoute (Pierre-Yves David) phabricator at mercurial-scm.org
Tue Jan 7 06:27:54 EST 2020


marmoute created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.

REVISION SUMMARY
  With this argument, we can control the size of the mmap created. (previously it
  was always the whole file.

REPOSITORY
  rHG Mercurial

REVISION DETAIL
  https://phab.mercurial-scm.org/D7808

AFFECTED FILES
  mercurial/util.py

CHANGE DETAILS

diff --git a/mercurial/util.py b/mercurial/util.py
--- a/mercurial/util.py
+++ b/mercurial/util.py
@@ -415,10 +415,14 @@
         return data
 
 
-def mmapread(fp):
+def mmapread(fp, size=None):
+    if size == 0:
+        return b''
+    elif size is None:
+        size = 0
     try:
         fd = getattr(fp, 'fileno', lambda: fp)()
-        return mmap.mmap(fd, 0, access=mmap.ACCESS_READ)
+        return mmap.mmap(fd, size, access=mmap.ACCESS_READ)
     except ValueError:
         # Empty files cannot be mmapped, but mmapread should still work.  Check
         # if the file is empty, and if so, return an empty buffer.



To: marmoute, #hg-reviewers
Cc: mercurial-devel


More information about the Mercurial-devel mailing list