Re: [PATCH v10 5/9] environment: move askpass_program into repo_config_values
- From
Pablo Sabater <pabloosabaterr@gmail.com>
- Date
- Jul 12, 2026, 14:31 UTC
- Message-ID
- <DJWNYXB8MWLC.2PYST8ANV51MB@gmail.com>
- In-Reply-To
- <20260712111734.1073514-6-cat@malon.dev>
On Sun Jul 12, 2026 at 1:17 PM CEST, Tian Yuchen wrote:
Show 27 quoted lines
> The global variable 'askpass_program' stores the path to the program > used to prompt the user for credentials. Move it into repo_config_values > to continue the libification effort. > > While it is uncommon for a single process to require different askpass > programs for different repositories, maintaining this value as a mutable > global string is a blocker for libification. Global heap-allocated > strings introduce thread-safety issues in a multi-repo environment. > > Move 'askpass_program' into 'struct repo_config_values' to eliminate > this global state. The memory is now safely managed and freed via > 'repo_config_values_clear()'. > > Mentored-by: Christian Couder <christian.couder@gmail.com> > Mentored-by: Ayush Chandekar <ayu.chandekar@gmail.com> > Mentored-by: Olamide Caleb Bello <belkid98@gmail.com> > Signed-off-by: Tian Yuchen <cat@malon.dev> > --- > environment.c | 6 ++++-- > environment.h | 1 + > prompt.c | 3 ++- > 3 files changed, 7 insertions(+), 3 deletions(-) > > diff --git a/environment.c b/environment.c > index 975c9cb9eb..1a26c9c6d6 100644 > --- a/environment.c > +++ b/environment.c
I think that the drop of the global variable is missing.
Show 58 quoted lines
> @@ -464,8 +464,8 @@ int git_default_core_config(const char *var, const char *value,
> }
>
> if (!strcmp(var, "core.askpass")) {
> - FREE_AND_NULL(askpass_program);
> - return git_config_string(&askpass_program, var, value);
> + FREE_AND_NULL(cfg->askpass_program);
> + return git_config_string(&cfg->askpass_program, var, value);
> }
>
> if (!strcmp(var, "core.excludesfile")) {
> @@ -726,6 +726,7 @@ void repo_config_values_init(struct repo_config_values *cfg)
> cfg->excludes_file = NULL;
> cfg->editor_program = NULL;
> cfg->pager_program = NULL;
> + cfg->askpass_program = NULL;
> cfg->apply_sparse_checkout = 0;
> cfg->branch_track = BRANCH_TRACK_REMOTE;
> cfg->trust_ctime = 1;
> @@ -744,4 +745,5 @@ void repo_config_values_clear(struct repo_config_values *cfg)
> FREE_AND_NULL(cfg->excludes_file);
> FREE_AND_NULL(cfg->editor_program);
> FREE_AND_NULL(cfg->pager_program);
> + FREE_AND_NULL(cfg->askpass_program);
> }
> diff --git a/environment.h b/environment.h
> index 39b6691b47..a2e9def89d 100644
> --- a/environment.h
> +++ b/environment.h
> @@ -93,6 +93,7 @@ struct repo_config_values {
> char *excludes_file;
> char *editor_program;
> char *pager_program;
> + char *askpass_program;
> int apply_sparse_checkout;
> int trust_ctime;
> int check_stat;
> diff --git a/prompt.c b/prompt.c
> index 706fba2a50..d8d74c7e37 100644
> --- a/prompt.c
> +++ b/prompt.c
> @@ -3,6 +3,7 @@
> #include "git-compat-util.h"
> #include "parse.h"
> #include "environment.h"
> +#include "repository.h"
> #include "run-command.h"
> #include "strbuf.h"
> #include "prompt.h"
> @@ -51,7 +52,7 @@ char *git_prompt(const char *prompt, int flags)
>
> askpass = getenv("GIT_ASKPASS");
> if (!askpass)
> - askpass = askpass_program;
> + askpass = repo_config_values(the_repository)->askpass_program;
> if (!askpass)
> askpass = getenv("SSH_ASKPASS");
> if (askpass && *askpass)The rest LGTM.
Regards, Pablo