]> git.ipfire.org Git - thirdparty/git.git/commitdiff
environment: move askpass_program into repo_config_values
authorTian Yuchen <cat@malon.dev>
Tue, 14 Jul 2026 03:25:20 +0000 (11:25 +0800)
committerJunio C Hamano <gitster@pobox.com>
Tue, 14 Jul 2026 14:30:23 +0000 (07:30 -0700)
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>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
environment.c
environment.h
prompt.c

index 975c9cb9ebdb8559273cbbfbe598147ad3bf7490..3857818da3f96c500d10f324c4fe82ea200b453f 100644 (file)
@@ -55,7 +55,6 @@ int fsync_object_files = -1;
 int use_fsync = -1;
 enum fsync_method fsync_method = FSYNC_METHOD_DEFAULT;
 enum fsync_component fsync_components = FSYNC_COMPONENTS_DEFAULT;
-char *askpass_program;
 enum auto_crlf auto_crlf = AUTO_CRLF_FALSE;
 enum eol core_eol = EOL_UNSET;
 int global_conv_flags_eol = CONV_EOL_RNDTRP_WARN;
@@ -464,8 +463,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 +725,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 +744,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);
 }
index 39b6691b478544877d3546746da29a8e89c6ace4..856dc70cc47170c4d121b32750cff99f11d81b6f 100644 (file)
@@ -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;
@@ -220,8 +221,6 @@ const char *get_commit_output_encoding(void);
 extern char *git_commit_encoding;
 extern char *git_log_output_encoding;
 
-extern char *askpass_program;
-
 /*
  * The character that begins a commented line in user-editable file
  * that is subject to stripspace.
index 706fba2a5030c7728457e4068d9f94f624df667a..d8d74c7e379dbef3df22ef55524f4d2413f420ed 100644 (file)
--- 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)