use open context managers in more places
Use open() as a context manager to simplify the close logic and make
the code easier to read & understand. This is also more Pythonic.
Change-Id: I579d03cca86f99b2c6c6a1f557f6e5704e2515a7
Reviewed-on: https://gerrit-review.googlesource.com/c/git-repo/+/244734
Reviewed-by: David Pursehouse <dpursehouse@collab.net>
Tested-by: Mike Frysinger <vapier@google.com>
diff --git a/git_refs.py b/git_refs.py
index 98ed1e2..debd4cb 100644
--- a/git_refs.py
+++ b/git_refs.py
@@ -141,18 +141,11 @@
def _ReadLoose1(self, path, name):
try:
- fd = open(path)
- except IOError:
- return
-
- try:
- try:
+ with open(path) as fd:
mtime = os.path.getmtime(path)
ref_id = fd.readline()
- except (IOError, OSError):
- return
- finally:
- fd.close()
+ except (IOError, OSError):
+ return
try:
ref_id = ref_id.decode()