]> git.ipfire.org Git - thirdparty/git.git/commitdiff
add-patch: use repository instance from add_i_state instead of the_repository
authorShreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>
Tue, 17 Mar 2026 15:50:29 +0000 (21:20 +0530)
committerJunio C Hamano <gitster@pobox.com>
Tue, 17 Mar 2026 16:27:13 +0000 (09:27 -0700)
Functions parse_diff(), edit_hunk_manually() and patch_update_file() use
the_repository even though a repository instance is already available via
struct add_i_state s which is defined in struct add_p_state *s.

Use 's->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 aligns with the ongoing effort to reduce usage of the_repository global
state.

Signed-off-by: Shreyansh Paliwal <shreyanshpaliwalcmsmn@gmail.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
add-patch.c

index 8c03f710d380c1209c18a08db761fd1d64f4cf4f..30df920723a3a9df4d1fdee20864c2c3f6a90715 100644 (file)
@@ -434,8 +434,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->s.r, "HEAD", &oid) ?
+                           empty_tree_oid_hex(s->s.r->hash_algo) : s->revision);
        }
        color_arg_index = args.nr;
        /* Use `--no-color` explicitly, just in case `diff.color = always`. */
@@ -1147,7 +1147,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->s.r, &s->buf,
                                      "addp-hunk-edit.diff", NULL) < 0)
                return -1;
 
@@ -1551,7 +1551,7 @@ static size_t patch_update_file(struct add_p_state *s, size_t idx)
                if (file_diff->hunk_nr) {
                        if (rendered_hunk_index != hunk_index) {
                                if (use_pager) {
-                                       setup_pager(the_repository);
+                                       setup_pager(s->s.r);
                                        sigchain_push(SIGPIPE, SIG_IGN);
                                }
                                render_hunk(s, hunk, 0, colored, &s->buf);