Skip to content

Commit

Permalink
Fix performance regression, see #906
Browse files Browse the repository at this point in the history
Revert "use git rev-parse to look for config file"

This reverts commit 0b6b90f.

Fix #906
Reopen #719
  • Loading branch information
Sebastian Thiel committed Aug 14, 2019
1 parent 5fa99bf commit d5cc590
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 41 deletions.
56 changes: 16 additions & 40 deletions git/repo/base.py
Expand Up @@ -67,7 +67,7 @@ class Repo(object):
'git_dir' is the .git repository directory, which is always set."""
DAEMON_EXPORT_FILE = 'git-daemon-export-ok'

_git = None # Must exist, or __del__ will fail in case we raise on `__init__()`
git = None # Must exist, or __del__ will fail in case we raise on `__init__()`
working_dir = None
_working_tree_dir = None
git_dir = None
Expand Down Expand Up @@ -203,42 +203,14 @@ def __init__(self, path=None, odbt=GitCmdObjectDB, search_parent_directories=Fal
# END working dir handling

self.working_dir = self._working_tree_dir or self.common_dir
self.git = self.GitCommandWrapperType(self.working_dir)

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

def _get_git(self):
working_dir = self._working_tree_dir or self.common_dir
if self._git:
if self._git._working_dir != expand_path(working_dir):
self.close()
self._git = None

if not self._git:
self._git = self.GitCommandWrapperType(working_dir)
return self._git

def _del_git(self):
if self._git:
self._git.clear_cache()
self._git = None
# Tempfiles objects on Windows are holding references to
# open files until they are collected by the garbage
# collector, thus preventing deletion.
# TODO: Find these references and ensure they are closed
# and deleted synchronously rather than forcing a gc
# collection.
if is_win:
gc.collect()
gitdb.util.mman.collect()
if is_win:
gc.collect()

git = property(fget=_get_git, fdel=_del_git)

def __enter__(self):
return self

Expand All @@ -252,7 +224,19 @@ def __del__(self):
pass

def close(self):
del self.git
if self.git:
self.git.clear_cache()
# Tempfiles objects on Windows are holding references to
# open files until they are collected by the garbage
# collector, thus preventing deletion.
# TODO: Find these references and ensure they are closed
# and deleted synchronously rather than forcing a gc
# collection.
if is_win:
gc.collect()
gitdb.util.mman.collect()
if is_win:
gc.collect()

def __eq__(self, rhs):
if isinstance(rhs, Repo):
Expand Down Expand Up @@ -448,15 +432,7 @@ def _get_config_path(self, config_level):
elif config_level == "global":
return osp.normpath(osp.expanduser("~/.gitconfig"))
elif config_level == "repository":
try:
config_path = self.git.rev_parse("config", git_path=True)
except GitCommandError:
return osp.normpath(osp.join(self._common_dir or self.git_dir, "config"))
else:
if self.git._working_dir:
return osp.normpath(osp.join(self.git._working_dir, config_path))
else:
return config_path
return osp.normpath(osp.join(self._common_dir or self.git_dir, "config"))

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

Expand Down
3 changes: 2 additions & 1 deletion git/test/lib/helper.py
Expand Up @@ -366,7 +366,8 @@ def setUpClass(cls):

@classmethod
def tearDownClass(cls):
del cls.rorepo.git
cls.rorepo.git.clear_cache()
cls.rorepo.git = None

def _make_file(self, rela_path, data, repo=None):
"""
Expand Down

0 comments on commit d5cc590

Please sign in to comment.