diff options
m--------- | lib/git/ext/gitdb | 0 | ||||
-rw-r--r-- | lib/git/index/base.py | 12 | ||||
-rw-r--r-- | lib/git/utils.py | 34 |
3 files changed, 7 insertions, 39 deletions
diff --git a/lib/git/ext/gitdb b/lib/git/ext/gitdb -Subproject f50643ff166180d3a048ff55422d84e631e831b +Subproject 099ec0dbd23bf46cba7618768e628ceeac7c2e1 diff --git a/lib/git/index/base.py b/lib/git/index/base.py index 02ed78ea..b2ba9e5c 100644 --- a/lib/git/index/base.py +++ b/lib/git/index/base.py @@ -6,7 +6,6 @@ """Module containing Index implementation, allowing to perform all kinds of index manipulations such as querying and merging. """ import binascii -import mmap import tempfile import os import sys @@ -44,7 +43,8 @@ from git.utils import ( IndexFileSHA1Writer, LazyMixin, LockedFD, - join_path_native + join_path_native, + file_contents_ro ) @@ -91,7 +91,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): # try memory map for speed lfd = LockedFD(self._file_path) try: - stream = lfd.open(write=False, stream=True) + fd = lfd.open(write=False, stream=False) except OSError: lfd.rollback() # in new repositories, there may be no index, which means we are empty @@ -99,11 +99,7 @@ class IndexFile(LazyMixin, diff.Diffable, Serializable): return # END exception handling - try: - stream = mmap.mmap(stream.fileno(), 0, access=mmap.ACCESS_READ) - except Exception: - pass - # END memory mapping + stream = file_contents_ro(fd, stream=True, allow_mmap=True) try: self._deserialize(stream) diff --git a/lib/git/utils.py b/lib/git/utils.py index 343338a9..bd7cc0f3 100644 --- a/lib/git/utils.py +++ b/lib/git/utils.py @@ -13,7 +13,9 @@ from gitdb.util import ( stream_copy, make_sha, FDStreamWrapper, - LockedFD + LockedFD, + file_contents_ro, + LazyMixin ) @@ -274,36 +276,6 @@ class BlockingLockFile(LockFile): # END endless loop -class LazyMixin(object): - """ - Base class providing an interface to lazily retrieve attribute values upon - first access. If slots are used, memory will only be reserved once the attribute - is actually accessed and retrieved the first time. All future accesses will - return the cached value as stored in the Instance's dict or slot. - """ - __slots__ = tuple() - - def __getattr__(self, attr): - """ - Whenever an attribute is requested that we do not know, we allow it - to be created and set. Next time the same attribute is reqeusted, it is simply - returned from our dict/slots. - """ - self._set_cache_(attr) - # will raise in case the cache was not created - return object.__getattribute__(self, attr) - - def _set_cache_(self, attr): - """ This method should be overridden in the derived class. - It should check whether the attribute named by attr can be created - and cached. Do nothing if you do not know the attribute or call your subclass - - The derived class may create as many additional attributes as it deems - necessary in case a git command returns more information than represented - in the single attribute.""" - pass - - class IterableList(list): """ List of iterable objects allowing to query an object by id or by named index:: |