config.c: remove unused git_config_key_is_valid()

The git_config_key_is_valid() function got left behind in a refactoring in a9bcf6586d1 (alias: use the early config machinery to expand aliases, 2017-06-14), It previously had two users when it was added in 9e9de18f1ad (config: silence warnings for command names with invalid keys, 2015-08-24), and after 6a1e1bc0a15 (pager: use callbacks instead of configset, 2016-09-12) only one remained. By removing it we can get rid of the "quiet" branches in this function, as well as cases where "store_key" is NULL, for which there are no other users. Out of the 5 callers of git_config_parse_key() only one needs to pass a non-NULL "size_t *baselen_", so we could remove the third parameter from the public interface. I did not find that potential simplification to be worthwhile. Signed-off-by: Ævar Arnfjörð Bjarmason <avarab@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Ævar Arnfjörð Bjarmason committed Sep 28, 2021 at 14:56 UTC 73c5f67071f5448858f7f745e888a4a8aa9fd72f
2 files changed +8 -27
config.c
+8 -26
@@ -425,7 +425,7 @@ static inline int iskeychar(int c)
425 * baselen - pointer to size_t which will hold the length of the
426 * section + subsection part, can be NULL
427 */
428 -static int git_config_parse_key_1(const char *key, char **store_key, size_t *baselen_, int quiet)
428 +int git_config_parse_key(const char *key, char **store_key, size_t *baselen_)
429 {
430 size_t i, baselen;
431 int dot;
@@ -437,14 +437,12 @@ static int git_config_parse_key_1(const char *key, char **store_key, size_t *bas
437 */
438
439 if (last_dot == NULL || last_dot == key) {
440 - if (!quiet)
441 - error(_("key does not contain a section: %s"), key);
440 + error(_("key does not contain a section: %s"), key);
441 return -CONFIG_NO_SECTION_OR_NAME;
442 }
443
444 if (!last_dot[1]) {
446 - if (!quiet)
447 - error(_("key does not contain variable name: %s"), key);
445 + error(_("key does not contain variable name: %s"), key);
446 return -CONFIG_NO_SECTION_OR_NAME;
447 }
448
@@ -455,8 +453,7 @@ static int git_config_parse_key_1(const char *key, char **store_key, size_t *bas
453 /*
454 * Validate the key and while at it, lower case it for matching.
455 */
458 - if (store_key)
459 - *store_key = xmallocz(strlen(key));
456 + *store_key = xmallocz(strlen(key));
457
458 dot = 0;
459 for (i = 0; key[i]; i++) {
@@ -467,39 +464,24 @@ static int git_config_parse_key_1(const char *key, char **store_key, size_t *bas
464 if (!dot || i > baselen) {
465 if (!iskeychar(c) ||
466 (i == baselen + 1 && !isalpha(c))) {
470 - if (!quiet)
471 - error(_("invalid key: %s"), key);
467 + error(_("invalid key: %s"), key);
468 goto out_free_ret_1;
469 }
470 c = tolower(c);
471 } else if (c == '\n') {
476 - if (!quiet)
477 - error(_("invalid key (newline): %s"), key);
472 + error(_("invalid key (newline): %s"), key);
473 goto out_free_ret_1;
474 }
480 - if (store_key)
481 - (*store_key)[i] = c;
475 + (*store_key)[i] = c;
476 }
477
478 return 0;
479
480 out_free_ret_1:
487 - if (store_key) {
488 - FREE_AND_NULL(*store_key);
489 - }
481 + FREE_AND_NULL(*store_key);
482 return -CONFIG_INVALID_KEY;
483 }
484
493 -int git_config_parse_key(const char *key, char **store_key, size_t *baselen)
494 -{
495 - return git_config_parse_key_1(key, store_key, baselen, 0);
496 -}
497 -
498 -int git_config_key_is_valid(const char *key)
499 -{
500 - return !git_config_parse_key_1(key, NULL, NULL, 1);
501 -}
502 -
485 static int config_parse_pair(const char *key, const char *value,
486 config_fn_t fn, void *data)
487 {
config.h
-1
@@ -259,7 +259,6 @@ int git_config_set_gently(const char *, const char *);
259 void git_config_set(const char *, const char *);
260
261 int git_config_parse_key(const char *, char **, size_t *);
262 -int git_config_key_is_valid(const char *key);
262
263 /*
264 * The following macros specify flag bits that alter the behavior