diff options
author | Anil Khatri <anil.soccer.khatri@gmail.com> | 2019-10-23 23:12:14 +0530 |
---|---|---|
committer | Anil Khatri <anil.soccer.khatri@gmail.com> | 2019-10-23 23:12:14 +0530 |
commit | 597fb586347bea58403c0d04ece26de5b6d74423 (patch) | |
tree | 64d67f99f1f123ddf79aea1f33c6f3bfedb9560e /git/refs | |
parent | 5eb8289e80c8b9fe48456e769e0421b7f9972af3 (diff) | |
download | gitpython-597fb586347bea58403c0d04ece26de5b6d74423.tar.gz |
fix File opened without the with statement
Diffstat (limited to 'git/refs')
-rw-r--r-- | git/refs/log.py | 35 |
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. |