diff options
author | Sebastian Thiel <byronimo@gmail.com> | 2015-07-27 10:56:51 +0200 |
---|---|---|
committer | Sebastian Thiel <byronimo@gmail.com> | 2015-07-27 10:56:51 +0200 |
commit | 7c96f5885e1ec1e24b0f8442610de42bd8e168d0 (patch) | |
tree | 6322e87014a278da898083d34618eee16dd480d3 | |
parent | 11b3a1dfc2eb03094c4c437162ce504722fa7ddf (diff) | |
parent | 58c5b993d218c0ebc3f610c2e55a14b194862e1c (diff) | |
download | gitpython-7c96f5885e1ec1e24b0f8442610de42bd8e168d0.tar.gz |
Merge pull request #326 from vokimon/packed-refs-releasing-resources-patch-1
Ensure file resources are released
-rw-r--r-- | git/refs/symbolic.py | 34 |
1 files changed, 17 insertions, 17 deletions
diff --git a/git/refs/symbolic.py b/git/refs/symbolic.py index d884250f..f3799ed4 100644 --- a/git/refs/symbolic.py +++ b/git/refs/symbolic.py @@ -88,25 +88,25 @@ class SymbolicReference(object): """Returns an iterator yielding pairs of sha1/path pairs (as bytes) for the corresponding refs. :note: The packed refs file will be kept open as long as we iterate""" try: - fp = open(cls._get_packed_refs_path(repo), 'rt') - for line in fp: - line = line.strip() - if not line: - continue - if line.startswith('#'): - if line.startswith('# pack-refs with:') and not line.endswith('peeled'): - raise TypeError("PackingType of packed-Refs not understood: %r" % line) - # END abort if we do not understand the packing scheme - continue - # END parse comment + with open(cls._get_packed_refs_path(repo), 'rt') as fp: + for line in fp: + line = line.strip() + if not line: + continue + if line.startswith('#'): + if line.startswith('# pack-refs with:') and not line.endswith('peeled'): + raise TypeError("PackingType of packed-Refs not understood: %r" % line) + # END abort if we do not understand the packing scheme + continue + # END parse comment - # skip dereferenced tag object entries - previous line was actual - # tag reference for it - if line[0] == '^': - continue + # skip dereferenced tag object entries - previous line was actual + # tag reference for it + if line[0] == '^': + continue - yield tuple(line.split(' ', 1)) - # END for each line + yield tuple(line.split(' ', 1)) + # END for each line except (OSError, IOError): raise StopIteration # END no packed-refs file handling |