From: "Derrick Stolee via GitGitGadget" <gitgitgadget@gmail.com>
To: git@vger.kernel.org
Cc: Derrick Stolee <derrickstolee@github.com>,
Derrick Stolee <derrickstolee@github.com>
Subject: [PATCH 4/5] config: return an empty list, not NULL
Date: Tue, 27 Sep 2022 14:08:30 +0000 [thread overview]
Message-ID: <396343ce7dd17f86bbbc66197c6f0b4012caf445.1664287711.git.gitgitgadget@gmail.com> (raw)
In-Reply-To: <pull.1369.git.1664287711.gitgitgadget@gmail.com>
From: Derrick Stolee <derrickstolee@github.com>
For the multi-valued config API methods, Git previously returned a NULL
list instead of an empty list. Previous changes adjusted all callers to
instead expect an empty, non-NULL list, making this a safe change.
The next change will remove the NULL checks from all callers.
Signed-off-by: Derrick Stolee <derrickstolee@github.com>
---
config.c | 3 ++-
config.h | 6 +++---
2 files changed, 5 insertions(+), 4 deletions(-)
diff --git a/config.c b/config.c
index 0c41606c7d4..2d4ca1ae6dc 100644
--- a/config.c
+++ b/config.c
@@ -2415,8 +2415,9 @@ int git_configset_get_value(struct config_set *cs, const char *key, const char *
const struct string_list *git_configset_get_value_multi(struct config_set *cs, const char *key)
{
+ static struct string_list empty_list = STRING_LIST_INIT_NODUP;
struct config_set_element *e = configset_find_element(cs, key);
- return e ? &e->value_list : NULL;
+ return e ? &e->value_list : &empty_list;
}
int git_configset_get_string(struct config_set *cs, const char *key, char **dest)
diff --git a/config.h b/config.h
index ca994d77147..9897b97c0b9 100644
--- a/config.h
+++ b/config.h
@@ -458,7 +458,7 @@ int git_configset_add_parameters(struct config_set *cs);
/**
* Finds and returns the value list, sorted in order of increasing priority
* for the configuration variable `key` and config set `cs`. When the
- * configuration variable `key` is not found, returns NULL. The caller
+ * configuration variable `key` is not found, returns an empty list. The caller
* should not free or modify the returned pointer, as it is owned by the cache.
*/
const struct string_list *git_configset_get_value_multi(struct config_set *cs, const char *key);
@@ -543,8 +543,8 @@ int git_config_get_value(const char *key, const char **value);
/**
* Finds and returns the value list, sorted in order of increasing priority
* for the configuration variable `key`. When the configuration variable
- * `key` is not found, returns NULL. The caller should not free or modify
- * the returned pointer, as it is owned by the cache.
+ * `key` is not found, returns an empty list. The caller should not free or
+ * modify the returned pointer, as it is owned by the cache.
*/
const struct string_list *git_config_get_value_multi(const char *key);
--
gitgitgadget
next prev parent reply other threads:[~2022-09-27 14:08 UTC|newest]
Thread overview: 21+ messages / expand[flat|nested] mbox.gz Atom feed top
2022-09-27 14:08 [PATCH 0/5] [RFC] config API: return empty list, not NULL Derrick Stolee via GitGitGadget
2022-09-27 14:08 ` [PATCH 1/5] config: relax requirements on multi-value return Derrick Stolee via GitGitGadget
2022-09-27 17:26 ` Junio C Hamano
2022-09-27 14:08 ` [PATCH 2/5] *: relax git_configset_get_value_multi result Derrick Stolee via GitGitGadget
2022-09-28 15:58 ` Taylor Blau
2022-09-27 14:08 ` [PATCH 3/5] config: add BUG() statement instead of possible segfault Derrick Stolee via GitGitGadget
2022-09-27 16:17 ` Ævar Arnfjörð Bjarmason
2022-09-27 16:46 ` Derrick Stolee
2022-09-27 17:22 ` Ævar Arnfjörð Bjarmason
2022-09-27 14:08 ` Derrick Stolee via GitGitGadget [this message]
2022-09-27 16:21 ` [PATCH 4/5] config: return an empty list, not NULL Ævar Arnfjörð Bjarmason
2022-09-27 16:50 ` Derrick Stolee
2022-09-27 19:18 ` Ævar Arnfjörð Bjarmason
2022-09-28 13:46 ` Derrick Stolee
2022-09-28 14:37 ` Ævar Arnfjörð Bjarmason
2022-09-28 18:10 ` Derrick Stolee
2022-09-28 19:33 ` Ævar Arnfjörð Bjarmason
2022-09-27 14:08 ` [PATCH 5/5] *: expect a non-NULL list of config values Derrick Stolee via GitGitGadget
2022-09-28 2:40 ` [PATCH 0/5] [RFC] config API: return empty list, not NULL Junio C Hamano
2022-09-28 18:38 ` Derrick Stolee
2022-09-28 19:27 ` Ævar Arnfjörð Bjarmason
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=396343ce7dd17f86bbbc66197c6f0b4012caf445.1664287711.git.gitgitgadget@gmail.com \
--to=gitgitgadget@gmail.com \
--cc=derrickstolee@github.com \
--cc=git@vger.kernel.org \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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 NNTP newsgroup(s).