Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitff84b26

Browse files
committed
Refactor try-finally cleanup in git/
This is, in part, to help avoid (or be able to notice) other bugslike the rollback bug that affected SymbolicReference. However, italso includes a simplification of try-(try-except)-finally totry-except-finally.
1 parent592ec84 commitff84b26

File tree

3 files changed

+14
-19
lines changed

3 files changed

+14
-19
lines changed

‎git/config.py

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -406,15 +406,14 @@ def release(self) -> None:
406406
return
407407

408408
try:
409-
try:
410-
self.write()
411-
exceptIOError:
412-
log.error("Exception during destruction of GitConfigParser",exc_info=True)
413-
exceptReferenceError:
414-
# This happens in PY3 ... and usually means that some state cannot be written
415-
# as the sections dict cannot be iterated
416-
# Usually when shutting down the interpreter, don'y know how to fix this
417-
pass
409+
self.write()
410+
exceptIOError:
411+
log.error("Exception during destruction of GitConfigParser",exc_info=True)
412+
exceptReferenceError:
413+
# This happens in PY3 ... and usually means that some state cannot be
414+
# written as the sections dict cannot be iterated
415+
# Usually when shutting down the interpreter, don't know how to fix this
416+
pass
418417
finally:
419418
ifself._lockisnotNone:
420419
self._lock._release_lock()

‎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_pathorself._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-
ifnotok:
233-
lfd.rollback()
229+
exceptBaseException:
230+
lfd.rollback()
231+
raise
234232

235233
lfd.commit()
236234

‎git/refs/symbolic.py

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -370,14 +370,12 @@ def set_reference(
370370

371371
lfd=LockedFD(fpath)
372372
fd=lfd.open(write=True,stream=True)
373-
ok=False
374373
try:
375374
fd.write(write_value.encode("utf-8")+b"\n")
376375
lfd.commit()
377-
ok=True
378-
finally:
379-
ifnotok:
380-
lfd.rollback()
376+
exceptBaseException:
377+
lfd.rollback()
378+
raise
381379
# Adjust the reflog
382380
iflogmsgisnotNone:
383381
self.log_append(oldbinsha,logmsg)

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp