{"thread":{"id":"65107","subject":"[GSOC][PATCH 0/2] Remove global state from editor.c","startedAt":"2026-03-01T10:53:03Z","lastAt":"2026-03-17T16:05:55Z","messageCount":14,"participants":["Shreyansh Paliwal","Burak Kaan Karaçay","Phillip Wood","Tian Yuchen","Karthik Nayak"],"isPatch":true,"patchVersion":1,"patchTotal":2},"messages":[{"id":"537435","messageId":"20260301105228.1738388-1-shreyanshpaliwalcmsmn@gmail.com","threadId":"65107","inReplyTo":null,"subject":"[GSOC][PATCH 0/2] Remove global state from editor.c","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-03-01T10:42:57Z","receivedAt":"2026-03-01T10:53:03Z","isPatch":true,"sender":{"key":"shreyanshpaliwalcmsmn@gmail.com","avatar":"https://avatars.githubusercontent.com/u/152720574?v=4"},"body":"This series reduces reliance on global states. Mainly there\nare two such global states in editor.c,\n\n* editor_program: defined in environment.c and populated during config\n  parsing, but only used by editor.c via git_editor().\n\n* the_repository: used in git_sequence_editor() to read the sequence.editor\n  configuration.\n\nIn patch 1/2, localize editor_program to editor.c by introducing a helper\nthat allows git_default_core_config() to continue initializing the value\nduring initial config parsing.\n\nIn patch 2/2, remove the remaining use of the_repository in editor.c by\npassing struct repository through git_sequence_editor() and its\ncallers. With this change, editor.c no longer requires\n'USE_THE_REPOSITORY_VARIABLE'.\n\nShreyansh Paliwal (2):\n  editor: make editor_program local to editor.c\n  editor: remove the_repository usage\n\n builtin/var.c        |  2 +-\n editor.c             | 18 ++++++++++++------\n editor.h             |  6 ++++--\n environment.c        |  5 ++---\n environment.h        |  1 -\n rebase-interactive.c |  2 +-\n 6 files changed, 20 insertions(+), 14 deletions(-)\n\n--\n2.53.0\n"},{"id":"537436","messageId":"20260301105228.1738388-2-shreyanshpaliwalcmsmn@gmail.com","threadId":"65107","inReplyTo":"20260301105228.1738388-1-shreyanshpaliwalcmsmn@gmail.com","subject":"[GSOC][PATCH 1/2] editor: make editor_program local to editor.c","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-03-01T10:42:58Z","receivedAt":"2026-03-01T10:53:47Z","isPatch":true,"sender":{"key":"shreyanshpaliwalcmsmn@gmail.com","avatar":"https://avatars.githubusercontent.com/u/152720574?v=4"},"body":"editor_program is a global variable defined in environment.c, which is set\nby git_default_core_config(), but is used only by editor.c in the function\ngit_editor().\n\nRemove the global from the environment.c and localize it in editor.c.\nIntroduce a helper for setting the local editor_program variable by the\nhelp of git_config_string(). Call this helper in the core.editor part of\nthe git_default_core_config().\n\nThis keeps the existing initialization timing and availability of the\nvariable, so invalid core.editor values are still reported early during\nstartup, causing no ux regression.\n\nSigned-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>\n---\n editor.c      | 8 ++++++++\n editor.h      | 2 ++\n environment.c | 5 ++---\n environment.h | 1 -\n 4 files changed, 12 insertions(+), 4 deletions(-)\n\ndiff --git a/editor.c b/editor.c\nindex fd174e6a03..b509d23f3b 100644\n--- a/editor.c\n+++ b/editor.c\n@@ -18,6 +18,14 @@\n #define DEFAULT_EDITOR \"vi\"\n #endif\n\n+static char *editor_program;\n+\n+int set_editor_program(const char *var, const char *value)\n+{\n+\tFREE_AND_NULL(editor_program);\n+\treturn git_config_string(&editor_program, var, value);\n+}\n+\n int is_terminal_dumb(void)\n {\n \tconst char *terminal = getenv(\"TERM\");\ndiff --git a/editor.h b/editor.h\nindex f1c41df378..ced29046f8 100644\n--- a/editor.h\n+++ b/editor.h\n@@ -8,6 +8,8 @@ const char *git_editor(void);\n const char *git_sequence_editor(void);\n int is_terminal_dumb(void);\n\n+int set_editor_program(const char *var, const char *value);\n+\n /**\n  * Launch the user preferred editor to edit a file and fill the buffer\n  * with the file's contents upon the user completing their editing. The\ndiff --git a/environment.c b/environment.c\nindex 0026eb2274..9aa9124328 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -37,6 +37,7 @@\n #include \"setup.h\"\n #include \"ws.h\"\n #include \"write-or-die.h\"\n+#include \"editor.h\"\n\n static int pack_compression_seen;\n static int zlib_compression_seen;\n@@ -61,7 +62,6 @@ int fsync_object_files = -1;\n int use_fsync = -1;\n enum fsync_method fsync_method = FSYNC_METHOD_DEFAULT;\n enum fsync_component fsync_components = FSYNC_COMPONENTS_DEFAULT;\n-char *editor_program;\n char *askpass_program;\n char *excludes_file;\n enum auto_crlf auto_crlf = AUTO_CRLF_FALSE;\n@@ -437,8 +437,7 @@ int git_default_core_config(const char *var, const char *value,\n \t}\n\n \tif (!strcmp(var, \"core.editor\")) {\n-\t\tFREE_AND_NULL(editor_program);\n-\t\treturn git_config_string(&editor_program, var, value);\n+\t\treturn set_editor_program(var, value);\n \t}\n\n \tif (!strcmp(var, \"core.commentchar\") ||\ndiff --git a/environment.h b/environment.h\nindex 27f657af04..053b678786 100644\n--- a/environment.h\n+++ b/environment.h\n@@ -199,7 +199,6 @@ const char *get_commit_output_encoding(void);\n extern char *git_commit_encoding;\n extern char *git_log_output_encoding;\n\n-extern char *editor_program;\n extern char *askpass_program;\n extern char *excludes_file;\n\n--\n2.53.0\n"},{"id":"537437","messageId":"20260301105228.1738388-3-shreyanshpaliwalcmsmn@gmail.com","threadId":"65107","inReplyTo":"20260301105228.1738388-1-shreyanshpaliwalcmsmn@gmail.com","subject":"[GSOC][PATCH 2/2] editor: remove the_repository usage","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-03-01T10:42:59Z","receivedAt":"2026-03-01T10:53:52Z","isPatch":true,"sender":{"key":"shreyanshpaliwalcmsmn@gmail.com","avatar":"https://avatars.githubusercontent.com/u/152720574?v=4"},"body":"git_sequence_editor() reads sequence.editor using the_repository. Pass\nstruct repository through the callers instead of relying on the global\nstate. It is called from,\n\n* builtin/var.c: Mostly the_repository is used in all the functions and\n  there is no proper local access to a repository, so pass the_repository.\n\n* editor.c: The caller is inside launch_sequence_editor() function which is\n  called from rebase-interactive.c:edit_todo_list(), which does have a\n  local repository instance, so pass it down the caller.\n\nWith no remaining global states in editor.c remove '#define\nUSE_THE_REPOSITORY_VARIABLE'. This removes another dependency on\nthe_repository and keeps editor code consistent with the ongoing effort to\nreduce global state.\n\nSigned-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>\n---\n builtin/var.c        |  2 +-\n editor.c             | 10 ++++------\n editor.h             |  4 ++--\n rebase-interactive.c |  2 +-\n 4 files changed, 8 insertions(+), 10 deletions(-)\n\ndiff --git a/builtin/var.c b/builtin/var.c\nindex cc3a43cde2..7da263b129 100644\n--- a/builtin/var.c\n+++ b/builtin/var.c\n@@ -38,7 +38,7 @@ static char *editor(int ident_flag UNUSED)\n\n static char *sequence_editor(int ident_flag UNUSED)\n {\n-\treturn xstrdup_or_null(git_sequence_editor());\n+\treturn xstrdup_or_null(git_sequence_editor(the_repository));\n }\n\n static char *pager(int ident_flag UNUSED)\ndiff --git a/editor.c b/editor.c\nindex b509d23f3b..1f97c362c2 100644\n--- a/editor.c\n+++ b/editor.c\n@@ -1,5 +1,3 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n-\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n #include \"advice.h\"\n@@ -53,12 +51,12 @@ const char *git_editor(void)\n \treturn editor;\n }\n\n-const char *git_sequence_editor(void)\n+const char *git_sequence_editor(struct repository *r)\n {\n \tconst char *editor = getenv(\"GIT_SEQUENCE_EDITOR\");\n\n \tif (!editor)\n-\t\trepo_config_get_string_tmp(the_repository, \"sequence.editor\", &editor);\n+\t\trepo_config_get_string_tmp(r, \"sequence.editor\", &editor);\n \tif (!editor)\n \t\teditor = git_editor();\n\n@@ -138,9 +136,9 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en\n }\n\n int launch_sequence_editor(const char *path, struct strbuf *buffer,\n-\t\t\t   const char *const *env)\n+\t\t\t   const char *const *env, struct repository *r)\n {\n-\treturn launch_specified_editor(git_sequence_editor(), path, buffer, env);\n+\treturn launch_specified_editor(git_sequence_editor(r), path, buffer, env);\n }\n\n int strbuf_edit_interactively(struct repository *r,\ndiff --git a/editor.h b/editor.h\nindex ced29046f8..bcd0cebc85 100644\n--- a/editor.h\n+++ b/editor.h\n@@ -5,7 +5,7 @@ struct repository;\n struct strbuf;\n\n const char *git_editor(void);\n-const char *git_sequence_editor(void);\n+const char *git_sequence_editor(struct repository *r);\n int is_terminal_dumb(void);\n\n int set_editor_program(const char *var, const char *value);\n@@ -21,7 +21,7 @@ int launch_editor(const char *path, struct strbuf *buffer,\n \t\t  const char *const *env);\n\n int launch_sequence_editor(const char *path, struct strbuf *buffer,\n-\t\t\t   const char *const *env);\n+\t\t\t   const char *const *env, struct repository *r);\n\n /*\n  * In contrast to `launch_editor()`, this function writes out the contents\ndiff --git a/rebase-interactive.c b/rebase-interactive.c\nindex 809f76a87b..405ef353af 100644\n--- a/rebase-interactive.c\n+++ b/rebase-interactive.c\n@@ -132,7 +132,7 @@ int edit_todo_list(struct repository *r, struct replay_opts *opts,\n \t\t\t\t    (flags | TODO_LIST_APPEND_TODO_HELP) & ~TODO_LIST_SHORTEN_IDS) < 0)\n \t\treturn error(_(\"could not write '%s'.\"), rebase_path_todo_backup());\n\n-\tif (launch_sequence_editor(todo_file, &new_todo->buf, NULL))\n+\tif (launch_sequence_editor(todo_file, &new_todo->buf, NULL, r))\n \t\treturn -2;\n\n \tstrbuf_stripspace(&new_todo->buf, comment_line_str);\n--\n2.53.0\n\n"},{"id":"537438","messageId":"aaQzlE2lsq4WfFxt@fedora","threadId":"65107","inReplyTo":"20260301105228.1738388-2-shreyanshpaliwalcmsmn@gmail.com","subject":"Re: [GSOC][PATCH 1/2] editor: make editor_program local to editor.c","fromName":"Burak Kaan Karaçay","fromEmail":"bkkaracay@gmail.com","sentAt":"2026-03-01T13:19:02Z","receivedAt":"2026-03-01T13:19:12Z","isPatch":true,"sender":{"key":"bkkaracay@gmail.com","avatar":"https://avatars.githubusercontent.com/u/29117336?v=4"},"body":"Hi Shreyansh,\n\nI am a GSoC applicant like you. I just wanted to leave my two cents \nhere.\n\nOn Sun, Mar 01, 2026 at 04:12:58PM +0530, Shreyansh Paliwal wrote:\n>+static char *editor_program;\n>+\n>+int set_editor_program(const char *var, const char *value)\n>+{\n>+\tFREE_AND_NULL(editor_program);\n>+\treturn git_config_string(&editor_program, var, value);\n>+}\n>+\n\nWhile moving the global variable from 'environment.c' to 'editor.c'\ndoesn't cause any behavior change, it still relies on global state.\n\nI think passing a 'struct repository' and using the 'repo_config_get*'\nhelpers here might be a more robust approach. I know this means we would\ncatch config errors later (right before the editor start up). However,\nsince it doesn't seem like it would cause a data loss or serious issues,\nthis behavioral change feels like a reasonable trade-off.\n\nThanks again for the patches!\n\nBest,\nBurak Kaan Karaçay\n"},{"id":"537446","messageId":"20260301154905.13993-1-shreyanshpaliwalcmsmn@gmail.com","threadId":"65107","inReplyTo":"aaQzlE2lsq4WfFxt@fedora","subject":"Re: [GSOC][PATCH 1/2] editor: make editor_program local to editor.c","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-03-01T15:42:30Z","receivedAt":"2026-03-01T15:49:39Z","isPatch":true,"sender":{"key":"shreyanshpaliwalcmsmn@gmail.com","avatar":"https://avatars.githubusercontent.com/u/152720574?v=4"},"body":"> Hi Shreyansh,\n>\n> I am a GSoC applicant like you. I just wanted to leave my two cents\n> here.\n>\n> On Sun, Mar 01, 2026 at 04:12:58PM +0530, Shreyansh Paliwal wrote:\n> >+static char *editor_program;\n> >+\n> >+int set_editor_program(const char *var, const char *value)\n> >+{\n> >+\tFREE_AND_NULL(editor_program);\n> >+\treturn git_config_string(&editor_program, var, value);\n> >+}\n> >+\n>\n> While moving the global variable from 'environment.c' to 'editor.c'\n> doesn't cause any behavior change, it still relies on global state.\n>\n> I think passing a 'struct repository' and using the 'repo_config_get*'\n> helpers here might be a more robust approach. I know this means we would\n> catch config errors later (right before the editor start up). However,\n> since it doesn't seem like it would cause a data loss or serious issues,\n> this behavioral change feels like a reasonable trade-off.\n>\n> Thanks again for the patches!\n\nHi Burak,\n\nThanks for the feedback on this, I appreciate you taking the time to look.\n\nI did consider the approach you suggested. Currently, editor_program is\nonly used within editor.c, and it is I believe a process-wide setting rather\nthan something tied to a specific repository. Because of that, it did not\nseem necessary to add it to struct repository or repo_settings at this stage.\n\nMore importantly, my intention for this was to keep original behavior as-is.\nAs noted in earlier discussions [1][2], maintaining early config validation\nis important so that invalid core.editor values are caught early. Moving to\na repo-based lazy lookup would change that.\n\nThat said, I agree that there may be a better way to do this refactor,\nso I'd be glad to hear more thoughts on this :)\n\nBest,\nShreyansh\n\n[1]- https://lore.kernel.org/git/1d43d1d0-bf6b-4806-834e-89f545fab766@gmail.com/\n[2]- https://lore.kernel.org/git/xmqqpl63b2tm.fsf@gitster.g/\n"},{"id":"537447","messageId":"8e657184-ee0b-453a-9f2d-a98080d3582e@gmail.com","threadId":"65107","inReplyTo":"aaQzlE2lsq4WfFxt@fedora","subject":"Re: [GSOC][PATCH 1/2] editor: make editor_program local to editor.c","fromName":"Phillip Wood","fromEmail":"phillip.wood123@gmail.com","sentAt":"2026-03-01T16:22:38Z","receivedAt":"2026-03-01T16:22:42Z","isPatch":true,"sender":{"key":"phillip.wood@dunelm.org.uk","avatar":null},"body":"Hi Burak\n\nOn 01/03/2026 13:19, Burak Kaan Karaçay wrote:\n> Hi Shreyansh,\n> \n> I am a GSoC applicant like you. I just wanted to leave my two cents here.\n> \n> On Sun, Mar 01, 2026 at 04:12:58PM +0530, Shreyansh Paliwal wrote:\n>> +static char *editor_program;\n>> +\n>> +int set_editor_program(const char *var, const char *value)\n>> +{\n>> +    FREE_AND_NULL(editor_program);\n>> +    return git_config_string(&editor_program, var, value);\n>> +}\n>> +\n> \n> While moving the global variable from 'environment.c' to 'editor.c'\n> doesn't cause any behavior change, it still relies on global state.\n\nThat's true, but does it really make sense for this config setting \nper-repository? Why would I want to use different editors for different \nrepositories in the same process?\n\nThanks\n\nPhillip\n\n> I think passing a 'struct repository' and using the 'repo_config_get*'\n> helpers here might be a more robust approach. I know this means we would\n> catch config errors later (right before the editor start up). However,\n> since it doesn't seem like it would cause a data loss or serious issues,\n> this behavioral change feels like a reasonable trade-off.\n> \n> Thanks again for the patches!\n> \n> Best,\n> Burak Kaan Karaçay\n> \n\n"},{"id":"537448","messageId":"feafa9bf-b1a3-4067-8b2f-5dbad1940578@gmail.com","threadId":"65107","inReplyTo":"20260301105228.1738388-1-shreyanshpaliwalcmsmn@gmail.com","subject":"Re: [GSOC][PATCH 0/2] Remove global state from editor.c","fromName":"Tian Yuchen","fromEmail":"a3205153416@gmail.com","sentAt":"2026-03-01T16:39:33Z","receivedAt":"2026-03-01T16:39:39Z","isPatch":true,"sender":{"key":"cat@malon.dev","avatar":"https://avatars.githubusercontent.com/u/232002048?v=4"},"body":"Hi Shreyansh and Burak,\n\nThanks for the patch.\n\nReading through discussion, I think both of you highlighted very valid \nconstraints:\n\n> While moving the global variable from 'environment.c' to 'editor.c'\n> doesn't cause any behavior change, it still relies on global state.\n\nYes, changing an extern to a static variable doesn't truly remove the \nglobal state, right?\n\n> More importantly, my intention for this was to keep original behavior as-is.\n> As noted in earlier discussions [1][2], maintaining early config validation\n> is important so that invalid core.editor values are caught early. Moving to\n> a repo-based lazy lookup would change that.\n\nThis one also makes sense to me.\n\nHowever,\n\n> I believe a process-wide setting rather\n> than something tied to a specific repository.\n\nI have reservations about this, and I believe this is the most critical \nissue. For instance, we can run:\n\n\tgit config --local core.editor \"nvim\"\n\nwhere the configuration is written in the .git/config of the current \nrepository. If core.editor is process-wide, git should not permit the \nexistence of a \"local\" core.editor at all. Since it can be set for \nindividual repositories, it should be tied to the specific struct \nrepository, right?\n\nA more intuitive case is:\n\n\tRepo A: core.editor = vim\n\tRepo B: core.editor = nvim\n\nFor users managing multiple repositories (submodules), it's perfectly \nreasonable to use different editors in different contexts. At least for \nme, I use different configurations for Vim and NVim, and I switch \nbetween different editors when writing with different languages. (like \nset textwidth=72 for Git? _(:3 ⌒ﾞ)_)\n\nI recently faced the same dilemma migrating git_commit_encoding and \ngit_log_output_encoding. I personally believe that adding editor_program \nto repo-settings.c is the best approach.\n\nBy doing this:\n\n- We truly eliminate the global state. Each struct repository gets its \nown editor setting.\n\n- We maintain early validation. The config can still be parsed early \n(e.g., during prepare_repo_settings()?)\n\nThanks again for the patch.\n\nRegards,\n\nYuchen\n\n\n"},{"id":"537453","messageId":"aaRzdeg2BkAKa-4J@fedora","threadId":"65107","inReplyTo":"8e657184-ee0b-453a-9f2d-a98080d3582e@gmail.com","subject":"Re: [GSOC][PATCH 1/2] editor: make editor_program local to editor.c","fromName":"Burak Kaan Karaçay","fromEmail":"bkkaracay@gmail.com","sentAt":"2026-03-01T18:30:09Z","receivedAt":"2026-03-01T18:30:20Z","isPatch":true,"sender":{"key":"bkkaracay@gmail.com","avatar":"https://avatars.githubusercontent.com/u/29117336?v=4"},"body":"On Sun, Mar 01, 2026 at 04:22:38PM +0000, Phillip Wood wrote:\n>>While moving the global variable from 'environment.c' to 'editor.c'\n>>doesn't cause any behavior change, it still relies on global state.\n>\n>That's true, but does it really make sense for this config setting \n>per-repository? Why would I want to use different editors for \n>different repositories in the same process?\n>\n>Thanks\n>\n>Phillip\n\nIn practical sense, yes, it's true. Users generally don't use different\neditors for different repositories. For repository dependent settings \n.editorconfig mostly cover all scenarios.\n\nHowever, as far as I know git doesn't have a system-wide only\nconfiguration settings. These changes mostly serve to libification\nprocess of git. If we leave 'core.editor' setting as a global variable \nand user tries to interact with multiple repositories that have\ndifferent editor configurations using our libified git, it can mix up\nthe configs of two repositories.\n\nIf we really want to keep these variables independent from repositories,\nwe should probably prohibit 'core.editor' setting in local repository\nconfigs. Otherwise, leaving it global seems like a weird behavioral\nchoice.\n\nThanks,\nBurak Kaan Karaçay\n"},{"id":"538258","messageId":"CAOLa=ZR1_OMnVNKeiZiWDLBBXCtxNveKCgjjTFQAYYCCjqbZ0Q@mail.gmail.com","threadId":"65107","inReplyTo":"aaRzdeg2BkAKa-4J@fedora","subject":"Re: [GSOC][PATCH 1/2] editor: make editor_program local to editor.c","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2026-03-09T10:36:29Z","receivedAt":"2026-03-09T10:36:31Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"Burak Kaan Karaçay <bkkaracay@gmail.com> writes:\n\n> On Sun, Mar 01, 2026 at 04:22:38PM +0000, Phillip Wood wrote:\n>>>While moving the global variable from 'environment.c' to 'editor.c'\n>>>doesn't cause any behavior change, it still relies on global state.\n>>\n>>That's true, but does it really make sense for this config setting\n>>per-repository? Why would I want to use different editors for\n>>different repositories in the same process?\n>>\n>>Thanks\n>>\n>>Phillip\n>\n> In practical sense, yes, it's true. Users generally don't use different\n> editors for different repositories. For repository dependent settings\n> .editorconfig mostly cover all scenarios.\n>\n> However, as far as I know git doesn't have a system-wide only\n> configuration settings. These changes mostly serve to libification\n> process of git. If we leave 'core.editor' setting as a global variable\n> and user tries to interact with multiple repositories that have\n> different editor configurations using our libified git, it can mix up\n> the configs of two repositories.\n>\n> If we really want to keep these variables independent from repositories,\n> we should probably prohibit 'core.editor' setting in local repository\n> configs. Otherwise, leaving it global seems like a weird behavioral\n> choice.\n>\n> Thanks,\n> Burak Kaan Karaçay\n\nI do agree with the point you're making, true isolation for libification\nwould indeed require that this variable is not a global variable.\n\nBut, while libification is the destination, steps in that direction\nshould be welcome, and I think one step is to simply localize the global\nvariables.\n\nAlso bloating up `struct repository` without much thought might not be a\ngood decision either.\n"},{"id":"538260","messageId":"CAOLa=ZQaLRBxjbD9yPJd3ksvAgnpyuCAKM=Y5YXvwVgw-0AzmQ@mail.gmail.com","threadId":"65107","inReplyTo":"20260301105228.1738388-3-shreyanshpaliwalcmsmn@gmail.com","subject":"Re: [GSOC][PATCH 2/2] editor: remove the_repository usage","fromName":"Karthik Nayak","fromEmail":"karthik.188@gmail.com","sentAt":"2026-03-09T10:37:34Z","receivedAt":"2026-03-09T10:37:36Z","isPatch":true,"sender":{"key":"karthik.188@gmail.com","avatar":"https://avatars.githubusercontent.com/u/1786334?v=4"},"body":"Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com> writes:\n\n> git_sequence_editor() reads sequence.editor using the_repository. Pass\n> struct repository through the callers instead of relying on the global\n> state. It is called from,\n>\n> * builtin/var.c: Mostly the_repository is used in all the functions and\n>   there is no proper local access to a repository, so pass the_repository.\n>\n> * editor.c: The caller is inside launch_sequence_editor() function which is\n>   called from rebase-interactive.c:edit_todo_list(), which does have a\n>   local repository instance, so pass it down the caller.\n>\n> With no remaining global states in editor.c remove '#define\n> USE_THE_REPOSITORY_VARIABLE'. This removes another dependency on\n> the_repository and keeps editor code consistent with the ongoing effort to\n> reduce global state.\n>\n\nWell explained, the patch looks good to me.\n"},{"id":"538485","messageId":"20260310174519.676851-1-shreyanshpaliwalcmsmn@gmail.com","threadId":"65107","inReplyTo":"20260301105228.1738388-1-shreyanshpaliwalcmsmn@gmail.com","subject":"[GSOC][PATCH v2 0/2] Remove global state from editor.c","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-03-10T17:40:47Z","receivedAt":"2026-03-10T17:45:37Z","isPatch":true,"sender":{"key":"shreyanshpaliwalcmsmn@gmail.com","avatar":"https://avatars.githubusercontent.com/u/152720574?v=4"},"body":"This series reduces reliance on global states. Mainly there\nare two such global states in editor.c,\n\n* editor_program: defined in environment.c and populated during config\n  parsing, but only used by editor.c via git_editor().\n\n* the_repository: used in git_sequence_editor() to read the sequence.editor\n  configuration.\n\nIn patch 1/2, localize editor_program to editor.c by introducing a helper\nthat allows git_default_core_config() to continue initializing the value\nduring initial config parsing.\n\nIn patch 2/2, remove the remaining use of the_repository in editor.c by\npassing struct repository through git_sequence_editor() and its\ncallers. With this change, editor.c no longer requires\n'USE_THE_REPOSITORY_VARIABLE' and 'environment.h' include.\n\nShreyansh Paliwal (2):\n  editor: make editor_program local to editor.c\n  editor: remove the_repository usage\n\n builtin/var.c        |  2 +-\n editor.c             | 19 ++++++++++++-------\n editor.h             |  6 ++++--\n environment.c        |  5 ++---\n environment.h        |  1 -\n rebase-interactive.c |  2 +-\n 6 files changed, 20 insertions(+), 15 deletions(-)\n\n---\nChanges in v2:\n - removed 'environment.h' dependency from editor.c as well.\n\nRange-diff against v1:\n-:  ---------- > 1:  6f8b82fed5 editor: make editor_program local to editor.c\n1:  f9ef18b77a ! 2:  5b858c7e98 editor: remove the_repository usage\n    @@ Commit message\n           local repository instance, so pass it down the caller.\n\n         With no remaining global states in editor.c remove '#define\n    -    USE_THE_REPOSITORY_VARIABLE'. This removes another dependency on\n    -    the_repository and keeps editor code consistent with the ongoing effort to\n    -    reduce global state.\n    +    USE_THE_REPOSITORY_VARIABLE' and drop the dependency on 'environment.h'.\n    +    This removes another dependency on the_repository and keeps editor code\n    +    consistent with the ongoing effort to reduce global state.\n\n         Signed-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>\n\n    @@ editor.c\n      #include \"git-compat-util.h\"\n      #include \"abspath.h\"\n      #include \"advice.h\"\n    + #include \"config.h\"\n    + #include \"editor.h\"\n    +-#include \"environment.h\"\n    + #include \"gettext.h\"\n    + #include \"pager.h\"\n    + #include \"path.h\"\n     @@ editor.c: const char *git_editor(void)\n      \treturn editor;\n      }\n--\n2.53.0\n\n"},{"id":"538486","messageId":"20260310174519.676851-2-shreyanshpaliwalcmsmn@gmail.com","threadId":"65107","inReplyTo":"20260310174519.676851-1-shreyanshpaliwalcmsmn@gmail.com","subject":"[GSOC][PATCH v2 1/2] editor: make editor_program local to editor.c","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-03-10T17:40:48Z","receivedAt":"2026-03-10T17:45:42Z","isPatch":true,"sender":{"key":"shreyanshpaliwalcmsmn@gmail.com","avatar":"https://avatars.githubusercontent.com/u/152720574?v=4"},"body":"editor_program is a global variable defined in environment.c, which is set\nby git_default_core_config(), but is used only by editor.c only in the\nfunction git_editor().\n\nRemove the global from the environment.c and localize it in editor.c.\nIntroduce a helper for setting the local editor_program variable by the\nhelp of git_config_string(). Call this helper in the core.editor part of\nthe git_default_core_config().\n\nThis keeps the existing initialization timing and availability of the\nvariable, so invalid core.editor values are still reported early during\nstartup, causing no ux regression.\n\nSigned-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>\n---\n editor.c      | 8 ++++++++\n editor.h      | 2 ++\n environment.c | 5 ++---\n environment.h | 1 -\n 4 files changed, 12 insertions(+), 4 deletions(-)\n\ndiff --git a/editor.c b/editor.c\nindex fd174e6a03..b509d23f3b 100644\n--- a/editor.c\n+++ b/editor.c\n@@ -18,6 +18,14 @@\n #define DEFAULT_EDITOR \"vi\"\n #endif\n\n+static char *editor_program;\n+\n+int set_editor_program(const char *var, const char *value)\n+{\n+\tFREE_AND_NULL(editor_program);\n+\treturn git_config_string(&editor_program, var, value);\n+}\n+\n int is_terminal_dumb(void)\n {\n \tconst char *terminal = getenv(\"TERM\");\ndiff --git a/editor.h b/editor.h\nindex f1c41df378..ced29046f8 100644\n--- a/editor.h\n+++ b/editor.h\n@@ -8,6 +8,8 @@ const char *git_editor(void);\n const char *git_sequence_editor(void);\n int is_terminal_dumb(void);\n\n+int set_editor_program(const char *var, const char *value);\n+\n /**\n  * Launch the user preferred editor to edit a file and fill the buffer\n  * with the file's contents upon the user completing their editing. The\ndiff --git a/environment.c b/environment.c\nindex 0026eb2274..9aa9124328 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -37,6 +37,7 @@\n #include \"setup.h\"\n #include \"ws.h\"\n #include \"write-or-die.h\"\n+#include \"editor.h\"\n\n static int pack_compression_seen;\n static int zlib_compression_seen;\n@@ -61,7 +62,6 @@ int fsync_object_files = -1;\n int use_fsync = -1;\n enum fsync_method fsync_method = FSYNC_METHOD_DEFAULT;\n enum fsync_component fsync_components = FSYNC_COMPONENTS_DEFAULT;\n-char *editor_program;\n char *askpass_program;\n char *excludes_file;\n enum auto_crlf auto_crlf = AUTO_CRLF_FALSE;\n@@ -437,8 +437,7 @@ int git_default_core_config(const char *var, const char *value,\n \t}\n\n \tif (!strcmp(var, \"core.editor\")) {\n-\t\tFREE_AND_NULL(editor_program);\n-\t\treturn git_config_string(&editor_program, var, value);\n+\t\treturn set_editor_program(var, value);\n \t}\n\n \tif (!strcmp(var, \"core.commentchar\") ||\ndiff --git a/environment.h b/environment.h\nindex 27f657af04..053b678786 100644\n--- a/environment.h\n+++ b/environment.h\n@@ -199,7 +199,6 @@ const char *get_commit_output_encoding(void);\n extern char *git_commit_encoding;\n extern char *git_log_output_encoding;\n\n-extern char *editor_program;\n extern char *askpass_program;\n extern char *excludes_file;\n\n--\n2.53.0\n\n"},{"id":"538487","messageId":"20260310174519.676851-3-shreyanshpaliwalcmsmn@gmail.com","threadId":"65107","inReplyTo":"20260310174519.676851-1-shreyanshpaliwalcmsmn@gmail.com","subject":"[GSOC][PATCH v2 2/2] editor: remove the_repository usage","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-03-10T17:40:49Z","receivedAt":"2026-03-10T17:45:46Z","isPatch":true,"sender":{"key":"shreyanshpaliwalcmsmn@gmail.com","avatar":"https://avatars.githubusercontent.com/u/152720574?v=4"},"body":"git_sequence_editor() reads sequence.editor using the_repository. Pass\nstruct repository through the callers instead of relying on the global\nstate. It is called from,\n\n- builtin/var.c: Mostly the_repository is used in all the functions and\n  there is no proper local access to a repository, so pass the_repository.\n\n- editor.c: The caller is inside launch_sequence_editor() function which is\n  called from rebase-interactive.c:edit_todo_list(), which does have a\n  local repository instance, so pass it down the caller.\n\nWith no remaining global states in editor.c remove '#define\nUSE_THE_REPOSITORY_VARIABLE' and drop the dependency on 'environment.h'.\nThis removes another dependency on the_repository and keeps editor code\nconsistent with the ongoing effort to reduce global state.\n\nSigned-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>\n---\n builtin/var.c        |  2 +-\n editor.c             | 11 ++++-------\n editor.h             |  4 ++--\n rebase-interactive.c |  2 +-\n 4 files changed, 8 insertions(+), 11 deletions(-)\n\ndiff --git a/builtin/var.c b/builtin/var.c\nindex cc3a43cde2..7da263b129 100644\n--- a/builtin/var.c\n+++ b/builtin/var.c\n@@ -38,7 +38,7 @@ static char *editor(int ident_flag UNUSED)\n\n static char *sequence_editor(int ident_flag UNUSED)\n {\n-\treturn xstrdup_or_null(git_sequence_editor());\n+\treturn xstrdup_or_null(git_sequence_editor(the_repository));\n }\n\n static char *pager(int ident_flag UNUSED)\ndiff --git a/editor.c b/editor.c\nindex b509d23f3b..b78c8a687f 100644\n--- a/editor.c\n+++ b/editor.c\n@@ -1,11 +1,8 @@\n-#define USE_THE_REPOSITORY_VARIABLE\n-\n #include \"git-compat-util.h\"\n #include \"abspath.h\"\n #include \"advice.h\"\n #include \"config.h\"\n #include \"editor.h\"\n-#include \"environment.h\"\n #include \"gettext.h\"\n #include \"pager.h\"\n #include \"path.h\"\n@@ -53,12 +50,12 @@ const char *git_editor(void)\n \treturn editor;\n }\n\n-const char *git_sequence_editor(void)\n+const char *git_sequence_editor(struct repository *r)\n {\n \tconst char *editor = getenv(\"GIT_SEQUENCE_EDITOR\");\n\n \tif (!editor)\n-\t\trepo_config_get_string_tmp(the_repository, \"sequence.editor\", &editor);\n+\t\trepo_config_get_string_tmp(r, \"sequence.editor\", &editor);\n \tif (!editor)\n \t\teditor = git_editor();\n\n@@ -138,9 +135,9 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en\n }\n\n int launch_sequence_editor(const char *path, struct strbuf *buffer,\n-\t\t\t   const char *const *env)\n+\t\t\t   const char *const *env, struct repository *r)\n {\n-\treturn launch_specified_editor(git_sequence_editor(), path, buffer, env);\n+\treturn launch_specified_editor(git_sequence_editor(r), path, buffer, env);\n }\n\n int strbuf_edit_interactively(struct repository *r,\ndiff --git a/editor.h b/editor.h\nindex ced29046f8..bcd0cebc85 100644\n--- a/editor.h\n+++ b/editor.h\n@@ -5,7 +5,7 @@ struct repository;\n struct strbuf;\n\n const char *git_editor(void);\n-const char *git_sequence_editor(void);\n+const char *git_sequence_editor(struct repository *r);\n int is_terminal_dumb(void);\n\n int set_editor_program(const char *var, const char *value);\n@@ -21,7 +21,7 @@ int launch_editor(const char *path, struct strbuf *buffer,\n \t\t  const char *const *env);\n\n int launch_sequence_editor(const char *path, struct strbuf *buffer,\n-\t\t\t   const char *const *env);\n+\t\t\t   const char *const *env, struct repository *r);\n\n /*\n  * In contrast to `launch_editor()`, this function writes out the contents\ndiff --git a/rebase-interactive.c b/rebase-interactive.c\nindex 809f76a87b..405ef353af 100644\n--- a/rebase-interactive.c\n+++ b/rebase-interactive.c\n@@ -132,7 +132,7 @@ int edit_todo_list(struct repository *r, struct replay_opts *opts,\n \t\t\t\t    (flags | TODO_LIST_APPEND_TODO_HELP) & ~TODO_LIST_SHORTEN_IDS) < 0)\n \t\treturn error(_(\"could not write '%s'.\"), rebase_path_todo_backup());\n\n-\tif (launch_sequence_editor(todo_file, &new_todo->buf, NULL))\n+\tif (launch_sequence_editor(todo_file, &new_todo->buf, NULL, r))\n \t\treturn -2;\n\n \tstrbuf_stripspace(&new_todo->buf, comment_line_str);\n--\n2.53.0\n\n"},{"id":"539230","messageId":"20260317160539.621560-1-shreyanshpaliwalcmsmn@gmail.com","threadId":"65107","inReplyTo":"20260310174519.676851-1-shreyanshpaliwalcmsmn@gmail.com","subject":"Re: [GSOC][PATCH v2 0/2] Remove global state from editor.c","fromName":"Shreyansh Paliwal","fromEmail":"shreyanshpaliwalcmsmn@gmail.com","sentAt":"2026-03-17T16:03:57Z","receivedAt":"2026-03-17T16:05:55Z","isPatch":true,"sender":{"key":"shreyanshpaliwalcmsmn@gmail.com","avatar":"https://avatars.githubusercontent.com/u/152720574?v=4"},"body":"> This series reduces reliance on global states. Mainly there\n> are two such global states in editor.c,\n>\n> * editor_program: defined in environment.c and populated during config\n>   parsing, but only used by editor.c via git_editor().\n>\n> * the_repository: used in git_sequence_editor() to read the sequence.editor\n>   configuration.\n>\n> In patch 1/2, localize editor_program to editor.c by introducing a helper\n> that allows git_default_core_config() to continue initializing the value\n> during initial config parsing.\n>\n> In patch 2/2, remove the remaining use of the_repository in editor.c by\n> passing struct repository through git_sequence_editor() and its\n> callers. With this change, editor.c no longer requires\n> 'USE_THE_REPOSITORY_VARIABLE' and 'environment.h' include.\n>\n> Shreyansh Paliwal (2):\n>   editor: make editor_program local to editor.c\n>   editor: remove the_repository usage\n>\n>  builtin/var.c        |  2 +-\n>  editor.c             | 19 ++++++++++++-------\n>  editor.h             |  6 ++++--\n>  environment.c        |  5 ++---\n>  environment.h        |  1 -\n>  rebase-interactive.c |  2 +-\n>  6 files changed, 20 insertions(+), 15 deletions(-)\n>\n> ---\n> Changes in v2:\n>  - removed 'environment.h' dependency from editor.c as well.\n>\n\nHi,\n\nSorry for the late follow-up, I was tied up with my college exams.\nI just wanted to check if there is any specific feedback or concern\nthat is holding this series back. Do let me know :)\n\nBest,\nShreyansh\n"}]}