File tree Expand file tree Collapse file tree 3 files changed +8
-40
lines changed Expand file tree Collapse file tree 3 files changed +8
-40
lines changed Submodule gitdb updated from f50643f to 099ec0d
Original file line number Diff line number Diff line change 66"""Module containing Index implementation, allowing to perform all kinds of index
77manipulations such as querying and merging. """
88import binascii
9- import mmap
109import tempfile
1110import os
1211import sys
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 )
Original file line number Diff line number Diff line change 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-
307279class IterableList (list ):
308280 """
309281 List of iterable objects allowing to query an object by id or by named index::
You can’t perform that action at this time.
0 commit comments