Skip to content

Closing file handles/streams #176

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Jul 25, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions git/cmd.py
Original file line number Diff line number Diff line change
Expand Up @@ -382,6 +382,11 @@ def execute(self, command,
finally:
proc.stdout.close()
proc.stderr.close()
if proc.stdin:
proc.stdin.close()
proc.poll()
if proc.returncode is None:
proc.terminate()

if self.GIT_PYTHON_TRACE == 'full':
cmdstr = " ".join(command)
Expand Down
35 changes: 21 additions & 14 deletions git/objects/commit.py
Original file line number Diff line number Diff line change
Expand Up @@ -350,24 +350,31 @@ def _iter_from_process_or_stream(cls, odb, proc_or_stream):
:param proc: git-rev-list process instance - one sha per line
:return: iterator returning Commit objects"""
stream = proc_or_stream
close_std_err = False
if not hasattr(stream,'readline'):
stream = proc_or_stream.stdout
close_std_err = True

readline = stream.readline
while True:
line = readline()
if not line:
break
hexsha = line.strip()
if len(hexsha) > 40:
# split additional information, as returned by bisect for instance
hexsha, rest = line.split(None, 1)
# END handle extra info

assert len(hexsha) == 40, "Invalid line: %s" % hexsha
yield cls(odb, hex_to_bin(hexsha))
# END for each line in stream

try:
while True:
line = readline()
if not line:
break
hexsha = line.strip()
if len(hexsha) > 40:
# split additional information, as returned by bisect for instance
hexsha, rest = line.split(None, 1)
# END handle extra info

assert len(hexsha) == 40, "Invalid line: %s" % hexsha
yield cls(odb, hex_to_bin(hexsha))
# END for each line in stream
finally:
stream.close()
if close_std_err:
proc_or_stream.stderr.close()

#{ Serializable Implementation

def _serialize(self, stream):
Expand Down