Skip to content

Commit d5cc590

Browse files
author
Sebastian Thiel
committed
Fix performance regression, see gitpython-developers#906
Revert "use git rev-parse to look for config file" This reverts commit 0b6b90f. Fix gitpython-developers#906 Reopen gitpython-developers#719
1 parent 5fa99bf commit d5cc590

File tree

2 files changed

+18
-41
lines changed

2 files changed

+18
-41
lines changed

git/repo/base.py

Lines changed: 16 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,7 @@ class Repo(object):
6767
'git_dir' is the .git repository directory, which is always set."""
6868
DAEMON_EXPORT_FILE = 'git-daemon-export-ok'
6969

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__()`
7171
working_dir = None
7272
_working_tree_dir = None
7373
git_dir = None
@@ -203,42 +203,14 @@ def __init__(self, path=None, odbt=GitCmdObjectDB, search_parent_directories=Fal
203203
# END working dir handling
204204

205205
self.working_dir = self._working_tree_dir or self.common_dir
206+
self.git = self.GitCommandWrapperType(self.working_dir)
206207

207208
# special handling, in special times
208209
args = [osp.join(self.common_dir, 'objects')]
209210
if issubclass(odbt, GitCmdObjectDB):
210211
args.append(self.git)
211212
self.odb = odbt(*args)
212213

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-
242214
def __enter__(self):
243215
return self
244216

@@ -252,7 +224,19 @@ def __del__(self):
252224
pass
253225

254226
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()
256240

257241
def __eq__(self, rhs):
258242
if isinstance(rhs, Repo):
@@ -448,15 +432,7 @@ def _get_config_path(self, config_level):
448432
elif config_level == "global":
449433
return osp.normpath(osp.expanduser("~/.gitconfig"))
450434
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"))
460436

461437
raise ValueError("Invalid configuration level: %r" % config_level)
462438

git/test/lib/helper.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -366,7 +366,8 @@ def setUpClass(cls):
366366

367367
@classmethod
368368
def tearDownClass(cls):
369-
del cls.rorepo.git
369+
cls.rorepo.git.clear_cache()
370+
cls.rorepo.git = None
370371

371372
def _make_file(self, rela_path, data, repo=None):
372373
"""

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy