D7808: mmap: add a size argument to mmapread
marmoute (Pierre-Yves David)
phabricator at mercurial-scm.org
Wed Jan 8 15:04:48 EST 2020
Closed by commit rHG8ed8dfbeabb9: mmap: add a size argument to mmapread (authored by marmoute).
This revision was automatically updated to reflect the committed changes.
This revision was not accepted when it landed; it landed in state "Needs Review".
CHANGED PRIOR TO COMMIT
https://phab.mercurial-scm.org/D7808?vs=19060&id=19109#toc
REPOSITORY
rHG Mercurial
CHANGES SINCE LAST UPDATE
https://phab.mercurial-scm.org/D7808?vs=19060&id=19109
CHANGES SINCE LAST ACTION
https://phab.mercurial-scm.org/D7808/new/
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,16 @@
return data
-def mmapread(fp):
+def mmapread(fp, size=None):
+ if size == 0:
+ # size of 0 to mmap.mmap() means "all data"
+ # rather than "zero bytes", so special case that.
+ 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: durin42, mharbison72, mercurial-devel
More information about the Mercurial-devel
mailing list