[GSOC][PATCH v2 1/2] editor: make editor_program local to editor.c
- From
Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>
- Date
- Mar 10, 2026, 17:40 UTC
- Message-ID
- <20260310174519.676851-2-shreyanshpaliwalcmsmn@gmail.com>
- In-Reply-To
- <20260310174519.676851-1-shreyanshpaliwalcmsmn@gmail.com>
editor_program is a global variable defined in environment.c, which is set by git_default_core_config(), but is used only by editor.c only in the function git_editor().
Remove the global from the environment.c and localize it in editor.c. Introduce a helper for setting the local editor_program variable by the help of git_config_string(). Call this helper in the core.editor part of the git_default_core_config().
This keeps the existing initialization timing and availability of the variable, so invalid core.editor values are still reported early during startup, causing no ux regression.
Signed-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com> --- editor.c | 8 ++++++++ editor.h | 2 ++ environment.c | 5 ++--- environment.h | 1 - 4 files changed, 12 insertions(+), 4 deletions(-)
diff --git a/editor.c b/editor.c index fd174e6a03..b509d23f3b 100644 --- a/editor.c +++ b/editor.c @@ -18,6 +18,14 @@ #define DEFAULT_EDITOR "vi" #endif +static char *editor_program; + +int set_editor_program(const char *var, const char *value) +{ + FREE_AND_NULL(editor_program); + return git_config_string(&editor_program, var, value); +} + int is_terminal_dumb(void) { const char *terminal = getenv("TERM"); diff --git a/editor.h b/editor.h index f1c41df378..ced29046f8 100644 --- a/editor.h +++ b/editor.h @@ -8,6 +8,8 @@ const char *git_editor(void); const char *git_sequence_editor(void); int is_terminal_dumb(void); +int set_editor_program(const char *var, const char *value); + /** * Launch the user preferred editor to edit a file and fill the buffer * with the file's contents upon the user completing their editing. The diff --git a/environment.c b/environment.c index 0026eb2274..9aa9124328 100644 --- a/environment.c +++ b/environment.c @@ -37,6 +37,7 @@ #include "setup.h" #include "ws.h" #include "write-or-die.h" +#include "editor.h" static int pack_compression_seen; static int zlib_compression_seen; @@ -61,7 +62,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 *editor_program; char *askpass_program; char *excludes_file; enum auto_crlf auto_crlf = AUTO_CRLF_FALSE; @@ -437,8 +437,7 @@ int git_default_core_config(const char *var, const char *value, } if (!strcmp(var, "core.editor")) { - FREE_AND_NULL(editor_program); - return git_config_string(&editor_program, var, value); + return set_editor_program(var, value); } if (!strcmp(var, "core.commentchar") || diff --git a/environment.h b/environment.h index 27f657af04..053b678786 100644 --- a/environment.h +++ b/environment.h @@ -199,7 +199,6 @@ const char *get_commit_output_encoding(void); extern char *git_commit_encoding; extern char *git_log_output_encoding; -extern char *editor_program; extern char *askpass_program; extern char *excludes_file; -- 2.53.0