Skip to content

Commit e837b90

Browse files
committed
Move LazyMixin type to gitdb, index reading now uses file_contents_ro from gitdb as well
1 parent 1d23075 commit e837b90

File tree

3 files changed

+8
-40
lines changed

3 files changed

+8
-40
lines changed

lib/git/ext/gitdb

Submodule gitdb updated from f50643f to 099ec0d

lib/git/index/base.py

+4-8
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
"""Module containing Index implementation, allowing to perform all kinds of index
77
manipulations such as querying and merging. """
88
import binascii
9-
import mmap
109
import tempfile
1110
import os
1211
import sys
@@ -44,7 +43,8 @@
4443
IndexFileSHA1Writer,
4544
LazyMixin,
4645
LockedFD,
47-
join_path_native
46+
join_path_native,
47+
file_contents_ro
4848
)
4949

5050

@@ -91,19 +91,15 @@ def _set_cache_(self, attr):
9191
# try memory map for speed
9292
lfd = LockedFD(self._file_path)
9393
try:
94-
stream = lfd.open(write=False, stream=True)
94+
fd = lfd.open(write=False, stream=False)
9595
except OSError:
9696
lfd.rollback()
9797
# in new repositories, there may be no index, which means we are empty
9898
self.entries = dict()
9999
return
100100
# END exception handling
101101

102-
try:
103-
stream = mmap.mmap(stream.fileno(), 0, access=mmap.ACCESS_READ)
104-
except Exception:
105-
pass
106-
# END memory mapping
102+
stream = file_contents_ro(fd, stream=True, allow_mmap=True)
107103

108104
try:
109105
self._deserialize(stream)

lib/git/utils.py

+3-31
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,9 @@
1313
stream_copy,
1414
make_sha,
1515
FDStreamWrapper,
16-
LockedFD
16+
LockedFD,
17+
file_contents_ro,
18+
LazyMixin
1719
)
1820

1921

@@ -274,36 +276,6 @@ def _obtain_lock(self):
274276
# END endless loop
275277

276278

277-
class LazyMixin(object):
278-
"""
279-
Base class providing an interface to lazily retrieve attribute values upon
280-
first access. If slots are used, memory will only be reserved once the attribute
281-
is actually accessed and retrieved the first time. All future accesses will
282-
return the cached value as stored in the Instance's dict or slot.
283-
"""
284-
__slots__ = tuple()
285-
286-
def __getattr__(self, attr):
287-
"""
288-
Whenever an attribute is requested that we do not know, we allow it
289-
to be created and set. Next time the same attribute is reqeusted, it is simply
290-
returned from our dict/slots.
291-
"""
292-
self._set_cache_(attr)
293-
# will raise in case the cache was not created
294-
return object.__getattribute__(self, attr)
295-
296-
def _set_cache_(self, attr):
297-
""" This method should be overridden in the derived class.
298-
It should check whether the attribute named by attr can be created
299-
and cached. Do nothing if you do not know the attribute or call your subclass
300-
301-
The derived class may create as many additional attributes as it deems
302-
necessary in case a git command returns more information than represented
303-
in the single attribute."""
304-
pass
305-
306-
307279
class IterableList(list):
308280
"""
309281
List of iterable objects allowing to query an object by id or by named index::

0 commit comments

Comments
 (0)