diff options
author | Craig Northway <craig.northway@gmail.com> | 2014-07-25 12:13:16 +1000 |
---|---|---|
committer | Craig Northway <craig.northway@gmail.com> | 2014-07-25 14:49:24 +1000 |
commit | d68ffc3a480d4b67dd11bf3ab4485c0e7ab789e3 (patch) | |
tree | 1fc87b4b6a2b43a9c80c928b0a13df66d62be103 /git/objects/commit.py | |
parent | ad715a0bceaa0d9e51a9c446a718152df4396de2 (diff) | |
download | gitpython-d68ffc3a480d4b67dd11bf3ab4485c0e7ab789e3.tar.gz |
Closing file handles/streams
Diffstat (limited to 'git/objects/commit.py')
-rw-r--r-- | git/objects/commit.py | 35 |
1 files changed, 21 insertions, 14 deletions
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): |