From: Martin Ågren Date: Sun, 05 Nov 2017 11:58:20 GMT Subject: [PATCH 2/4] pager: refactor `pager_command_config()` Message-ID: <2b0f8f5c1f42f7a85d8017ca378de8acde2688a3.1509879269.git.martin.agren@gmail.com> In-Reply-To: `pager_command_config()` checks for the config `pager.`. In the next commit, we will want to also look for some strings on the form `pager..foo`. Refactor the code to verify upfront that the string starts with "pager." and then check that the remainder is the empty string. This makes it easy to look for other remainders in the next patch. While at it, before assigning to `value`, free any old value we might already have picked up. Signed-off-by: Martin Ågren --- pager.c | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/pager.c b/pager.c index 92b23e6cd..8968f26f1 100644 --- a/pager.c +++ b/pager.c @@ -191,14 +191,19 @@ struct pager_command_config_data { static int pager_command_config(const char *var, const char *value, void *vdata) { struct pager_command_config_data *data = vdata; - const char *cmd; + const char *cmd, *remainder; + + if (!skip_prefix(var, "pager.", &cmd) || + !skip_prefix(cmd, data->cmd, &remainder)) + return 0; - if (skip_prefix(var, "pager.", &cmd) && !strcmp(cmd, data->cmd)) { + if (!*remainder) { int b = git_parse_maybe_bool(value); if (b >= 0) data->want = b; else { data->want = 1; + free(data->value); data->value = xstrdup(value); } } -- 2.15.0.415.gac1375d7e