Skip to content

Commit 247e2f8

Browse files
derrickstoleegitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 504ee12 commit 247e2f8

File tree

4 files changed

+44
-44
lines changed

4 files changed

+44
-44
lines changed

Documentation/git-config.txt

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -9,15 +9,15 @@ git-config - Get and set repository or global options
99
SYNOPSIS
1010
--------
1111
[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]]
1313
'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]
1818
'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]
2121
'git config' [<file-option>] --rename-section old_name new_name
2222
'git config' [<file-option>] --remove-section name
2323
'git config' [<file-option>] [--show-origin] [--show-scope] [-z|--null] [--name-only] -l | --list
@@ -33,7 +33,7 @@ escaped.
3333

3434
Multiple lines can be added to an option by using the `--add` option.
3535
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
3737
existing values that match the regexp are updated or unset. If
3838
you want to handle the lines that do *not* match the regex, just
3939
prepend a single exclamation mark in front (see also <<EXAMPLES>>).
@@ -73,11 +73,11 @@ OPTIONS
7373

7474
--replace-all::
7575
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`).
7777

7878
--add::
7979
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`
8181
in `--replace-all`.
8282

8383
--get::

builtin/config.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -133,14 +133,14 @@ static struct option builtin_config_options[] = {
133133
OPT_STRING('f', "file", &given_config_source.file, N_("file"), N_("use given config file")),
134134
OPT_STRING(0, "blob", &given_config_source.blob, N_("blob-id"), N_("read config from given blob object")),
135135
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),
139139
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),
141141
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),
144144
OPT_BIT(0, "rename-section", &actions, N_("rename section: old-name new-name"), ACTION_RENAME_SECTION),
145145
OPT_BIT(0, "remove-section", &actions, N_("remove a section: name"), ACTION_REMOVE_SECTION),
146146
OPT_BIT('l', "list", &actions, N_("list all"), ACTION_LIST),

config.c

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2415,7 +2415,7 @@ struct config_store_data {
24152415
size_t baselen;
24162416
char *key;
24172417
int do_not_match;
2418-
regex_t *value_regex;
2418+
regex_t *value_pattern;
24192419
int multi_replace;
24202420
struct {
24212421
size_t begin, end;
@@ -2429,10 +2429,10 @@ struct config_store_data {
24292429
static void config_store_data_clear(struct config_store_data *store)
24302430
{
24312431
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);
24362436
}
24372437
free(store->parsed);
24382438
free(store->seen);
@@ -2444,13 +2444,13 @@ static int matches(const char *key, const char *value,
24442444
{
24452445
if (strcmp(key, store->key))
24462446
return 0; /* not ours */
2447-
if (!store->value_regex)
2447+
if (!store->value_pattern)
24482448
return 1; /* always matches */
2449-
if (store->value_regex == CONFIG_REGEX_NONE)
2449+
if (store->value_pattern == CONFIG_REGEX_NONE)
24502450
return 0; /* never matches */
24512451

24522452
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));
24542454
}
24552455

24562456
static int store_aux_event(enum config_event_t type,
@@ -2726,8 +2726,8 @@ void git_config_set(const char *key, const char *value)
27262726

27272727
/*
27282728
* 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
27312731
* (only add a new one)
27322732
* if flags contains the CONFIG_FLAGS_MULTI_REPLACE flag, all matching
27332733
* 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)
27512751
*/
27522752
int git_config_set_multivar_in_file_gently(const char *config_filename,
27532753
const char *key, const char *value,
2754-
const char *value_regex,
2754+
const char *value_pattern,
27552755
unsigned flags)
27562756
{
27572757
int fd = -1, in_fd = -1;
@@ -2812,22 +2812,22 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
28122812
int i, new_line = 0;
28132813
struct config_options opts;
28142814

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;
28192819
else {
2820-
if (value_regex[0] == '!') {
2820+
if (value_pattern[0] == '!') {
28212821
store.do_not_match = 1;
2822-
value_regex++;
2822+
value_pattern++;
28232823
} else
28242824
store.do_not_match = 0;
28252825

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,
28282828
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);
28312831
ret = CONFIG_INVALID_PATTERN;
28322832
goto out_free;
28332833
}
@@ -2997,10 +2997,10 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
29972997

29982998
void git_config_set_multivar_in_file(const char *config_filename,
29992999
const char *key, const char *value,
3000-
const char *value_regex, unsigned flags)
3000+
const char *value_pattern, unsigned flags)
30013001
{
30023002
if (!git_config_set_multivar_in_file_gently(config_filename, key, value,
3003-
value_regex, flags))
3003+
value_pattern, flags))
30043004
return;
30053005
if (value)
30063006
die(_("could not set '%s' to '%s'"), key, value);
@@ -3009,16 +3009,16 @@ void git_config_set_multivar_in_file(const char *config_filename,
30093009
}
30103010

30113011
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)
30133013
{
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,
30153015
flags);
30163016
}
30173017

30183018
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)
30203020
{
3021-
git_config_set_multivar_in_file(NULL, key, value, value_regex,
3021+
git_config_set_multivar_in_file(NULL, key, value, value_pattern,
30223022
flags);
30233023
}
30243024

config.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -296,7 +296,7 @@ int git_config_set_multivar_in_file_gently(const char *, const char *, const cha
296296
void git_config_set_multivar_in_file(const char *config_filename,
297297
const char *key,
298298
const char *value,
299-
const char *value_regex,
299+
const char *value_pattern,
300300
unsigned flags);
301301

302302
/**

0 commit comments

Comments
 (0)