summaryrefslogtreecommitdiff
path: root/git/refs
diff options
context:
space:
mode:
authorAnil Khatri <anil.soccer.khatri@gmail.com>2019-10-23 23:12:14 +0530
committerAnil Khatri <anil.soccer.khatri@gmail.com>2019-10-23 23:12:14 +0530
commit597fb586347bea58403c0d04ece26de5b6d74423 (patch)
tree64d67f99f1f123ddf79aea1f33c6f3bfedb9560e /git/refs
parent5eb8289e80c8b9fe48456e769e0421b7f9972af3 (diff)
downloadgitpython-597fb586347bea58403c0d04ece26de5b6d74423.tar.gz
fix File opened without the with statement
Diffstat (limited to 'git/refs')
-rw-r--r--git/refs/log.py35
1 files changed, 18 insertions, 17 deletions
diff --git a/git/refs/log.py b/git/refs/log.py
index 01673ae0..bc6d4486 100644
--- a/git/refs/log.py
+++ b/git/refs/log.py
@@ -217,23 +217,24 @@ class RefLog(list, Serializable):
the index is negative
"""
fp = open(filepath, 'rb')
- if index < 0:
- return RefLogEntry.from_line(fp.readlines()[index].strip())
- else:
- # read until index is reached
- for i in xrange(index + 1):
- line = fp.readline()
- if not line:
- break
- # END abort on eof
- # END handle runup
-
- if i != index or not line: # skipcq:PYL-W0631
- raise IndexError
- # END handle exception
-
- return RefLogEntry.from_line(line.strip())
- # END handle index
+ with open(filepath, 'rb') as fp:
+ if index < 0:
+ return RefLogEntry.from_line(fp.readlines()[index].strip())
+ else:
+ # read until index is reached
+ for i in xrange(index + 1):
+ line = fp.readline()
+ if not line:
+ break
+ # END abort on eof
+ # END handle runup
+
+ if i != index or not line: # skipcq:PYL-W0631
+ raise IndexError
+ # END handle exception
+
+ return RefLogEntry.from_line(line.strip())
+ # END handle index
def to_file(self, filepath):
"""Write the contents of the reflog instance to a file at the given filepath.