Skip to content

Commit

Permalink
Merge pull request #1532 from marlamb/feature/reduce-resource-leaks
Browse files Browse the repository at this point in the history
Fix some resource leaks by open file handles
  • Loading branch information
Byron authored Jan 9, 2023
2 parents 27a283b + e500466 commit 90c81a5
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
9 changes: 7 additions & 2 deletions git/repo/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,9 @@
import re
import shlex
import warnings

from pathlib import Path

from gitdb.db.loose import LooseObjectDB

from gitdb.exc import BadObject
Expand Down Expand Up @@ -268,7 +271,7 @@ def __init__(
pass

try:
common_dir = open(osp.join(self.git_dir, "commondir"), "rt").readlines()[0].strip()
common_dir = (Path(self.git_dir) / "commondir").read_text().splitlines()[0].strip()
self._common_dir = osp.join(self.git_dir, common_dir)
except OSError:
self._common_dir = ""
Expand Down Expand Up @@ -1385,4 +1388,6 @@ def currently_rebasing_on(self) -> Commit | None:
rebase_head_file = osp.join(self.git_dir, "REBASE_HEAD")
if not osp.isfile(rebase_head_file):
return None
return self.commit(open(rebase_head_file, "rt").readline().strip())
with open(rebase_head_file, "rt") as f:
content = f.readline().strip()
return self.commit(content)
3 changes: 2 additions & 1 deletion git/repo/fun.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from __future__ import annotations
import os
import stat
from pathlib import Path
from string import digits

from git.exc import WorkTreeRepositoryUnsupported
Expand Down Expand Up @@ -83,7 +84,7 @@ def find_worktree_git_dir(dotgit: "PathLike") -> Optional[str]:
return None

try:
lines = open(dotgit, "r").readlines()
lines = Path(dotgit).read_text().splitlines()
for key, value in [line.strip().split(": ") for line in lines]:
if key == "gitdir":
return value
Expand Down

0 comments on commit 90c81a5

Please sign in to comment.