* [PATCH] config.c: remove unused git_config_key_is_valid()
@ 2021-09-28 12:56 Ævar Arnfjörð Bjarmason
2021-09-28 18:03 ` Jeff King
2021-09-29 18:25 ` Taylor Blau
0 siblings, 2 replies; 3+ messages in thread
From: Ævar Arnfjörð Bjarmason @ 2021-09-28 12:56 UTC (permalink / raw)
To: git; +Cc: Junio C Hamano, Jeff King, Ævar Arnfjörð Bjarmason
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>
---
I noticed this while looking at the "env" includes, we can get some
easy dead code removal with this cleanup.
config.c | 34 ++++++++--------------------------
config.h | 1 -
2 files changed, 8 insertions(+), 27 deletions(-)
diff --git a/config.c b/config.c
index 2edf835262f..2dcbe901b6b 100644
--- a/config.c
+++ b/config.c
@@ -425,7 +425,7 @@ static inline int iskeychar(int c)
* baselen - pointer to size_t which will hold the length of the
* section + subsection part, can be NULL
*/
-static int git_config_parse_key_1(const char *key, char **store_key, size_t *baselen_, int quiet)
+int git_config_parse_key(const char *key, char **store_key, size_t *baselen_)
{
size_t i, baselen;
int dot;
@@ -437,14 +437,12 @@ static int git_config_parse_key_1(const char *key, char **store_key, size_t *bas
*/
if (last_dot == NULL || last_dot == key) {
- if (!quiet)
- error(_("key does not contain a section: %s"), key);
+ error(_("key does not contain a section: %s"), key);
return -CONFIG_NO_SECTION_OR_NAME;
}
if (!last_dot[1]) {
- if (!quiet)
- error(_("key does not contain variable name: %s"), key);
+ error(_("key does not contain variable name: %s"), key);
return -CONFIG_NO_SECTION_OR_NAME;
}
@@ -455,8 +453,7 @@ static int git_config_parse_key_1(const char *key, char **store_key, size_t *bas
/*
* Validate the key and while at it, lower case it for matching.
*/
- if (store_key)
- *store_key = xmallocz(strlen(key));
+ *store_key = xmallocz(strlen(key));
dot = 0;
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
if (!dot || i > baselen) {
if (!iskeychar(c) ||
(i == baselen + 1 && !isalpha(c))) {
- if (!quiet)
- error(_("invalid key: %s"), key);
+ error(_("invalid key: %s"), key);
goto out_free_ret_1;
}
c = tolower(c);
} else if (c == '\n') {
- if (!quiet)
- error(_("invalid key (newline): %s"), key);
+ error(_("invalid key (newline): %s"), key);
goto out_free_ret_1;
}
- if (store_key)
- (*store_key)[i] = c;
+ (*store_key)[i] = c;
}
return 0;
out_free_ret_1:
- if (store_key) {
- FREE_AND_NULL(*store_key);
- }
+ FREE_AND_NULL(*store_key);
return -CONFIG_INVALID_KEY;
}
-int git_config_parse_key(const char *key, char **store_key, size_t *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);
-}
-
static int config_parse_pair(const char *key, const char *value,
config_fn_t fn, void *data)
{
diff --git a/config.h b/config.h
index 147f5e0490e..8b79441ee0c 100644
--- a/config.h
+++ b/config.h
@@ -259,7 +259,6 @@ int git_config_set_gently(const char *, const char *);
void git_config_set(const char *, const char *);
int git_config_parse_key(const char *, char **, size_t *);
-int git_config_key_is_valid(const char *key);
/*
* The following macros specify flag bits that alter the behavior
--
2.33.0.1340.ge9f77250f2b
^ permalink raw reply related [flat|nested] 3+ messages in thread
* Re: [PATCH] config.c: remove unused git_config_key_is_valid()
2021-09-28 12:56 [PATCH] config.c: remove unused git_config_key_is_valid() Ævar Arnfjörð Bjarmason
@ 2021-09-28 18:03 ` Jeff King
2021-09-29 18:25 ` Taylor Blau
1 sibling, 0 replies; 3+ messages in thread
From: Jeff King @ 2021-09-28 18:03 UTC (permalink / raw)
To: Ævar Arnfjörð Bjarmason; +Cc: git, Junio C Hamano
On Tue, Sep 28, 2021 at 02:56:03PM +0200, Ævar Arnfjörð Bjarmason wrote:
> 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.
Yeah, the patch here is trivially correct. The greater question is
whether we're likely to need this quiet parameter again. I kind of doubt
it given the history, so this seems like a sensible cleanup.
> 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.
Yeah, I think stopping here is good for now.
-Peff
^ permalink raw reply [flat|nested] 3+ messages in thread
* Re: [PATCH] config.c: remove unused git_config_key_is_valid()
2021-09-28 12:56 [PATCH] config.c: remove unused git_config_key_is_valid() Ævar Arnfjörð Bjarmason
2021-09-28 18:03 ` Jeff King
@ 2021-09-29 18:25 ` Taylor Blau
1 sibling, 0 replies; 3+ messages in thread
From: Taylor Blau @ 2021-09-29 18:25 UTC (permalink / raw)
To: Ævar Arnfjörð Bjarmason; +Cc: git, Junio C Hamano, Jeff King
On Tue, Sep 28, 2021 at 02:56:03PM +0200, Ævar Arnfjörð Bjarmason wrote:
> 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.
This was the part that I paid most attention to. The only caller which
passed "quiet == 1" was git_config_key_is_valid(), which is gone. So all
of those "if (!quiet)" conditionals can go away. And the remaining
callers all pass a non-null pointer to store_key, so those guard can go
away too.
> 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.
But the guard for baselen being NULL needs to stay, and it does. I agree
with you (and Peff) that stopping here is fine.
Thanks,
Taylor
^ permalink raw reply [flat|nested] 3+ messages in thread
end of thread, other threads:[~2021-09-29 18:25 UTC | newest]
Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-09-28 12:56 [PATCH] config.c: remove unused git_config_key_is_valid() Ævar Arnfjörð Bjarmason
2021-09-28 18:03 ` Jeff King
2021-09-29 18:25 ` Taylor Blau
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).