Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit0b6b90f

Browse files
bdauvergneByron
authored andcommitted
use git rev-parse to look for config file
1 parentdaa3f35 commit0b6b90f

File tree

2 files changed

+41
-18
lines changed

2 files changed

+41
-18
lines changed

‎git/repo/base.py

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

69-
git=None# Must exist, or __del__ will fail in case we raise on `__init__()`
69+
_git=None# Must exist, or __del__ will fail in case we raise on `__init__()`
7070
working_dir=None
7171
_working_tree_dir=None
7272
git_dir=None
@@ -202,14 +202,42 @@ def __init__(self, path=None, odbt=GitCmdObjectDB, search_parent_directories=Fal
202202
# END working dir handling
203203

204204
self.working_dir=self._working_tree_dirorself.common_dir
205-
self.git=self.GitCommandWrapperType(self.working_dir)
206205

207206
# special handling, in special times
208207
args= [osp.join(self.common_dir,'objects')]
209208
ifissubclass(odbt,GitCmdObjectDB):
210209
args.append(self.git)
211210
self.odb=odbt(*args)
212211

212+
def_get_git(self):
213+
working_dir=self._working_tree_dirorself.common_dir
214+
ifself._git:
215+
ifself._git._working_dir!=expand_path(working_dir):
216+
self.close()
217+
self._git=None
218+
219+
ifnotself._git:
220+
self._git=self.GitCommandWrapperType(working_dir)
221+
returnself._git
222+
223+
def_del_git(self):
224+
ifself._git:
225+
self._git.clear_cache()
226+
self._git=None
227+
# Tempfiles objects on Windows are holding references to
228+
# open files until they are collected by the garbage
229+
# collector, thus preventing deletion.
230+
# TODO: Find these references and ensure they are closed
231+
# and deleted synchronously rather than forcing a gc
232+
# collection.
233+
ifis_win:
234+
gc.collect()
235+
gitdb.util.mman.collect()
236+
ifis_win:
237+
gc.collect()
238+
239+
git=property(fget=_get_git,fdel=_del_git)
240+
213241
def__enter__(self):
214242
returnself
215243

@@ -223,19 +251,7 @@ def __del__(self):
223251
pass
224252

225253
defclose(self):
226-
ifself.git:
227-
self.git.clear_cache()
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-
ifis_win:
235-
gc.collect()
236-
gitdb.util.mman.collect()
237-
ifis_win:
238-
gc.collect()
254+
delself.git
239255

240256
def__eq__(self,rhs):
241257
ifisinstance(rhs,Repo):
@@ -431,7 +447,15 @@ def _get_config_path(self, config_level):
431447
elifconfig_level=="global":
432448
returnosp.normpath(osp.expanduser("~/.gitconfig"))
433449
elifconfig_level=="repository":
434-
returnosp.normpath(osp.join(self._common_dirorself.git_dir,"config"))
450+
try:
451+
config_path=self.git.rev_parse("config",git_path=True)
452+
exceptGitCommandError:
453+
returnosp.normpath(osp.join(self._common_dirorself.git_dir,"config"))
454+
else:
455+
ifself.git._working_dir:
456+
returnosp.normpath(osp.join(self.git._working_dir,config_path))
457+
else:
458+
returnconfig_path
435459

436460
raiseValueError("Invalid configuration level: %r"%config_level)
437461

‎git/test/lib/helper.py

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

367367
@classmethod
368368
deftearDownClass(cls):
369-
cls.rorepo.git.clear_cache()
370-
cls.rorepo.git=None
369+
delcls.rorepo.git
371370

372371
def_make_file(self,rela_path,data,repo=None):
373372
"""

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp