Conversation
ethomson
reviewed
Jan 1, 2017
| git_config_get_string(&email, snap_cfg, "user.email"); | ||
| printf("Email: %s\n", email); | ||
| error_code = git_config_get_string(&email, snap_cfg, "user.email"); | ||
| switch (error_code) |
Member
There was a problem hiding this comment.
Instead of copy/pasting this, a macro might clean this up nicely...?
Author
There was a problem hiding this comment.
I did cut and paste tge fragments starting with the "switch". A macro would be a nice way to avoid the duplication, but it will have to take a number of parameters:
- The displayed name of the variable (Autocorrect or Email).
- The variable's type (%d or %s).
- The value of the variable.
- The error message for check_error().
- Maybe "error_code" so the user of the macro could use any name for this variable.
I'll be glad to add a macro if you think that's nicer.
Author
There was a problem hiding this comment.
I was curious how your proposed macro would look so I coded it. I enclose below the macro and its invocations. Is this better than the original?
#define GIT_CFG_ERR_CHK(display_name, format, variable, error_msg, error_code) \
switch (error_code) \
{ \
case 0: \
printf(display_name ": " format "\n", variable); \
break; \
case GIT_ENOTFOUND: \
printf(display_name ": Undefined\n"); \
break; \
default: \
check_error(error_code, error_msg); \
}
error_code = git_config_get_int32(&j, cfg, "help.autocorrect");
GIT_CFG_ERR_CHK("Autocorrect", "%d", j, "get_int32 failed", error_code)
error_code = git_config_get_string(&email, snap_cfg, "user.email");
GIT_CFG_ERR_CHK("Email", "%s", email, "get_string failed", error_code)
Member
|
Sorry, I should have merged this long ago. I don't love the copypasta, but it's superior to the macro for code clarity in an example, I think. Thanks for the contribution! |
Member
|
Merged via #4370 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Prior to this fix config_files() in examples/general.c produced random / incorrect values for "Autocorrect" in its output.
Prior to this fix config_files() did not free its config objects.