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

Honor read-only flag when writing to config backends #4217

Merged
merged 3 commits into from Apr 26, 2017

Conversation

pks-t
Copy link
Member

@pks-t pks-t commented Apr 25, 2017

Configuration backends have a readonly-flag which is currently used to
distinguish configuration snapshots. But somewhat unexpectedly, we do
not use the flag to prevent writing to a readonly backend but happily
proceed to do so.

This commit modifies logic to also honor the readonly flag for
configuration setters. We will now traverse through all backends and
pick the first one which is not marked as read-only whenever we want to
write new configuration.

Implements #4134

The config_file.h header provides some inline declarations accessing the
`git_config_backend`, but misses its declaration. Add the missing
include for "git2/sys/config.h" to add it.
src/config.c Outdated

if (git_vector_length(&cfg->files) == 0) {
giterr_set(GITERR_CONFIG,
"cannot set value for '%s' when no config files exist", name);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I can bikeshed here just a touch, it might be nice to switch this message on whether we're in a set function or in delete_entry.

Configuration backends have a readonly-flag which is currently used to
distinguish configuration snapshots. But somewhat unexpectedly, we do
not use the flag to prevent writing to a readonly backend but happily
proceed to do so.

This commit modifies logic to also honor the readonly flag for
configuration setters. We will now traverse through all backends and
pick the first one which is not marked as read-only whenever we want to
write new configuration.
@pks-t
Copy link
Member Author

pks-t commented Apr 26, 2017

Okay, I've extended the function to accept a use-case. Right now it feels a bit overengineered, so I initially thought about extending the function to also handle the other use cases (lock/unlock and read). It would then be some kind of "get me the right thing for whatever I want to do" function, so it would also honor the readonly flag. But the interface would look horrible. So I refrained from doing so and instead stayed with this version.

@ethomson
Copy link
Member

Seems fine to me. Thanks!

@ethomson ethomson merged commit cecd41f into libgit2:master Apr 26, 2017
@pks-t pks-t deleted the pks/readonly-cfg-backend branch June 6, 2017 07:28
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.

None yet

2 participants