config: replace 'value_regex' with 'value_pattern'

The 'value_regex' argument in the 'git config' builtin is poorly named, especially related to an upcoming change that allows exact string matches instead of ERE pattern matches. Perform a mostly mechanical change of every instance of 'value_regex' to 'value_pattern' in the codebase. This is only critical for documentation and error messages, but it is best to be consistent inside the codebase, too. For documentation, use 'value-pattern' which is better punctuation. This affects Documentation/git-config.txt and the usage in builtin/config.c, which was already mixed between 'value_regex' and 'value-regex'. I gave some thought to leaving the value_regex variables inside config.c that are regex_t pointers. However, it is probably best to keep the name consistent with the rest of the variables. This does not update the translations inside the po/ directory, as that creates conflicts with ongoing work. The input strings should automatically update through automation, and a few of the output strings currently use "[value_regex]" directly. Signed-off-by: Derrick Stolee <dstolee@microsoft.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Derrick Stolee committed Nov 25, 2020 at 22:12 UTC 247e2f822e6ccdccaa19ca1a54d4082ce5d819e7
4 files changed +44 -44
Documentation/git-config.txt
+10 -10
@@ -9,15 +9,15 @@ git-config - Get and set repository or global options
9 SYNOPSIS
10 --------
11 [verse]
12 -'git config' [<file-option>] [--type=<type>] [--show-origin] [--show-scope] [-z|--null] name [value [value_regex]]
12 +'git config' [<file-option>] [--type=<type>] [--show-origin] [--show-scope] [-z|--null] name [value [value-pattern]]
13 'git config' [<file-option>] [--type=<type>] --add name value
14 -'git config' [<file-option>] [--type=<type>] --replace-all name value [value_regex]
15 -'git config' [<file-option>] [--type=<type>] [--show-origin] [--show-scope] [-z|--null] --get name [value_regex]
16 -'git config' [<file-option>] [--type=<type>] [--show-origin] [--show-scope] [-z|--null] --get-all name [value_regex]
17 -'git config' [<file-option>] [--type=<type>] [--show-origin] [--show-scope] [-z|--null] [--name-only] --get-regexp name_regex [value_regex]
14 +'git config' [<file-option>] [--type=<type>] --replace-all name value [value-pattern]
15 +'git config' [<file-option>] [--type=<type>] [--show-origin] [--show-scope] [-z|--null] --get name [value-pattern]
16 +'git config' [<file-option>] [--type=<type>] [--show-origin] [--show-scope] [-z|--null] --get-all name [value-pattern]
17 +'git config' [<file-option>] [--type=<type>] [--show-origin] [--show-scope] [-z|--null] [--name-only] --get-regexp name_regex [value-pattern]
18 'git config' [<file-option>] [--type=<type>] [-z|--null] --get-urlmatch name URL
19 -'git config' [<file-option>] --unset name [value_regex]
20 -'git config' [<file-option>] --unset-all name [value_regex]
19 +'git config' [<file-option>] --unset name [value-pattern]
20 +'git config' [<file-option>] --unset-all name [value-pattern]
21 'git config' [<file-option>] --rename-section old_name new_name
22 'git config' [<file-option>] --remove-section name
23 'git config' [<file-option>] [--show-origin] [--show-scope] [-z|--null] [--name-only] -l | --list
@@ -33,7 +33,7 @@ escaped.
33
34 Multiple lines can be added to an option by using the `--add` option.
35 If you want to update or unset an option which can occur on multiple
36 -lines, a POSIX regexp `value_regex` needs to be given. Only the
36 +lines, a POSIX regexp `value-pattern` needs to be given. Only the
37 existing values that match the regexp are updated or unset. If
38 you want to handle the lines that do *not* match the regex, just
39 prepend a single exclamation mark in front (see also <<EXAMPLES>>).
@@ -73,11 +73,11 @@ OPTIONS
73
74 --replace-all::
75 Default behavior is to replace at most one line. This replaces
76 - all lines matching the key (and optionally the value_regex).
76 + all lines matching the key (and optionally the `value-pattern`).
77
78 --add::
79 Adds a new line to the option without altering any existing
80 - values. This is the same as providing '^$' as the value_regex
80 + values. This is the same as providing '^$' as the `value-pattern`
81 in `--replace-all`.
82
83 --get::
builtin/config.c
+6 -6
@@ -133,14 +133,14 @@ static struct option builtin_config_options[] = {
133 OPT_STRING('f', "file", &given_config_source.file, N_("file"), N_("use given config file")),
134 OPT_STRING(0, "blob", &given_config_source.blob, N_("blob-id"), N_("read config from given blob object")),
135 OPT_GROUP(N_("Action")),
136 - OPT_BIT(0, "get", &actions, N_("get value: name [value-regex]"), ACTION_GET),
137 - OPT_BIT(0, "get-all", &actions, N_("get all values: key [value-regex]"), ACTION_GET_ALL),
138 - OPT_BIT(0, "get-regexp", &actions, N_("get values for regexp: name-regex [value-regex]"), ACTION_GET_REGEXP),
136 + OPT_BIT(0, "get", &actions, N_("get value: name [value-pattern]"), ACTION_GET),
137 + OPT_BIT(0, "get-all", &actions, N_("get all values: key [value-pattern]"), ACTION_GET_ALL),
138 + OPT_BIT(0, "get-regexp", &actions, N_("get values for regexp: name-regex [value-pattern]"), ACTION_GET_REGEXP),
139 OPT_BIT(0, "get-urlmatch", &actions, N_("get value specific for the URL: section[.var] URL"), ACTION_GET_URLMATCH),
140 - OPT_BIT(0, "replace-all", &actions, N_("replace all matching variables: name value [value_regex]"), ACTION_REPLACE_ALL),
140 + OPT_BIT(0, "replace-all", &actions, N_("replace all matching variables: name value [value-pattern]"), ACTION_REPLACE_ALL),
141 OPT_BIT(0, "add", &actions, N_("add a new variable: name value"), ACTION_ADD),
142 - OPT_BIT(0, "unset", &actions, N_("remove a variable: name [value-regex]"), ACTION_UNSET),
143 - OPT_BIT(0, "unset-all", &actions, N_("remove all matches: name [value-regex]"), ACTION_UNSET_ALL),
142 + OPT_BIT(0, "unset", &actions, N_("remove a variable: name [value-pattern]"), ACTION_UNSET),
143 + OPT_BIT(0, "unset-all", &actions, N_("remove all matches: name [value-pattern]"), ACTION_UNSET_ALL),
144 OPT_BIT(0, "rename-section", &actions, N_("rename section: old-name new-name"), ACTION_RENAME_SECTION),
145 OPT_BIT(0, "remove-section", &actions, N_("remove a section: name"), ACTION_REMOVE_SECTION),
146 OPT_BIT('l', "list", &actions, N_("list all"), ACTION_LIST),
config.c
+27 -27
@@ -2415,7 +2415,7 @@ struct config_store_data {
2415 size_t baselen;
2416 char *key;
2417 int do_not_match;
2418 - regex_t *value_regex;
2418 + regex_t *value_pattern;
2419 int multi_replace;
2420 struct {
2421 size_t begin, end;
@@ -2429,10 +2429,10 @@ struct config_store_data {
2429 static void config_store_data_clear(struct config_store_data *store)
2430 {
2431 free(store->key);
2432 - if (store->value_regex != NULL &&
2433 - store->value_regex != CONFIG_REGEX_NONE) {
2434 - regfree(store->value_regex);
2435 - free(store->value_regex);
2432 + if (store->value_pattern != NULL &&
2433 + store->value_pattern != CONFIG_REGEX_NONE) {
2434 + regfree(store->value_pattern);
2435 + free(store->value_pattern);
2436 }
2437 free(store->parsed);
2438 free(store->seen);
@@ -2444,13 +2444,13 @@ static int matches(const char *key, const char *value,
2444 {
2445 if (strcmp(key, store->key))
2446 return 0; /* not ours */
2447 - if (!store->value_regex)
2447 + if (!store->value_pattern)
2448 return 1; /* always matches */
2449 - if (store->value_regex == CONFIG_REGEX_NONE)
2449 + if (store->value_pattern == CONFIG_REGEX_NONE)
2450 return 0; /* never matches */
2451
2452 return store->do_not_match ^
2453 - (value && !regexec(store->value_regex, value, 0, NULL, 0));
2453 + (value && !regexec(store->value_pattern, value, 0, NULL, 0));
2454 }
2455
2456 static int store_aux_event(enum config_event_t type,
@@ -2726,8 +2726,8 @@ void git_config_set(const char *key, const char *value)
2726
2727 /*
2728 * If value==NULL, unset in (remove from) config,
2729 - * if value_regex!=NULL, disregard key/value pairs where value does not match.
2730 - * if value_regex==CONFIG_REGEX_NONE, do not match any existing values
2729 + * if value_pattern!=NULL, disregard key/value pairs where value does not match.
2730 + * if value_pattern==CONFIG_REGEX_NONE, do not match any existing values
2731 * (only add a new one)
2732 * if flags contains the CONFIG_FLAGS_MULTI_REPLACE flag, all matching
2733 * key/values are removed before a single new pair is written. If the
@@ -2751,7 +2751,7 @@ void git_config_set(const char *key, const char *value)
2751 */
2752 int git_config_set_multivar_in_file_gently(const char *config_filename,
2753 const char *key, const char *value,
2754 - const char *value_regex,
2754 + const char *value_pattern,
2755 unsigned flags)
2756 {
2757 int fd = -1, in_fd = -1;
@@ -2812,22 +2812,22 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
2812 int i, new_line = 0;
2813 struct config_options opts;
2814
2815 - if (value_regex == NULL)
2816 - store.value_regex = NULL;
2817 - else if (value_regex == CONFIG_REGEX_NONE)
2818 - store.value_regex = CONFIG_REGEX_NONE;
2815 + if (value_pattern == NULL)
2816 + store.value_pattern = NULL;
2817 + else if (value_pattern == CONFIG_REGEX_NONE)
2818 + store.value_pattern = CONFIG_REGEX_NONE;
2819 else {
2820 - if (value_regex[0] == '!') {
2820 + if (value_pattern[0] == '!') {
2821 store.do_not_match = 1;
2822 - value_regex++;
2822 + value_pattern++;
2823 } else
2824 store.do_not_match = 0;
2825
2826 - store.value_regex = (regex_t*)xmalloc(sizeof(regex_t));
2827 - if (regcomp(store.value_regex, value_regex,
2826 + store.value_pattern = (regex_t*)xmalloc(sizeof(regex_t));
2827 + if (regcomp(store.value_pattern, value_pattern,
2828 REG_EXTENDED)) {
2829 - error(_("invalid pattern: %s"), value_regex);
2830 - FREE_AND_NULL(store.value_regex);
2829 + error(_("invalid pattern: %s"), value_pattern);
2830 + FREE_AND_NULL(store.value_pattern);
2831 ret = CONFIG_INVALID_PATTERN;
2832 goto out_free;
2833 }
@@ -2997,10 +2997,10 @@ write_err_out:
2997
2998 void git_config_set_multivar_in_file(const char *config_filename,
2999 const char *key, const char *value,
3000 - const char *value_regex, unsigned flags)
3000 + const char *value_pattern, unsigned flags)
3001 {
3002 if (!git_config_set_multivar_in_file_gently(config_filename, key, value,
3003 - value_regex, flags))
3003 + value_pattern, flags))
3004 return;
3005 if (value)
3006 die(_("could not set '%s' to '%s'"), key, value);
@@ -3009,16 +3009,16 @@ void git_config_set_multivar_in_file(const char *config_filename,
3009 }
3010
3011 int git_config_set_multivar_gently(const char *key, const char *value,
3012 - const char *value_regex, unsigned flags)
3012 + const char *value_pattern, unsigned flags)
3013 {
3014 - return git_config_set_multivar_in_file_gently(NULL, key, value, value_regex,
3014 + return git_config_set_multivar_in_file_gently(NULL, key, value, value_pattern,
3015 flags);
3016 }
3017
3018 void git_config_set_multivar(const char *key, const char *value,
3019 - const char *value_regex, unsigned flags)
3019 + const char *value_pattern, unsigned flags)
3020 {
3021 - git_config_set_multivar_in_file(NULL, key, value, value_regex,
3021 + git_config_set_multivar_in_file(NULL, key, value, value_pattern,
3022 flags);
3023 }
3024
config.h
+1 -1
@@ -296,7 +296,7 @@ int git_config_set_multivar_in_file_gently(const char *, const char *, const cha
296 void git_config_set_multivar_in_file(const char *config_filename,
297 const char *key,
298 const char *value,
299 - const char *value_regex,
299 + const char *value_pattern,
300 unsigned flags);
301
302 /**