Skip to content

refdb_fs: refactor error handling in refdb_reflog_fs__delete#4915

Merged
ethomson merged 1 commit intolibgit2:masterfrom
pks-t:pks/refdb-minor-refactorings
Dec 19, 2018
Merged

refdb_fs: refactor error handling in refdb_reflog_fs__delete#4915
ethomson merged 1 commit intolibgit2:masterfrom
pks-t:pks/refdb-minor-refactorings

Conversation

@pks-t
Copy link
Copy Markdown
Member

@pks-t pks-t commented Dec 19, 2018

The function refdb_reflog_fs__delete uses the if (!error && foobar())
pattern of checking, where error conditions are being checked by following calls
to different code. This does not match our current style, where the call-site of
a function is usually directly responsible for checking the return value.

Convert the function to use if ((error = foobar()) < 0) goto out; style. Note
that this changes the code flow a bit: previously, we were always trying to
delete empty reference hierarchies even if deleting the reflog entry has failed.
This wasn't much of a problem -- if deletion failed, the hierarchy will still
contain at least one file and thus the function call was an expensive no-op.
Now, we will only perform this deletion if we have successfully removed the
reflog.

The function `refdb_reflog_fs__delete` uses the `if (!error && foobar())`
pattern of checking, where error conditions are being checked by following calls
to different code. This does not match our current style, where the call-site of
a function is usually directly responsible for checking the return value.

Convert the function to use `if ((error = foobar()) < 0) goto out;` style. Note
that this changes the code flow a bit: previously, we were always trying to
delete empty reference hierarchies even if deleting the reflog entry has failed.
This wasn't much of a problem -- if deletion failed, the hierarchy will still
contain at least one file and thus the function call was an expensive no-op.
Now, we will only perform this deletion if we have successfully removed the
reflog.
@pks-t pks-t force-pushed the pks/refdb-minor-refactorings branch from 142f35b to 8dde7e1 Compare December 19, 2018 11:30
@ethomson ethomson merged commit 77f1460 into libgit2:master Dec 19, 2018
@ethomson
Copy link
Copy Markdown
Member

👍

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants