summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSebastian Thiel <byronimo@gmail.com>2015-07-27 10:56:51 +0200
committerSebastian Thiel <byronimo@gmail.com>2015-07-27 10:56:51 +0200
commit7c96f5885e1ec1e24b0f8442610de42bd8e168d0 (patch)
tree6322e87014a278da898083d34618eee16dd480d3
parent11b3a1dfc2eb03094c4c437162ce504722fa7ddf (diff)
parent58c5b993d218c0ebc3f610c2e55a14b194862e1c (diff)
downloadgitpython-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.py34
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