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

Appearance settings

Commit e500466

Browse filesBrowse files
author
Martin Lambertsen
committed
Fix some resource leaks by open file handles
1 parent 27a283b commit e500466
Copy full SHA for e500466

2 files changed

+9-3Lines changed: 9 additions & 3 deletions

File tree

Expand file treeCollapse file tree
Open diff view settings
Filter options
Expand file treeCollapse file tree
Open diff view settings
Collapse file

‎git/repo/base.py‎

Copy file name to clipboardExpand all lines: git/repo/base.py
+7-2Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@
99
import re
1010
import shlex
1111
import warnings
12+
13+
from pathlib import Path
14+
1215
from gitdb.db.loose import LooseObjectDB
1316

1417
from gitdb.exc import BadObject
@@ -268,7 +271,7 @@ def __init__(
268271
pass
269272

270273
try:
271-
common_dir = open(osp.join(self.git_dir, "commondir"), "rt").readlines()[0].strip()
274+
common_dir = (Path(self.git_dir) / "commondir").read_text().splitlines()[0].strip()
272275
self._common_dir = osp.join(self.git_dir, common_dir)
273276
except OSError:
274277
self._common_dir = ""
@@ -1385,4 +1388,6 @@ def currently_rebasing_on(self) -> Commit | None:
13851388
rebase_head_file = osp.join(self.git_dir, "REBASE_HEAD")
13861389
if not osp.isfile(rebase_head_file):
13871390
return None
1388-
return self.commit(open(rebase_head_file, "rt").readline().strip())
1391+
with open(rebase_head_file, "rt") as f:
1392+
content = f.readline().strip()
1393+
return self.commit(content)
Collapse file

‎git/repo/fun.py‎

Copy file name to clipboardExpand all lines: git/repo/fun.py
+2-1Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from __future__ import annotations
33
import os
44
import stat
5+
from pathlib import Path
56
from string import digits
67

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

8586
try:
86-
lines = open(dotgit, "r").readlines()
87+
lines = Path(dotgit).read_text().splitlines()
8788
for key, value in [line.strip().split(": ") for line in lines]:
8889
if key == "gitdir":
8990
return value

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.