summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2014-07-25 09:53:11 +0200
committerSebastian Thiel <byronimo@gmail.com>2014-07-25 09:53:11 +0200
commit22a2103cf550d141b1e2a82877b9a5de64700210 (patch)
tree1fc87b4b6a2b43a9c80c928b0a13df66d62be103
parentad715a0bceaa0d9e51a9c446a718152df4396de2 (diff)
parentd68ffc3a480d4b67dd11bf3ab4485c0e7ab789e3 (diff)
downloadgitpython-22a2103cf550d141b1e2a82877b9a5de64700210.tar.gz
Merge pull request #176 from craigez/feature/file_closing
Closing file handles/streams
-rw-r--r--git/cmd.py5
-rw-r--r--git/objects/commit.py35
2 files changed, 26 insertions, 14 deletions
diff --git a/git/cmd.py b/git/cmd.py
index 1d9b4efb..cbbd0a7a 100644
--- a/git/cmd.py
+++ b/git/cmd.py
@@ -382,6 +382,11 @@ class Git(LazyMixin):
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)
diff --git a/git/objects/commit.py b/git/objects/commit.py
index f9923e4d..e64d4da3 100644
--- a/git/objects/commit.py
+++ b/git/objects/commit.py
@@ -350,24 +350,31 @@ class Commit(Diffable, Iterable, RepoAliasMixin, base.Object, Traversable, Seria
: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):