From: Junio C Hamano <gitster@pobox.com>
To: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH v2 ] add-patch: use repository instance from add_p_state instead of the_repository
Date: Wed, 18 Mar 2026 09:43:03 -0700 [thread overview]
Message-ID: <xmqqbjglgkbs.fsf@gitster.g> (raw)
In-Reply-To: <20260318090546.1213077-1-shreyanshpaliwalcmsmn@gmail.com> (Shreyansh Paliwal's message of "Wed, 18 Mar 2026 14:30:03 +0530")
Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com> writes:
> Functions parse_diff(), edit_hunk_manually() and patch_update_file() use
> the_repository even though a repository instance is already available via
> struct add_p_state *s.
> Use 's->r' instead of the_repository to avoid relying on global state.
> All callers pass a valid add_p_state and this does not change any behavior.
>
> This follows recent refactoring that removed 'add_i_state' and moved
> repository pointer and other add-patch config into struct add_p_state [1].
> This aligns with the ongoing effort to reduce usage of the_repository
> global state.
>
> [1]- https://lore.kernel.org/git/20260302-pks-history-split-v1-3-444fc987a324@pks.im/
>
> Signed-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>
> ---
> Changes in v2:
> - made changes on top of ps/history-split and used s->r instead of s->s.r
Good. Brief and clear description on what this patch was based on.
Thanks.
>
> add-patch.c | 8 ++++----
> 1 file changed, 4 insertions(+), 4 deletions(-)
>
> diff --git a/add-patch.c b/add-patch.c
> index 4e28e5c187..f27edcbe8d 100644
> --- a/add-patch.c
> +++ b/add-patch.c
> @@ -558,8 +558,8 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
> strvec_push(&args,
> /* could be on an unborn branch */
> !strcmp("HEAD", s->revision) &&
> - repo_get_oid(the_repository, "HEAD", &oid) ?
> - empty_tree_oid_hex(the_repository->hash_algo) : s->revision);
> + repo_get_oid(s->r, "HEAD", &oid) ?
> + empty_tree_oid_hex(s->r->hash_algo) : s->revision);
> }
> color_arg_index = args.nr;
> /* Use `--no-color` explicitly, just in case `diff.color = always`. */
> @@ -1271,7 +1271,7 @@ static int edit_hunk_manually(struct add_p_state *s, struct hunk *hunk)
> "removed, then the edit is\n"
> "aborted and the hunk is left unchanged.\n"));
>
> - if (strbuf_edit_interactively(the_repository, &s->buf,
> + if (strbuf_edit_interactively(s->r, &s->buf,
> "addp-hunk-edit.diff", NULL) < 0)
> return -1;
>
> @@ -1679,7 +1679,7 @@ static size_t patch_update_file(struct add_p_state *s,
> if (file_diff->hunk_nr) {
> if (rendered_hunk_index != hunk_index) {
> if (use_pager) {
> - setup_pager(the_repository);
> + setup_pager(s->r);
> sigchain_push(SIGPIPE, SIG_IGN);
> }
> render_hunk(s, hunk, 0, colored, &s->buf);
> --
> 2.53.0
prev parent reply other threads:[~2026-03-18 16:43 UTC|newest]
Thread overview: 9+ messages / expand[flat|nested] mbox.gz Atom feed top
2026-03-17 15:50 [PATCH] add-patch: use repository instance from add_i_state instead of the_repository Shreyansh Paliwal
2026-03-17 16:47 ` Junio C Hamano
2026-03-17 16:51 ` Shreyansh Paliwal
2026-03-17 18:04 ` Junio C Hamano
2026-03-17 20:10 ` Junio C Hamano
2026-03-17 20:25 ` Junio C Hamano
2026-03-18 7:01 ` Shreyansh Paliwal
2026-03-18 9:00 ` [PATCH v2 ] add-patch: use repository instance from add_p_state " Shreyansh Paliwal
2026-03-18 16:43 ` Junio C Hamano [this message]
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=xmqqbjglgkbs.fsf@gitster.g \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=shreyanshpaliwalcmsmn@gmail.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
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