git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH v3 2/8] config: replace 'value_regex' with 'value_pattern'

From
Derrick Stolee via GitGitGadget <gitgitgadget@gmail.com>
Date
Nov 25, 2020, 22:12 UTC
Message-ID
<f135b001ad911c079b0754c61e2179277ce37e0f.1606342377.git.gitgitgadget@gmail.com>
In-Reply-To
<pull.796.v3.git.1606342376.gitgitgadget@gmail.com>
From: Derrick Stolee <dstolee@microsoft.com>

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>
---
 Documentation/git-config.txt | 20 ++++++-------
 builtin/config.c             | 12 ++++----
 config.c                     | 54 ++++++++++++++++++------------------
 config.h                     |  2 +-
 4 files changed, 44 insertions(+), 44 deletions(-)
diff --git a/Documentation/git-config.txt b/Documentation/git-config.txt
index 7573160f21..0be5499952 100644
--- a/Documentation/git-config.txt
+++ b/Documentation/git-config.txt
@@ -9,15 +9,15 @@ git-config - Get and set repository or global options
 SYNOPSIS
 --------
 [verse]
-'git config' [<file-option>] [--type=<type>] [--show-origin] [--show-scope] [-z|--null] name [value [value_regex]]
+'git config' [<file-option>] [--type=<type>] [--show-origin] [--show-scope] [-z|--null] name [value [value-pattern]]
 'git config' [<file-option>] [--type=<type>] --add name value
-'git config' [<file-option>] [--type=<type>] --replace-all name value [value_regex]
-'git config' [<file-option>] [--type=<type>] [--show-origin] [--show-scope] [-z|--null] --get name [value_regex]
-'git config' [<file-option>] [--type=<type>] [--show-origin] [--show-scope] [-z|--null] --get-all name [value_regex]
-'git config' [<file-option>] [--type=<type>] [--show-origin] [--show-scope] [-z|--null] [--name-only] --get-regexp name_regex [value_regex]
+'git config' [<file-option>] [--type=<type>] --replace-all name value [value-pattern]
+'git config' [<file-option>] [--type=<type>] [--show-origin] [--show-scope] [-z|--null] --get name [value-pattern]
+'git config' [<file-option>] [--type=<type>] [--show-origin] [--show-scope] [-z|--null] --get-all name [value-pattern]
+'git config' [<file-option>] [--type=<type>] [--show-origin] [--show-scope] [-z|--null] [--name-only] --get-regexp name_regex [value-pattern]
 'git config' [<file-option>] [--type=<type>] [-z|--null] --get-urlmatch name URL
-'git config' [<file-option>] --unset name [value_regex]
-'git config' [<file-option>] --unset-all name [value_regex]
+'git config' [<file-option>] --unset name [value-pattern]
+'git config' [<file-option>] --unset-all name [value-pattern]
 'git config' [<file-option>] --rename-section old_name new_name
 'git config' [<file-option>] --remove-section name
 'git config' [<file-option>] [--show-origin] [--show-scope] [-z|--null] [--name-only] -l | --list
@@ -33,7 +33,7 @@ escaped.
 
 Multiple lines can be added to an option by using the `--add` option.
 If you want to update or unset an option which can occur on multiple
-lines, a POSIX regexp `value_regex` needs to be given.  Only the
+lines, a POSIX regexp `value-pattern` needs to be given.  Only the
 existing values that match the regexp are updated or unset.  If
 you want to handle the lines that do *not* match the regex, just
 prepend a single exclamation mark in front (see also <<EXAMPLES>>).
@@ -73,11 +73,11 @@ OPTIONS
 
 --replace-all::
 	Default behavior is to replace at most one line. This replaces
-	all lines matching the key (and optionally the value_regex).
+	all lines matching the key (and optionally the `value-pattern`).
 
 --add::
 	Adds a new line to the option without altering any existing
-	values.  This is the same as providing '^$' as the value_regex
+	values.  This is the same as providing '^$' as the `value-pattern`
 	in `--replace-all`.
 
 --get::
diff --git a/builtin/config.c b/builtin/config.c
index e7c7f3d455..9d97091561 100644
--- a/builtin/config.c
+++ b/builtin/config.c
@@ -130,14 +130,14 @@ static struct option builtin_config_options[] = {
 	OPT_STRING('f', "file", &given_config_source.file, N_("file"), N_("use given config file")),
 	OPT_STRING(0, "blob", &given_config_source.blob, N_("blob-id"), N_("read config from given blob object")),
 	OPT_GROUP(N_("Action")),
-	OPT_BIT(0, "get", &actions, N_("get value: name [value-regex]"), ACTION_GET),
-	OPT_BIT(0, "get-all", &actions, N_("get all values: key [value-regex]"), ACTION_GET_ALL),
-	OPT_BIT(0, "get-regexp", &actions, N_("get values for regexp: name-regex [value-regex]"), ACTION_GET_REGEXP),
+	OPT_BIT(0, "get", &actions, N_("get value: name [value-pattern]"), ACTION_GET),
+	OPT_BIT(0, "get-all", &actions, N_("get all values: key [value-pattern]"), ACTION_GET_ALL),
+	OPT_BIT(0, "get-regexp", &actions, N_("get values for regexp: name-regex [value-pattern]"), ACTION_GET_REGEXP),
 	OPT_BIT(0, "get-urlmatch", &actions, N_("get value specific for the URL: section[.var] URL"), ACTION_GET_URLMATCH),
-	OPT_BIT(0, "replace-all", &actions, N_("replace all matching variables: name value [value_regex]"), ACTION_REPLACE_ALL),
+	OPT_BIT(0, "replace-all", &actions, N_("replace all matching variables: name value [value-pattern]"), ACTION_REPLACE_ALL),
 	OPT_BIT(0, "add", &actions, N_("add a new variable: name value"), ACTION_ADD),
-	OPT_BIT(0, "unset", &actions, N_("remove a variable: name [value-regex]"), ACTION_UNSET),
-	OPT_BIT(0, "unset-all", &actions, N_("remove all matches: name [value-regex]"), ACTION_UNSET_ALL),
+	OPT_BIT(0, "unset", &actions, N_("remove a variable: name [value-pattern]"), ACTION_UNSET),
+	OPT_BIT(0, "unset-all", &actions, N_("remove all matches: name [value-pattern]"), ACTION_UNSET_ALL),
 	OPT_BIT(0, "rename-section", &actions, N_("rename section: old-name new-name"), ACTION_RENAME_SECTION),
 	OPT_BIT(0, "remove-section", &actions, N_("remove a section: name"), ACTION_REMOVE_SECTION),
 	OPT_BIT('l', "list", &actions, N_("list all"), ACTION_LIST),
diff --git a/config.c b/config.c
index f34a11d94b..ac6aace166 100644
--- a/config.c
+++ b/config.c
@@ -2402,7 +2402,7 @@ struct config_store_data {
 	size_t baselen;
 	char *key;
 	int do_not_match;
-	regex_t *value_regex;
+	regex_t *value_pattern;
 	int multi_replace;
 	struct {
 		size_t begin, end;
@@ -2416,10 +2416,10 @@ struct config_store_data {
 static void config_store_data_clear(struct config_store_data *store)
 {
 	free(store->key);
-	if (store->value_regex != NULL &&
-	    store->value_regex != CONFIG_REGEX_NONE) {
-		regfree(store->value_regex);
-		free(store->value_regex);
+	if (store->value_pattern != NULL &&
+	    store->value_pattern != CONFIG_REGEX_NONE) {
+		regfree(store->value_pattern);
+		free(store->value_pattern);
 	}
 	free(store->parsed);
 	free(store->seen);
@@ -2431,13 +2431,13 @@ static int matches(const char *key, const char *value,
 {
 	if (strcmp(key, store->key))
 		return 0; /* not ours */
-	if (!store->value_regex)
+	if (!store->value_pattern)
 		return 1; /* always matches */
-	if (store->value_regex == CONFIG_REGEX_NONE)
+	if (store->value_pattern == CONFIG_REGEX_NONE)
 		return 0; /* never matches */
 
 	return store->do_not_match ^
-		(value && !regexec(store->value_regex, value, 0, NULL, 0));
+		(value && !regexec(store->value_pattern, value, 0, NULL, 0));
 }
 
 static int store_aux_event(enum config_event_t type,
@@ -2713,8 +2713,8 @@ void git_config_set(const char *key, const char *value)
 
 /*
  * If value==NULL, unset in (remove from) config,
- * if value_regex!=NULL, disregard key/value pairs where value does not match.
- * if value_regex==CONFIG_REGEX_NONE, do not match any existing values
+ * if value_pattern!=NULL, disregard key/value pairs where value does not match.
+ * if value_pattern==CONFIG_REGEX_NONE, do not match any existing values
  *     (only add a new one)
  * if flags contains the CONFIG_FLAGS_MULTI_REPLACE flag, all matching
  *     key/values are removed before a single new pair is written. If the
@@ -2738,7 +2738,7 @@ void git_config_set(const char *key, const char *value)
  */
 int git_config_set_multivar_in_file_gently(const char *config_filename,
 					   const char *key, const char *value,
-					   const char *value_regex,
+					   const char *value_pattern,
 					   unsigned flags)
 {
 	int fd = -1, in_fd = -1;
@@ -2799,22 +2799,22 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
 		int i, new_line = 0;
 		struct config_options opts;
 
-		if (value_regex == NULL)
-			store.value_regex = NULL;
-		else if (value_regex == CONFIG_REGEX_NONE)
-			store.value_regex = CONFIG_REGEX_NONE;
+		if (value_pattern == NULL)
+			store.value_pattern = NULL;
+		else if (value_pattern == CONFIG_REGEX_NONE)
+			store.value_pattern = CONFIG_REGEX_NONE;
 		else {
-			if (value_regex[0] == '!') {
+			if (value_pattern[0] == '!') {
 				store.do_not_match = 1;
-				value_regex++;
+				value_pattern++;
 			} else
 				store.do_not_match = 0;
 
-			store.value_regex = (regex_t*)xmalloc(sizeof(regex_t));
-			if (regcomp(store.value_regex, value_regex,
+			store.value_pattern = (regex_t*)xmalloc(sizeof(regex_t));
+			if (regcomp(store.value_pattern, value_pattern,
 					REG_EXTENDED)) {
-				error(_("invalid pattern: %s"), value_regex);
-				FREE_AND_NULL(store.value_regex);
+				error(_("invalid pattern: %s"), value_pattern);
+				FREE_AND_NULL(store.value_pattern);
 				ret = CONFIG_INVALID_PATTERN;
 				goto out_free;
 			}
@@ -2984,10 +2984,10 @@ int git_config_set_multivar_in_file_gently(const char *config_filename,
 
 void git_config_set_multivar_in_file(const char *config_filename,
 				     const char *key, const char *value,
-				     const char *value_regex, unsigned flags)
+				     const char *value_pattern, unsigned flags)
 {
 	if (!git_config_set_multivar_in_file_gently(config_filename, key, value,
-						    value_regex, flags))
+						    value_pattern, flags))
 		return;
 	if (value)
 		die(_("could not set '%s' to '%s'"), key, value);
@@ -2996,16 +2996,16 @@ void git_config_set_multivar_in_file(const char *config_filename,
 }
 
 int git_config_set_multivar_gently(const char *key, const char *value,
-				   const char *value_regex, unsigned flags)
+				   const char *value_pattern, unsigned flags)
 {
-	return git_config_set_multivar_in_file_gently(NULL, key, value, value_regex,
+	return git_config_set_multivar_in_file_gently(NULL, key, value, value_pattern,
 						      flags);
 }
 
 void git_config_set_multivar(const char *key, const char *value,
-			     const char *value_regex, unsigned flags)
+			     const char *value_pattern, unsigned flags)
 {
-	git_config_set_multivar_in_file(NULL, key, value, value_regex,
+	git_config_set_multivar_in_file(NULL, key, value, value_pattern,
 					flags);
 }
 
diff --git a/config.h b/config.h
index 58726c34d6..8ad1085b74 100644
--- a/config.h
+++ b/config.h
@@ -296,7 +296,7 @@ int git_config_set_multivar_in_file_gently(const char *, const char *, const cha
 void git_config_set_multivar_in_file(const char *config_filename,
 				     const char *key,
 				     const char *value,
-				     const char *value_regex,
+				     const char *value_pattern,
 				     unsigned flags);
 
 /**
-- 
gitgitgadget
Previous: Eric SunshineNext: Eric Sunshine
Message 66 of 72 in “config: add --literal-value option”
  1. 0/7 config: add --literal-value optionDerrick Stolee via GitGitGadget, Nov 19, 2020
  2. 1/7 t1300: test "set all" mode with value_regexDerrick Stolee via GitGitGadget, Nov 19, 2020
  3. Junio C HamanoNov 19, 2020
  4. brian m. carlsonNov 20, 2020
  5. Junio C HamanoNov 20, 2020
  6. Jeff KingNov 20, 2020
  7. Junio C HamanoNov 20, 2020
  8. brian m. carlsonNov 21, 2020
  9. Junio C HamanoNov 22, 2020
  10. Jeff KingNov 24, 2020
  11. Junio C HamanoNov 24, 2020
  12. 2/7 t1300: add test for --replace-all with value_regexDerrick Stolee via GitGitGadget, Nov 19, 2020
  13. 5/7 config: plumb --literal-value into config APIDerrick Stolee via GitGitGadget, Nov 19, 2020
  14. Junio C HamanoNov 19, 2020
  15. 4/7 config: add --literal-value option, un-implementedDerrick Stolee via GitGitGadget, Nov 19, 2020
  16. Junio C HamanoNov 19, 2020
  17. Martin ÅgrenNov 20, 2020
  18. 3/7 config: convert multi_replace to flagsDerrick Stolee via GitGitGadget, Nov 19, 2020
  19. Junio C HamanoNov 19, 2020
  20. 7/7 maintenance: use 'git config --literal-value'Derrick Stolee via GitGitGadget, Nov 19, 2020
  21. Junio C HamanoNov 19, 2020
  22. 6/7 config: implement --literal-value with --get*Derrick Stolee via GitGitGadget, Nov 19, 2020
  23. Ævar Arnfjörð BjarmasonNov 20, 2020
  24. Derrick StoleeNov 20, 2020
  25. Junio C HamanoNov 20, 2020
  26. Derrick StoleeNov 20, 2020
  27. Junio C HamanoNov 20, 2020
  28. Ævar Arnfjörð BjarmasonNov 24, 2020
  29. 0/7 config: add --fixed-value optionDerrick Stolee via GitGitGadget, Nov 23, 2020
  30. 1/7 t1300: test "set all" mode with value_regexDerrick Stolee via GitGitGadget, Nov 23, 2020
  31. Emily ShafferNov 23, 2020
  32. 2/7 t1300: add test for --replace-all with value_regexDerrick Stolee via GitGitGadget, Nov 23, 2020
  33. Emily ShafferNov 23, 2020
  34. 4/7 config: add --fixed-value option, un-implementedDerrick Stolee via GitGitGadget, Nov 23, 2020
  35. Junio C HamanoNov 23, 2020
  36. Emily ShafferNov 23, 2020
  37. Junio C HamanoNov 23, 2020
  38. Derrick StoleeNov 25, 2020
  39. Derrick StoleeNov 25, 2020
  40. Eric SunshineNov 25, 2020
  41. Junio C HamanoNov 25, 2020
  42. Junio C HamanoNov 25, 2020
  43. 3/7 config: convert multi_replace to flagsDerrick Stolee via GitGitGadget, Nov 23, 2020
  44. Emily ShafferNov 23, 2020
  45. 5/7 config: plumb --fixed-value into config APIDerrick Stolee via GitGitGadget, Nov 23, 2020
  46. Emily ShafferNov 23, 2020
  47. Eric SunshineNov 24, 2020
  48. Derrick StoleeNov 25, 2020
  49. Eric SunshineNov 25, 2020
  50. 6/7 config: implement --fixed-value with --get*Derrick Stolee via GitGitGadget, Nov 23, 2020
  51. Junio C HamanoNov 23, 2020
  52. Emily ShafferNov 23, 2020
  53. 7/7 maintenance: use 'git config --fixed-value'Derrick Stolee via GitGitGadget, Nov 23, 2020
  54. Junio C HamanoNov 23, 2020
  55. Emily ShafferNov 23, 2020
  56. Junio C HamanoNov 23, 2020
  57. Junio C HamanoNov 23, 2020
  58. 0/8 config: add --fixed-value optionDerrick Stolee via GitGitGadget, Nov 25, 2020
  59. 3/8 t1300: test "set all" mode with value-patternDerrick Stolee via GitGitGadget, Nov 25, 2020
  60. 4/8 t1300: add test for --replace-all with value-patternDerrick Stolee via GitGitGadget, Nov 25, 2020
  61. 6/8 config: plumb --fixed-value into config APIDerrick Stolee via GitGitGadget, Nov 25, 2020
  62. 8/8 maintenance: use 'git config --fixed-value'Derrick Stolee via GitGitGadget, Nov 25, 2020
  63. Junio C HamanoNov 25, 2020
  64. 5/8 config: add --fixed-value option, un-implementedDerrick Stolee via GitGitGadget, Nov 25, 2020
  65. Eric SunshineNov 25, 2020
  66. 2/8 config: replace 'value_regex' with 'value_pattern'Derrick Stolee via GitGitGadget, Nov 25, 2020
  67. Eric SunshineNov 25, 2020
  68. 1/8 config: convert multi_replace to flagsDerrick Stolee via GitGitGadget, Nov 25, 2020
  69. 7/8 config: implement --fixed-value with --get*Derrick Stolee via GitGitGadget, Nov 25, 2020
  70. Junio C HamanoNov 25, 2020
  71. Derrick StoleeNov 26, 2020
  72. Junio C HamanoDec 1, 2020

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.