@@ -67,7 +67,7 @@ class Repo(object):
67
67
'git_dir' is the .git repository directory, which is always set."""
68
68
DAEMON_EXPORT_FILE = 'git-daemon-export-ok'
69
69
70
- _git = None # Must exist, or __del__ will fail in case we raise on `__init__()`
70
+ git = None # Must exist, or __del__ will fail in case we raise on `__init__()`
71
71
working_dir = None
72
72
_working_tree_dir = None
73
73
git_dir = None
@@ -203,42 +203,14 @@ def __init__(self, path=None, odbt=GitCmdObjectDB, search_parent_directories=Fal
203
203
# END working dir handling
204
204
205
205
self .working_dir = self ._working_tree_dir or self .common_dir
206
+ self .git = self .GitCommandWrapperType (self .working_dir )
206
207
207
208
# special handling, in special times
208
209
args = [osp .join (self .common_dir , 'objects' )]
209
210
if issubclass (odbt , GitCmdObjectDB ):
210
211
args .append (self .git )
211
212
self .odb = odbt (* args )
212
213
213
- def _get_git (self ):
214
- working_dir = self ._working_tree_dir or self .common_dir
215
- if self ._git :
216
- if self ._git ._working_dir != expand_path (working_dir ):
217
- self .close ()
218
- self ._git = None
219
-
220
- if not self ._git :
221
- self ._git = self .GitCommandWrapperType (working_dir )
222
- return self ._git
223
-
224
- def _del_git (self ):
225
- if self ._git :
226
- self ._git .clear_cache ()
227
- self ._git = None
228
- # Tempfiles objects on Windows are holding references to
229
- # open files until they are collected by the garbage
230
- # collector, thus preventing deletion.
231
- # TODO: Find these references and ensure they are closed
232
- # and deleted synchronously rather than forcing a gc
233
- # collection.
234
- if is_win :
235
- gc .collect ()
236
- gitdb .util .mman .collect ()
237
- if is_win :
238
- gc .collect ()
239
-
240
- git = property (fget = _get_git , fdel = _del_git )
241
-
242
214
def __enter__ (self ):
243
215
return self
244
216
@@ -252,7 +224,19 @@ def __del__(self):
252
224
pass
253
225
254
226
def close (self ):
255
- del self .git
227
+ if self .git :
228
+ self .git .clear_cache ()
229
+ # Tempfiles objects on Windows are holding references to
230
+ # open files until they are collected by the garbage
231
+ # collector, thus preventing deletion.
232
+ # TODO: Find these references and ensure they are closed
233
+ # and deleted synchronously rather than forcing a gc
234
+ # collection.
235
+ if is_win :
236
+ gc .collect ()
237
+ gitdb .util .mman .collect ()
238
+ if is_win :
239
+ gc .collect ()
256
240
257
241
def __eq__ (self , rhs ):
258
242
if isinstance (rhs , Repo ):
@@ -448,15 +432,7 @@ def _get_config_path(self, config_level):
448
432
elif config_level == "global" :
449
433
return osp .normpath (osp .expanduser ("~/.gitconfig" ))
450
434
elif config_level == "repository" :
451
- try :
452
- config_path = self .git .rev_parse ("config" , git_path = True )
453
- except GitCommandError :
454
- return osp .normpath (osp .join (self ._common_dir or self .git_dir , "config" ))
455
- else :
456
- if self .git ._working_dir :
457
- return osp .normpath (osp .join (self .git ._working_dir , config_path ))
458
- else :
459
- return config_path
435
+ return osp .normpath (osp .join (self ._common_dir or self .git_dir , "config" ))
460
436
461
437
raise ValueError ("Invalid configuration level: %r" % config_level )
462
438
0 commit comments