Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix rollback bug in SymbolicReference.set_reference #1675

Merged
merged 3 commits into from
Sep 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading