From 597fb586347bea58403c0d04ece26de5b6d74423 Mon Sep 17 00:00:00 2001 From: Anil Khatri Date: Wed, 23 Oct 2019 23:12:14 +0530 Subject: fix File opened without the with statement --- git/refs/log.py | 35 ++++++++++++++++++----------------- 1 file changed, 18 insertions(+), 17 deletions(-) (limited to 'git/refs/log.py') 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. -- cgit v1.2.1