Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit 597fb58

Browse files
committed
fix File opened without the with statement
1 parent 5eb8289 commit 597fb58

File tree

1 file changed

+18
-17
lines changed

1 file changed

+18
-17
lines changed

‎git/refs/log.py

Lines changed: 18 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -217,23 +217,24 @@ def entry_at(cls, filepath, index):
217217
the index is negative
218218
"""
219219
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
237238

238239
def to_file(self, filepath):
239240
"""Write the contents of the reflog instance to a file at the given filepath.

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /