Refactor try-finally cleanup in git/ · gitpython-developers/GitPython@ff84b26 · GitHub
Skip to content

Commit ff84b26

Browse files
committed
Refactor try-finally cleanup in git/
This is, in part, to help avoid (or be able to notice) other bugs like the rollback bug that affected SymbolicReference. However, it also includes a simplification of try-(try-except)-finally to try-except-finally.
1 parent 592ec84 commit ff84b26

3 files changed

Lines changed: 14 additions & 19 deletions

File tree

git/config.py

Lines changed: 8 additions & 9 deletions

git/index/base.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -224,13 +224,11 @@ def write(
224224
lfd = LockedFD(file_path or self._file_path)
225225
stream = lfd.open(write=True, stream=True)
226226

227-
ok = False
228227
try:
229228
self._serialize(stream, ignore_extension_data)
230-
ok = True
231-
finally:
232-
if not ok:
233-
lfd.rollback()
229+
except BaseException:
230+
lfd.rollback()
231+
raise
234232

235233
lfd.commit()
236234

git/refs/symbolic.py

Lines changed: 3 additions & 5 deletions

0 commit comments

Comments
 (0)