Message ID | c0bb37db12ea8724431fe4294d591cd8cef73e66.1716877921.git.gitgitgadget@gmail.com (mailing list archive) |
---|---|
State | New, archived |
Headers | show |
Series | Remove some usages of the_repository | expand |
"Philip Peterson via GitGitGadget" <gitgitgadget@gmail.com> writes: > -static int parse_diff(struct add_p_state *s, const struct pathspec *ps) > +static int parse_diff(struct repository *r, struct add_p_state *s, const struct pathspec *ps) Given that add_p_state has add_i_state in it, which in turn as a pointer to the repository, which is initialized like so: int run_add_p(struct repository *r, enum add_p_mode mode, const char *revision, const struct pathspec *ps) { struct add_p_state s = { { r }, STRBUF_INIT, STRBUF_INIT, STRBUF_INIT, STRBUF_INIT }; size_t i, binary_count = 0; init_add_i_state(&s.s, r); this patch looks wrong. Adding a separate repository pointer to the function means you are saying that this function should be able to operate one repository in 'r' that may be DIFFERENT from the repository add_p_state was initialized for. I do not think you are achieving that with this patch (and I do not think such a feature makes much sense, either). Instead just leave everything the same as before, and rewrite things that depend on the_repository (either by explicitly referring to it, or by implicitly using it, like empty_tree_oid_hex() which hardcodes the use of the_hash_algo which is the_repository->hash_algo) to refer to the repository the add_p_state was initialized for.
diff --git a/add-patch.c b/add-patch.c index 2252895c280..b7f09122e1f 100644 --- a/add-patch.c +++ b/add-patch.c @@ -399,7 +399,7 @@ static void complete_file(char marker, struct hunk *hunk) hunk->splittable_into++; } -static int parse_diff(struct add_p_state *s, const struct pathspec *ps) +static int parse_diff(struct repository *r, struct add_p_state *s, const struct pathspec *ps) { struct strvec args = STRVEC_INIT; const char *diff_algorithm = s->s.interactive_diff_algorithm; @@ -419,7 +419,7 @@ 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) ? + repo_get_oid(r, "HEAD", &oid) ? empty_tree_oid_hex() : s->revision); } color_arg_index = args.nr; @@ -1768,7 +1768,7 @@ int run_add_p(struct repository *r, enum add_p_mode mode, (!s.mode->index_only && repo_refresh_and_write_index(r, REFRESH_QUIET, 0, 1, NULL, NULL, NULL) < 0) || - parse_diff(&s, ps) < 0) { + parse_diff(r, &s, ps) < 0) { add_p_state_clear(&s); return -1; }