From: Pablo Sabater <pabloosabaterr@gmail.com>
To: git@vger.kernel.org
Cc: rleone@scaleway.com
Subject: Re: [PATCH] gc: add git maintenance list command
Date: Fri, 13 Mar 2026 12:59:31 +0100 [thread overview]
Message-ID: <20260313115932.15259-1-pabloosabaterr@gmail.com> (raw)
In-Reply-To: <pull.2201.git.git.1772040758787.gitgitgadget@gmail.com>
> char *config_file = NULL;
> if (config_file) {
> git_configset_init(&cs);
> git_configset_add_file(&cs, config_file);
> if (git_configset_get_string_multi(&cs, key, &list)) {
> /* No repositories registered in custom config */
> git_configset_clear(&cs);
> return 0;
> }
> } else {
> global_config_file = git_global_config();
> if (!global_config_file)
> die(_("$HOME not set"));
> git_configset_init(&cs);
> git_configset_add_file(&cs, global_config_file);
> if (git_configset_get_string_multi(&cs, key, &list)) {
> /* No repositories registered in global config */
> free(global_config_file);
> git_configset_clear(&cs);
> return 0;
> }
> }
Here the branches look too similar, after the third line at the else it becomes
exactly the same. If you notice, global_config_file is initialized as NULL
then in case of !config_file, its value comes from git_global_config().
Anyways, there's no need to separate the free logic because both NULL and
git_global_config() can be freed.
you can avoid this by extracting the diferent logic from the else
if (!config_file) {
config_file = git_global_config();
if (!config_file)
die(_("$HOME not set"));
global_config_file = config_file;
}
and then the rest of the code is common for both cases
git_configset_init(&cs);
git_configset_add_file(&cs, config_file);
if (git_configset_get_string_multi(&cs, key, &list)) {
free(global_config_file);
git_configset_clear(&cs);
return 0;
}
prev parent reply other threads:[~2026-03-13 11:59 UTC|newest]
Thread overview: 2+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-02-25 17:32 [PATCH] gc: add git maintenance list command Rémy Léone via GitGitGadget
2026-03-13 11:59 ` Pablo Sabater [this message]
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=20260313115932.15259-1-pabloosabaterr@gmail.com \
--to=pabloosabaterr@gmail.com \
--cc=git@vger.kernel.org \
--cc=rleone@scaleway.com \
/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