Skip to content

Commit

Permalink
Merge pull request #1675 from EliahKagan/rollback
Browse files Browse the repository at this point in the history
Fix rollback bug in SymbolicReference.set_reference
  • Loading branch information
Byron authored Sep 21, 2023
2 parents d1c1f31 + e480985 commit d40320b
Show file tree
Hide file tree
Showing 4 changed files with 15 additions and 21 deletions.
17 changes: 8 additions & 9 deletions git/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -406,15 +406,14 @@ def release(self) -> None:
return

try:
try:
self.write()
except IOError:
log.error("Exception during destruction of GitConfigParser", exc_info=True)
except ReferenceError:
# This happens in PY3 ... and usually means that some state cannot be written
# as the sections dict cannot be iterated
# Usually when shutting down the interpreter, don'y know how to fix this
pass
self.write()
except IOError:
log.error("Exception during destruction of GitConfigParser", exc_info=True)
except ReferenceError:
# This happens in PY3 ... and usually means that some state cannot be
# written as the sections dict cannot be iterated
# Usually when shutting down the interpreter, don't know how to fix this
pass
finally:
if self._lock is not None:
self._lock._release_lock()
Expand Down
8 changes: 3 additions & 5 deletions git/index/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -224,13 +224,11 @@ def write(
lfd = LockedFD(file_path or self._file_path)
stream = lfd.open(write=True, stream=True)

ok = False
try:
self._serialize(stream, ignore_extension_data)
ok = True
finally:
if not ok:
lfd.rollback()
except BaseException:
lfd.rollback()
raise

lfd.commit()

Expand Down
3 changes: 1 addition & 2 deletions git/refs/log.py
Original file line number Diff line number Diff line change
Expand Up @@ -262,8 +262,7 @@ def to_file(self, filepath: PathLike) -> None:
try:
self._serialize(fp)
lfd.commit()
except Exception:
# on failure it rolls back automatically, but we make it clear
except BaseException:
lfd.rollback()
raise
# END handle change
Expand Down
8 changes: 3 additions & 5 deletions git/refs/symbolic.py
Original file line number Diff line number Diff line change
Expand Up @@ -370,14 +370,12 @@ def set_reference(

lfd = LockedFD(fpath)
fd = lfd.open(write=True, stream=True)
ok = True
try:
fd.write(write_value.encode("utf-8") + b"\n")
lfd.commit()
ok = True
finally:
if not ok:
lfd.rollback()
except BaseException:
lfd.rollback()
raise
# Adjust the reflog
if logmsg is not None:
self.log_append(oldbinsha, logmsg)
Expand Down

0 comments on commit d40320b

Please sign in to comment.