Merge branch 'jk/fix-alias-pager-config-key-warnings'
Because the configuration system does not allow "alias.0foo" and "pager.0foo" as the configuration key, the user cannot use '0foo' as a custom command name anyway, but "git 0foo" tried to look these keys up and emitted useless warnings before saying '0foo is not a git command'. These warning messages have been squelched. * jk/fix-alias-pager-config-key-warnings: config: silence warnings for command names with invalid keysmaint
						commit
						7b7c10bf5e
					
				
							
								
								
									
										3
									
								
								alias.c
								
								
								
								
							
							
						
						
									
										3
									
								
								alias.c
								
								
								
								
							|  | @ -5,7 +5,8 @@ char *alias_lookup(const char *alias) | ||||||
| 	char *v = NULL; | 	char *v = NULL; | ||||||
| 	struct strbuf key = STRBUF_INIT; | 	struct strbuf key = STRBUF_INIT; | ||||||
| 	strbuf_addf(&key, "alias.%s", alias); | 	strbuf_addf(&key, "alias.%s", alias); | ||||||
| 	git_config_get_string(key.buf, &v); | 	if (git_config_key_is_valid(key.buf)) | ||||||
|  | 		git_config_get_string(key.buf, &v); | ||||||
| 	strbuf_release(&key); | 	strbuf_release(&key); | ||||||
| 	return v; | 	return v; | ||||||
| } | } | ||||||
|  |  | ||||||
							
								
								
									
										1
									
								
								cache.h
								
								
								
								
							
							
						
						
									
										1
									
								
								cache.h
								
								
								
								
							|  | @ -1440,6 +1440,7 @@ extern int git_config_pathname(const char **, const char *, const char *); | ||||||
| extern int git_config_set_in_file(const char *, const char *, const char *); | extern int git_config_set_in_file(const char *, const char *, const char *); | ||||||
| extern int git_config_set(const char *, const char *); | extern int git_config_set(const char *, const char *); | ||||||
| extern int git_config_parse_key(const char *, char **, int *); | extern int git_config_parse_key(const char *, char **, int *); | ||||||
|  | extern int git_config_key_is_valid(const char *key); | ||||||
| extern int git_config_set_multivar(const char *, const char *, const char *, int); | extern int git_config_set_multivar(const char *, const char *, const char *, int); | ||||||
| extern int git_config_set_multivar_in_file(const char *, const char *, const char *, const char *, int); | extern int git_config_set_multivar_in_file(const char *, const char *, const char *, const char *, int); | ||||||
| extern int git_config_rename_section(const char *, const char *); | extern int git_config_rename_section(const char *, const char *); | ||||||
|  |  | ||||||
							
								
								
									
										39
									
								
								config.c
								
								
								
								
							
							
						
						
									
										39
									
								
								config.c
								
								
								
								
							|  | @ -1848,7 +1848,7 @@ int git_config_set(const char *key, const char *value) | ||||||
|  * baselen - pointer to int which will hold the length of the |  * baselen - pointer to int which will hold the length of the | ||||||
|  *           section + subsection part, can be NULL |  *           section + subsection part, can be NULL | ||||||
|  */ |  */ | ||||||
| int git_config_parse_key(const char *key, char **store_key, int *baselen_) | static int git_config_parse_key_1(const char *key, char **store_key, int *baselen_, int quiet) | ||||||
| { | { | ||||||
| 	int i, dot, baselen; | 	int i, dot, baselen; | ||||||
| 	const char *last_dot = strrchr(key, '.'); | 	const char *last_dot = strrchr(key, '.'); | ||||||
|  | @ -1859,12 +1859,14 @@ int git_config_parse_key(const char *key, char **store_key, int *baselen_) | ||||||
| 	 */ | 	 */ | ||||||
|  |  | ||||||
| 	if (last_dot == NULL || last_dot == key) { | 	if (last_dot == NULL || last_dot == key) { | ||||||
| 		error("key does not contain a section: %s", key); | 		if (!quiet) | ||||||
|  | 			error("key does not contain a section: %s", key); | ||||||
| 		return -CONFIG_NO_SECTION_OR_NAME; | 		return -CONFIG_NO_SECTION_OR_NAME; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
| 	if (!last_dot[1]) { | 	if (!last_dot[1]) { | ||||||
| 		error("key does not contain variable name: %s", key); | 		if (!quiet) | ||||||
|  | 			error("key does not contain variable name: %s", key); | ||||||
| 		return -CONFIG_NO_SECTION_OR_NAME; | 		return -CONFIG_NO_SECTION_OR_NAME; | ||||||
| 	} | 	} | ||||||
|  |  | ||||||
|  | @ -1875,7 +1877,8 @@ int git_config_parse_key(const char *key, char **store_key, int *baselen_) | ||||||
| 	/* | 	/* | ||||||
| 	 * Validate the key and while at it, lower case it for matching. | 	 * Validate the key and while at it, lower case it for matching. | ||||||
| 	 */ | 	 */ | ||||||
| 	*store_key = xmalloc(strlen(key) + 1); | 	if (store_key) | ||||||
|  | 		*store_key = xmalloc(strlen(key) + 1); | ||||||
|  |  | ||||||
| 	dot = 0; | 	dot = 0; | ||||||
| 	for (i = 0; key[i]; i++) { | 	for (i = 0; key[i]; i++) { | ||||||
|  | @ -1886,26 +1889,42 @@ int git_config_parse_key(const char *key, char **store_key, int *baselen_) | ||||||
| 		if (!dot || i > baselen) { | 		if (!dot || i > baselen) { | ||||||
| 			if (!iskeychar(c) || | 			if (!iskeychar(c) || | ||||||
| 			    (i == baselen + 1 && !isalpha(c))) { | 			    (i == baselen + 1 && !isalpha(c))) { | ||||||
| 				error("invalid key: %s", key); | 				if (!quiet) | ||||||
|  | 					error("invalid key: %s", key); | ||||||
| 				goto out_free_ret_1; | 				goto out_free_ret_1; | ||||||
| 			} | 			} | ||||||
| 			c = tolower(c); | 			c = tolower(c); | ||||||
| 		} else if (c == '\n') { | 		} else if (c == '\n') { | ||||||
| 			error("invalid key (newline): %s", key); | 			if (!quiet) | ||||||
|  | 				error("invalid key (newline): %s", key); | ||||||
| 			goto out_free_ret_1; | 			goto out_free_ret_1; | ||||||
| 		} | 		} | ||||||
| 		(*store_key)[i] = c; | 		if (store_key) | ||||||
|  | 			(*store_key)[i] = c; | ||||||
| 	} | 	} | ||||||
| 	(*store_key)[i] = 0; | 	if (store_key) | ||||||
|  | 		(*store_key)[i] = 0; | ||||||
|  |  | ||||||
| 	return 0; | 	return 0; | ||||||
|  |  | ||||||
| out_free_ret_1: | out_free_ret_1: | ||||||
| 	free(*store_key); | 	if (store_key) { | ||||||
| 	*store_key = NULL; | 		free(*store_key); | ||||||
|  | 		*store_key = NULL; | ||||||
|  | 	} | ||||||
| 	return -CONFIG_INVALID_KEY; | 	return -CONFIG_INVALID_KEY; | ||||||
| } | } | ||||||
|  |  | ||||||
|  | int git_config_parse_key(const char *key, char **store_key, int *baselen) | ||||||
|  | { | ||||||
|  | 	return git_config_parse_key_1(key, store_key, baselen, 0); | ||||||
|  | } | ||||||
|  |  | ||||||
|  | int git_config_key_is_valid(const char *key) | ||||||
|  | { | ||||||
|  | 	return !git_config_parse_key_1(key, NULL, NULL, 1); | ||||||
|  | } | ||||||
|  |  | ||||||
| /* | /* | ||||||
|  * If value==NULL, unset in (remove from) config, |  * If value==NULL, unset in (remove from) config, | ||||||
|  * if value_regex!=NULL, disregard key/value pairs where value does not match. |  * if value_regex!=NULL, disregard key/value pairs where value does not match. | ||||||
|  |  | ||||||
							
								
								
									
										3
									
								
								pager.c
								
								
								
								
							
							
						
						
									
										3
									
								
								pager.c
								
								
								
								
							|  | @ -150,7 +150,8 @@ int check_pager_config(const char *cmd) | ||||||
| 	struct strbuf key = STRBUF_INIT; | 	struct strbuf key = STRBUF_INIT; | ||||||
| 	const char *value = NULL; | 	const char *value = NULL; | ||||||
| 	strbuf_addf(&key, "pager.%s", cmd); | 	strbuf_addf(&key, "pager.%s", cmd); | ||||||
| 	if (!git_config_get_value(key.buf, &value)) { | 	if (git_config_key_is_valid(key.buf) && | ||||||
|  | 	    !git_config_get_value(key.buf, &value)) { | ||||||
| 		int b = git_config_maybe_bool(key.buf, value); | 		int b = git_config_maybe_bool(key.buf, value); | ||||||
| 		if (b >= 0) | 		if (b >= 0) | ||||||
| 			want = b; | 			want = b; | ||||||
|  |  | ||||||
|  | @ -447,4 +447,13 @@ test_expect_success TTY 'external command pagers override sub-commands' ' | ||||||
| 	test_cmp expect actual | 	test_cmp expect actual | ||||||
| ' | ' | ||||||
|  |  | ||||||
|  | test_expect_success 'command with underscores does not complain' ' | ||||||
|  | 	write_script git-under_score <<-\EOF && | ||||||
|  | 	echo ok | ||||||
|  | 	EOF | ||||||
|  | 	git --exec-path=. under_score >actual 2>&1 && | ||||||
|  | 	echo ok >expect && | ||||||
|  | 	test_cmp expect actual | ||||||
|  | ' | ||||||
|  |  | ||||||
| test_done | test_done | ||||||
|  |  | ||||||
		Loading…
	
		Reference in New Issue
	
	 Junio C Hamano
						Junio C Hamano