public inbox for git@vger.kernel.org 
 help / color / mirror / Atom feed
From: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail•com>
To: git@vger•kernel.org
Cc: gitster@pobox•com, christian.couder@gmail•com,
	karthik.188@gmail•com, jltobler@gmail•com,
	ayu.chandekar@gmail•com, siddharthasthana31@gmail•com,
	lucasseikioshiro@gmail•com,
	Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail•com>
Subject: [GSOC][PATCH 2/2] editor: remove the_repository usage
Date: Sun,  1 Mar 2026 16:12:59 +0530	[thread overview]
Message-ID: <20260301105228.1738388-3-shreyanshpaliwalcmsmn@gmail.com> (raw)
In-Reply-To: <20260301105228.1738388-1-shreyanshpaliwalcmsmn@gmail.com>

git_sequence_editor() reads sequence.editor using the_repository. Pass
struct repository through the callers instead of relying on the global
state. It is called from,

* builtin/var.c: Mostly the_repository is used in all the functions and
  there is no proper local access to a repository, so pass the_repository.

* editor.c: The caller is inside launch_sequence_editor() function which is
  called from rebase-interactive.c:edit_todo_list(), which does have a
  local repository instance, so pass it down the caller.

With no remaining global states in editor.c remove '#define
USE_THE_REPOSITORY_VARIABLE'. This removes another dependency on
the_repository and keeps editor code consistent with the ongoing effort to
reduce global state.

Signed-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail•com>
---
 builtin/var.c        |  2 +-
 editor.c             | 10 ++++------
 editor.h             |  4 ++--
 rebase-interactive.c |  2 +-
 4 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/builtin/var.c b/builtin/var.c
index cc3a43cde2..7da263b129 100644
--- a/builtin/var.c
+++ b/builtin/var.c
@@ -38,7 +38,7 @@ static char *editor(int ident_flag UNUSED)

 static char *sequence_editor(int ident_flag UNUSED)
 {
-	return xstrdup_or_null(git_sequence_editor());
+	return xstrdup_or_null(git_sequence_editor(the_repository));
 }

 static char *pager(int ident_flag UNUSED)
diff --git a/editor.c b/editor.c
index b509d23f3b..1f97c362c2 100644
--- a/editor.c
+++ b/editor.c
@@ -1,5 +1,3 @@
-#define USE_THE_REPOSITORY_VARIABLE
-
 #include "git-compat-util.h"
 #include "abspath.h"
 #include "advice.h"
@@ -53,12 +51,12 @@ const char *git_editor(void)
 	return editor;
 }

-const char *git_sequence_editor(void)
+const char *git_sequence_editor(struct repository *r)
 {
 	const char *editor = getenv("GIT_SEQUENCE_EDITOR");

 	if (!editor)
-		repo_config_get_string_tmp(the_repository, "sequence.editor", &editor);
+		repo_config_get_string_tmp(r, "sequence.editor", &editor);
 	if (!editor)
 		editor = git_editor();

@@ -138,9 +136,9 @@ int launch_editor(const char *path, struct strbuf *buffer, const char *const *en
 }

 int launch_sequence_editor(const char *path, struct strbuf *buffer,
-			   const char *const *env)
+			   const char *const *env, struct repository *r)
 {
-	return launch_specified_editor(git_sequence_editor(), path, buffer, env);
+	return launch_specified_editor(git_sequence_editor(r), path, buffer, env);
 }

 int strbuf_edit_interactively(struct repository *r,
diff --git a/editor.h b/editor.h
index ced29046f8..bcd0cebc85 100644
--- a/editor.h
+++ b/editor.h
@@ -5,7 +5,7 @@ struct repository;
 struct strbuf;

 const char *git_editor(void);
-const char *git_sequence_editor(void);
+const char *git_sequence_editor(struct repository *r);
 int is_terminal_dumb(void);

 int set_editor_program(const char *var, const char *value);
@@ -21,7 +21,7 @@ int launch_editor(const char *path, struct strbuf *buffer,
 		  const char *const *env);

 int launch_sequence_editor(const char *path, struct strbuf *buffer,
-			   const char *const *env);
+			   const char *const *env, struct repository *r);

 /*
  * In contrast to `launch_editor()`, this function writes out the contents
diff --git a/rebase-interactive.c b/rebase-interactive.c
index 809f76a87b..405ef353af 100644
--- a/rebase-interactive.c
+++ b/rebase-interactive.c
@@ -132,7 +132,7 @@ int edit_todo_list(struct repository *r, struct replay_opts *opts,
 				    (flags | TODO_LIST_APPEND_TODO_HELP) & ~TODO_LIST_SHORTEN_IDS) < 0)
 		return error(_("could not write '%s'."), rebase_path_todo_backup());

-	if (launch_sequence_editor(todo_file, &new_todo->buf, NULL))
+	if (launch_sequence_editor(todo_file, &new_todo->buf, NULL, r))
 		return -2;

 	strbuf_stripspace(&new_todo->buf, comment_line_str);
--
2.53.0


  parent reply	other threads:[~2026-03-01 10:53 UTC|newest]

Thread overview: 14+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2026-03-01 10:42 [GSOC][PATCH 0/2] Remove global state from editor.c Shreyansh Paliwal
2026-03-01 10:42 ` [GSOC][PATCH 1/2] editor: make editor_program local to editor.c Shreyansh Paliwal
2026-03-01 13:19   ` Burak Kaan Karaçay
2026-03-01 15:42     ` Shreyansh Paliwal
2026-03-01 16:22     ` Phillip Wood
2026-03-01 18:30       ` Burak Kaan Karaçay
2026-03-09 10:36         ` Karthik Nayak
2026-03-01 10:42 ` Shreyansh Paliwal [this message]
2026-03-09 10:37   ` [GSOC][PATCH 2/2] editor: remove the_repository usage Karthik Nayak
2026-03-01 16:39 ` [GSOC][PATCH 0/2] Remove global state from editor.c Tian Yuchen
2026-03-10 17:40 ` [GSOC][PATCH v2 " Shreyansh Paliwal
2026-03-10 17:40   ` [GSOC][PATCH v2 1/2] editor: make editor_program local to editor.c Shreyansh Paliwal
2026-03-10 17:40   ` [GSOC][PATCH v2 2/2] editor: remove the_repository usage Shreyansh Paliwal
2026-03-17 16:03   ` [GSOC][PATCH v2 0/2] Remove global state from editor.c Shreyansh Paliwal

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=20260301105228.1738388-3-shreyanshpaliwalcmsmn@gmail.com \
    --to=shreyanshpaliwalcmsmn@gmail$(echo .)com \
    --cc=ayu.chandekar@gmail$(echo .)com \
    --cc=christian.couder@gmail$(echo .)com \
    --cc=git@vger$(echo .)kernel.org \
    --cc=gitster@pobox$(echo .)com \
    --cc=jltobler@gmail$(echo .)com \
    --cc=karthik.188@gmail$(echo .)com \
    --cc=lucasseikioshiro@gmail$(echo .)com \
    --cc=siddharthasthana31@gmail$(echo .)com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html
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