treewide: pass strvecs around for setup_revisions_from_strvec()

The previous commit converted callers of setup_revisions() with a strvec to use the safer and easier _from_strvec() variant. Let's now convert spots that don't directly have a strvec, but receive an argc/argv pair that eventually comes from one. We'll instead pass the strvec down to the point where we call setup_revisions(). That makes these functions slightly less flexible if they were to grow other callers that don't use strvecs, but this rigidity is buying us some safety. It is only safe to pass the free_removed_argv_elements option to setup_revisions() if we know the elements of argv/argc are allocated on the heap. That isn't communicated in the type system when we are passed the bare elements. But if we get a strvec, we know that the elements are allocated strings. And at any rate, each of these modified functions has only a single caller (that has a strvec), so the loss of flexibility is unlikely to ever matter. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Sep 19, 2025 at 18:50 UTC 18068139f2d0fc2aa82f34f2c177d781e228e732
7 files changed +18 -18
builtin/pack-objects.c
+3 -3
@@ -4650,7 +4650,7 @@ static void get_object_list_path_walk(struct rev_info *revs)
4650 die(_("failed to pack objects via path-walk"));
4651 }
4652
4653 -static void get_object_list(struct rev_info *revs, int ac, const char **av)
4653 +static void get_object_list(struct rev_info *revs, struct strvec *argv)
4654 {
4655 struct setup_revision_opt s_r_opt = {
4656 .allow_exclude_promisor_objects = 1,
@@ -4660,7 +4660,7 @@ static void get_object_list(struct rev_info *revs, int ac, const char **av)
4660 int save_warning;
4661
4662 save_commit_buffer = 0;
4663 - setup_revisions(ac, av, revs, &s_r_opt);
4663 + setup_revisions_from_strvec(argv, revs, &s_r_opt);
4664
4665 /* make sure shallows are read */
4666 is_repository_shallow(the_repository);
@@ -5229,7 +5229,7 @@ int cmd_pack_objects(int argc,
5229 revs.include_check = is_not_in_promisor_pack;
5230 revs.include_check_obj = is_not_in_promisor_pack_obj;
5231 }
5232 - get_object_list(&revs, rp.nr, rp.v);
5232 + get_object_list(&revs, &rp);
5233 release_revisions(&revs);
5234 }
5235 cleanup_preferred_base();
builtin/rebase.c
+1 -2
@@ -299,8 +299,7 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)
299 oid_to_hex(&opts->restrict_revision->object.oid));
300
301 ret = sequencer_make_script(the_repository, &todo_list.buf,
302 - make_script_args.nr, make_script_args.v,
303 - flags);
302 + &make_script_args, flags);
303 if (ret) {
304 error(_("could not generate todo list"));
305 goto cleanup;
sequencer.c
+4 -3
@@ -6063,8 +6063,8 @@ static int make_script_with_merges(struct pretty_print_context *pp,
6063 return 0;
6064 }
6065
6066 -int sequencer_make_script(struct repository *r, struct strbuf *out, int argc,
6067 - const char **argv, unsigned flags)
6066 +int sequencer_make_script(struct repository *r, struct strbuf *out,
6067 + struct strvec *argv, unsigned flags)
6068 {
6069 char *format = NULL;
6070 struct pretty_print_context pp = {0};
@@ -6105,7 +6105,8 @@ int sequencer_make_script(struct repository *r, struct strbuf *out, int argc,
6105 pp.fmt = revs.commit_format;
6106 pp.output_encoding = get_log_output_encoding();
6107
6108 - if (setup_revisions(argc, argv, &revs, NULL) > 1) {
6108 + setup_revisions_from_strvec(argv, &revs, NULL);
6109 + if (argv->nr > 1) {
6110 ret = error(_("make_script: unhandled options"));
6111 goto cleanup;
6112 }
sequencer.h
+2 -2
@@ -186,8 +186,8 @@ int sequencer_remove_state(struct replay_opts *opts);
186 #define TODO_LIST_REAPPLY_CHERRY_PICKS (1U << 7)
187 #define TODO_LIST_WARN_SKIPPED_CHERRY_PICKS (1U << 8)
188
189 -int sequencer_make_script(struct repository *r, struct strbuf *out, int argc,
190 - const char **argv, unsigned flags);
189 +int sequencer_make_script(struct repository *r, struct strbuf *out,
190 + struct strvec *argv, unsigned flags);
191
192 int complete_action(struct repository *r, struct replay_opts *opts, unsigned flags,
193 const char *shortrevisions, const char *onto_name,
shallow.c
+2 -2
@@ -213,7 +213,7 @@ static void show_commit(struct commit *commit, void *data)
213 * are marked with shallow_flag. The list of border/shallow commits
214 * are also returned.
215 */
216 -struct commit_list *get_shallow_commits_by_rev_list(int ac, const char **av,
216 +struct commit_list *get_shallow_commits_by_rev_list(struct strvec *argv,
217 int shallow_flag,
218 int not_shallow_flag)
219 {
@@ -232,7 +232,7 @@ struct commit_list *get_shallow_commits_by_rev_list(int ac, const char **av,
232
233 repo_init_revisions(the_repository, &revs, NULL);
234 save_commit_buffer = 0;
235 - setup_revisions(ac, av, &revs, NULL);
235 + setup_revisions_from_strvec(argv, &revs, NULL);
236
237 if (prepare_revision_walk(&revs))
238 die("revision walk setup failed");
shallow.h
+3 -2
@@ -7,6 +7,7 @@
7 #include "strbuf.h"
8
9 struct oid_array;
10 +struct strvec;
11
12 void set_alternate_shallow_file(struct repository *r, const char *path, int override);
13 int register_shallow(struct repository *r, const struct object_id *oid);
@@ -36,8 +37,8 @@ void rollback_shallow_file(struct repository *r, struct shallow_lock *lk);
37
38 struct commit_list *get_shallow_commits(struct object_array *heads,
39 int depth, int shallow_flag, int not_shallow_flag);
39 -struct commit_list *get_shallow_commits_by_rev_list(
40 - int ac, const char **av, int shallow_flag, int not_shallow_flag);
40 +struct commit_list *get_shallow_commits_by_rev_list(struct strvec *argv,
41 + int shallow_flag, int not_shallow_flag);
42 int write_shallow_commits(struct strbuf *out, int use_pack_protocol,
43 const struct oid_array *extra);
44
upload-pack.c
+3 -4
@@ -914,13 +914,12 @@ static void deepen(struct upload_pack_data *data, int depth)
914 }
915
916 static void deepen_by_rev_list(struct upload_pack_data *data,
917 - int ac,
918 - const char **av)
917 + struct strvec *argv)
918 {
919 struct commit_list *result;
920
921 disable_commit_graph(the_repository);
923 - result = get_shallow_commits_by_rev_list(ac, av, SHALLOW, NOT_SHALLOW);
922 + result = get_shallow_commits_by_rev_list(argv, SHALLOW, NOT_SHALLOW);
923 send_shallow(data, result);
924 free_commit_list(result);
925 send_unshallow(data);
@@ -956,7 +955,7 @@ static int send_shallow_list(struct upload_pack_data *data)
955 struct object *o = data->want_obj.objects[i].item;
956 strvec_push(&av, oid_to_hex(&o->oid));
957 }
959 - deepen_by_rev_list(data, av.nr, av.v);
958 + deepen_by_rev_list(data, &av);
959 strvec_clear(&av);
960 ret = 1;
961 } else {