Skip to content

Commit d3a24b9

Browse files
committed
fixing file descriptor leaks
using GitCmdObjectDB when initiating repo(suggestion of library creator; gitpython-developers/GitPython#60 (comment) ; for the future may be better to use newer version of the library)
1 parent d800167 commit d3a24b9

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

src/jens/git_wrapper.py

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -28,14 +28,15 @@ def gc(repository_path, aggressive=False, bare=False):
2828

2929
@git_exec
3030
def gc_exec(*args, **kwargs):
31-
repo = git.Repo(repository_path)
31+
repo = git.Repo(repository_path, odbt=git.GitCmdObjectDB)
3232
repo.git.gc(*args, **kwargs)
3333

3434
gc_exec(name='gc', args=args, kwargs=kwargs)
3535

3636
def clone(repository_path, url, bare=False, shared=False, branch=None):
3737
args = [url, repository_path]
38-
kwargs = {"no-hardlinks": True, "shared": shared}
38+
kwargs = {"no-hardlinks": True, "shared": shared,
39+
"odbt": git.GitCmdObjectDB}
3940
logging.debug("Cloning from %s to %s" % (url, repository_path))
4041
if bare is True:
4142
kwargs["bare"] = True
@@ -56,7 +57,8 @@ def fetch(repository_path, prune=False):
5657

5758
@git_exec
5859
def fetch_exec(*args, **kwargs):
59-
git.Repo(repository_path).remotes.origin.fetch(*args, **kwargs)
60+
repo = git.Repo(repository_path, odbt=git.GitCmdObjectDB)
61+
repo.remotes.origin.fetch(*args, **kwargs)
6062

6163
fetch_exec(name='fetch', args=args, kwargs=kwargs)
6264

@@ -67,7 +69,8 @@ def reset(repository_path, treeish, hard=False):
6769

6870
@git_exec
6971
def reset_exec(*args, **kwargs):
70-
git.refs.head.HEAD(git.Repo(repository_path)).reset(*args, **kwargs)
72+
repo = git.Repo(repository_path, odbt=git.GitCmdObjectDB)
73+
git.refs.head.HEAD(repo).reset(*args, **kwargs)
7174

7275
reset_exec(name='reset', args=args, kwargs=kwargs)
7376

@@ -77,6 +80,8 @@ def get_refs(repository_path):
7780

7881
@git_exec
7982
def get_refs_exec(*args, **kwargs):
80-
return dict((h.name, h.commit.hexsha) for h in git.Repo(repository_path).heads)
83+
r = dict((h.name, h.commit.hexsha) for h in git.Repo(repository_path,
84+
odbt=git.GitCmdObjectDB).heads)
85+
return r
8186

8287
return get_refs_exec(name='show-ref', args=args, kwargs=kwargs)

0 commit comments

Comments
 (0)