Skip to content

Commit 3cfe355

Browse files
shreyp135gitster
authored andcommitted
add-patch: use repository instance from add_i_state instead of the_repository
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>
1 parent ca1db8a commit 3cfe355

1 file changed

Lines changed: 4 additions & 4 deletions

File tree

add-patch.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -434,8 +434,8 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
434434
strvec_push(&args,
435435
/* could be on an unborn branch */
436436
!strcmp("HEAD", s->revision) &&
437-
repo_get_oid(the_repository, "HEAD", &oid) ?
438-
empty_tree_oid_hex(the_repository->hash_algo) : s->revision);
437+
repo_get_oid(s->s.r, "HEAD", &oid) ?
438+
empty_tree_oid_hex(s->s.r->hash_algo) : s->revision);
439439
}
440440
color_arg_index = args.nr;
441441
/* 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)
11471147
"removed, then the edit is\n"
11481148
"aborted and the hunk is left unchanged.\n"));
11491149

1150-
if (strbuf_edit_interactively(the_repository, &s->buf,
1150+
if (strbuf_edit_interactively(s->s.r, &s->buf,
11511151
"addp-hunk-edit.diff", NULL) < 0)
11521152
return -1;
11531153

@@ -1551,7 +1551,7 @@ static size_t patch_update_file(struct add_p_state *s, size_t idx)
15511551
if (file_diff->hunk_nr) {
15521552
if (rendered_hunk_index != hunk_index) {
15531553
if (use_pager) {
1554-
setup_pager(the_repository);
1554+
setup_pager(s->s.r);
15551555
sigchain_push(SIGPIPE, SIG_IGN);
15561556
}
15571557
render_hunk(s, hunk, 0, colored, &s->buf);

0 commit comments

Comments
 (0)