D476: util: add an mmapread method
mbthomas (Mark Thomas)
phabricator at mercurial-scm.org
Tue Aug 22 14:31:19 UTC 2017
mbthomas created this revision.
Herald added a subscriber: mercurial-devel.
Herald added a reviewer: hg-reviewers.
REVISION SUMMARY
This is useful for large files that are only partly touched.
TEST PLAN
Will be used and tested in a later patch.
REPOSITORY
rHG Mercurial
BRANCH
default
REVISION DETAIL
https://phab.mercurial-scm.org/D476
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
@@ -26,6 +26,7 @@
import gc
import hashlib
import imp
+import mmap
import os
import platform as pyplatform
import re as remod
@@ -407,6 +408,12 @@
self._lenbuf += len(data)
self._buffer.append(data)
+def mmapread(fp):
+ try:
+ return mmap.mmap(fp.fileno(), 0, access=mmap.ACCESS_READ)
+ except ValueError: # cannot mmap an empty file
+ return ''
+
def popen2(cmd, env=None, newlines=False):
# Setting bufsize to -1 lets the system decide the buffer size.
# The default for bufsize is 0, meaning unbuffered. This leads to
To: mbthomas, #fbhgext, #hg-reviewers
Cc: mercurial-devel
More information about the Mercurial-devel
mailing list