@@ -217,23 +217,24 @@ def entry_at(cls, filepath, index):
217
217
the index is negative
218
218
"""
219
219
fp = open (filepath , 'rb' )
220
- if index < 0 :
221
- return RefLogEntry .from_line (fp .readlines ()[index ].strip ())
222
- else :
223
- # read until index is reached
224
- for i in xrange (index + 1 ):
225
- line = fp .readline ()
226
- if not line :
227
- break
228
- # END abort on eof
229
- # END handle runup
230
-
231
- if i != index or not line : # skipcq:PYL-W0631
232
- raise IndexError
233
- # END handle exception
234
-
235
- return RefLogEntry .from_line (line .strip ())
236
- # END handle index
220
+ with open (filepath , 'rb' ) as fp :
221
+ if index < 0 :
222
+ return RefLogEntry .from_line (fp .readlines ()[index ].strip ())
223
+ else :
224
+ # read until index is reached
225
+ for i in xrange (index + 1 ):
226
+ line = fp .readline ()
227
+ if not line :
228
+ break
229
+ # END abort on eof
230
+ # END handle runup
231
+
232
+ if i != index or not line : # skipcq:PYL-W0631
233
+ raise IndexError
234
+ # END handle exception
235
+
236
+ return RefLogEntry .from_line (line .strip ())
237
+ # END handle index
237
238
238
239
def to_file (self , filepath ):
239
240
"""Write the contents of the reflog instance to a file at the given filepath.
0 commit comments