File tree 3 files changed +8
-40
lines changed
3 files changed +8
-40
lines changed Submodule gitdb updated from f50643f to 099ec0d
Original file line number Diff line number Diff line change 6
6
"""Module containing Index implementation, allowing to perform all kinds of index
7
7
manipulations such as querying and merging. """
8
8
import binascii
9
- import mmap
10
9
import tempfile
11
10
import os
12
11
import sys
44
43
IndexFileSHA1Writer ,
45
44
LazyMixin ,
46
45
LockedFD ,
47
- join_path_native
46
+ join_path_native ,
47
+ file_contents_ro
48
48
)
49
49
50
50
@@ -91,19 +91,15 @@ def _set_cache_(self, attr):
91
91
# try memory map for speed
92
92
lfd = LockedFD (self ._file_path )
93
93
try :
94
- stream = lfd .open (write = False , stream = True )
94
+ fd = lfd .open (write = False , stream = False )
95
95
except OSError :
96
96
lfd .rollback ()
97
97
# in new repositories, there may be no index, which means we are empty
98
98
self .entries = dict ()
99
99
return
100
100
# END exception handling
101
101
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 )
107
103
108
104
try :
109
105
self ._deserialize (stream )
Original file line number Diff line number Diff line change 13
13
stream_copy ,
14
14
make_sha ,
15
15
FDStreamWrapper ,
16
- LockedFD
16
+ LockedFD ,
17
+ file_contents_ro ,
18
+ LazyMixin
17
19
)
18
20
19
21
@@ -274,36 +276,6 @@ def _obtain_lock(self):
274
276
# END endless loop
275
277
276
278
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
-
307
279
class IterableList (list ):
308
280
"""
309
281
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