summaryrefslogtreecommitdiff
path: root/git/repo/base.py
diff options
context:
space:
mode:
authorKostis Anagnostopoulos <ankostis@gmail.com>2016-10-01 12:58:54 +0200
committerKostis Anagnostopoulos <ankostis@gmail.com>2016-10-01 13:02:53 +0200
commita79cf677744e2c1721fa55f934fa07034bc54b0a (patch)
treeac4bc1ae7d58cab6735633a66dc9b4fb437a8cea /git/repo/base.py
parent13d399f4460ecb17cecc59d7158a4159010b2ac5 (diff)
downloadgitpython-a79cf677744e2c1721fa55f934fa07034bc54b0a.tar.gz
repo-TCs, #519: FIX config resource leaks
+ Modify lock/read-config-file code to ensure files closed. + Use `with GitConfigarser()` more systematically in TCs. + Clear any locks left hanging from prev Tcs. + Util: mark lock-files as SHORT_LIVED; save some SSDs...
Diffstat (limited to 'git/repo/base.py')
-rw-r--r--git/repo/base.py18
1 files changed, 6 insertions, 12 deletions
diff --git a/git/repo/base.py b/git/repo/base.py
index 2a56eaed..9cc70571 100644
--- a/git/repo/base.py
+++ b/git/repo/base.py
@@ -210,11 +210,13 @@ class Repo(object):
# Description property
def _get_description(self):
filename = join(self.git_dir, 'description')
- return open(filename, 'rb').read().rstrip().decode(defenc)
+ with open(filename, 'rb') as fp:
+ return fp.read().rstrip().decode(defenc)
def _set_description(self, descr):
filename = join(self.git_dir, 'description')
- open(filename, 'wb').write((descr + '\n').encode(defenc))
+ with open(filename, 'wb') as fp:
+ fp.write((descr + '\n').encode(defenc))
description = property(_get_description, _set_description,
doc="the project's description")
@@ -548,11 +550,8 @@ class Repo(object):
alternates_path = join(self.git_dir, 'objects', 'info', 'alternates')
if os.path.exists(alternates_path):
- try:
- f = open(alternates_path, 'rb')
+ with open(alternates_path, 'rb') as f:
alts = f.read().decode(defenc)
- finally:
- f.close()
return alts.strip().splitlines()
else:
return list()
@@ -573,13 +572,8 @@ class Repo(object):
if isfile(alternates_path):
os.remove(alternates_path)
else:
- try:
- f = open(alternates_path, 'wb')
+ with open(alternates_path, 'wb') as f:
f.write("\n".join(alts).encode(defenc))
- finally:
- f.close()
- # END file handling
- # END alts handling
alternates = property(_get_alternates, _set_alternates,
doc="Retrieve a list of alternates paths or set a list paths to be used as alternates")