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>
This commit is contained in:
Jeff King
2025-09-19 18:50:48 -04:00
committed by Junio C Hamano
parent b553332f82
commit 18068139f2
7 changed files with 18 additions and 18 deletions

View File

@@ -4650,7 +4650,7 @@ static void get_object_list_path_walk(struct rev_info *revs)
die(_("failed to pack objects via path-walk")); die(_("failed to pack objects via path-walk"));
} }
static void get_object_list(struct rev_info *revs, int ac, const char **av) static void get_object_list(struct rev_info *revs, struct strvec *argv)
{ {
struct setup_revision_opt s_r_opt = { struct setup_revision_opt s_r_opt = {
.allow_exclude_promisor_objects = 1, .allow_exclude_promisor_objects = 1,
@@ -4660,7 +4660,7 @@ static void get_object_list(struct rev_info *revs, int ac, const char **av)
int save_warning; int save_warning;
save_commit_buffer = 0; save_commit_buffer = 0;
setup_revisions(ac, av, revs, &s_r_opt); setup_revisions_from_strvec(argv, revs, &s_r_opt);
/* make sure shallows are read */ /* make sure shallows are read */
is_repository_shallow(the_repository); is_repository_shallow(the_repository);
@@ -5229,7 +5229,7 @@ int cmd_pack_objects(int argc,
revs.include_check = is_not_in_promisor_pack; revs.include_check = is_not_in_promisor_pack;
revs.include_check_obj = is_not_in_promisor_pack_obj; revs.include_check_obj = is_not_in_promisor_pack_obj;
} }
get_object_list(&revs, rp.nr, rp.v); get_object_list(&revs, &rp);
release_revisions(&revs); release_revisions(&revs);
} }
cleanup_preferred_base(); cleanup_preferred_base();

View File

@@ -299,8 +299,7 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)
oid_to_hex(&opts->restrict_revision->object.oid)); oid_to_hex(&opts->restrict_revision->object.oid));
ret = sequencer_make_script(the_repository, &todo_list.buf, ret = sequencer_make_script(the_repository, &todo_list.buf,
make_script_args.nr, make_script_args.v, &make_script_args, flags);
flags);
if (ret) { if (ret) {
error(_("could not generate todo list")); error(_("could not generate todo list"));
goto cleanup; goto cleanup;

View File

@@ -6063,8 +6063,8 @@ static int make_script_with_merges(struct pretty_print_context *pp,
return 0; return 0;
} }
int sequencer_make_script(struct repository *r, struct strbuf *out, int argc, int sequencer_make_script(struct repository *r, struct strbuf *out,
const char **argv, unsigned flags) struct strvec *argv, unsigned flags)
{ {
char *format = NULL; char *format = NULL;
struct pretty_print_context pp = {0}; struct pretty_print_context pp = {0};
@@ -6105,7 +6105,8 @@ int sequencer_make_script(struct repository *r, struct strbuf *out, int argc,
pp.fmt = revs.commit_format; pp.fmt = revs.commit_format;
pp.output_encoding = get_log_output_encoding(); pp.output_encoding = get_log_output_encoding();
if (setup_revisions(argc, argv, &revs, NULL) > 1) { setup_revisions_from_strvec(argv, &revs, NULL);
if (argv->nr > 1) {
ret = error(_("make_script: unhandled options")); ret = error(_("make_script: unhandled options"));
goto cleanup; goto cleanup;
} }

View File

@@ -186,8 +186,8 @@ int sequencer_remove_state(struct replay_opts *opts);
#define TODO_LIST_REAPPLY_CHERRY_PICKS (1U << 7) #define TODO_LIST_REAPPLY_CHERRY_PICKS (1U << 7)
#define TODO_LIST_WARN_SKIPPED_CHERRY_PICKS (1U << 8) #define TODO_LIST_WARN_SKIPPED_CHERRY_PICKS (1U << 8)
int sequencer_make_script(struct repository *r, struct strbuf *out, int argc, int sequencer_make_script(struct repository *r, struct strbuf *out,
const char **argv, unsigned flags); struct strvec *argv, unsigned flags);
int complete_action(struct repository *r, struct replay_opts *opts, unsigned flags, int complete_action(struct repository *r, struct replay_opts *opts, unsigned flags,
const char *shortrevisions, const char *onto_name, const char *shortrevisions, const char *onto_name,

View File

@@ -213,7 +213,7 @@ static void show_commit(struct commit *commit, void *data)
* are marked with shallow_flag. The list of border/shallow commits * are marked with shallow_flag. The list of border/shallow commits
* are also returned. * are also returned.
*/ */
struct commit_list *get_shallow_commits_by_rev_list(int ac, const char **av, struct commit_list *get_shallow_commits_by_rev_list(struct strvec *argv,
int shallow_flag, int shallow_flag,
int not_shallow_flag) int not_shallow_flag)
{ {
@@ -232,7 +232,7 @@ struct commit_list *get_shallow_commits_by_rev_list(int ac, const char **av,
repo_init_revisions(the_repository, &revs, NULL); repo_init_revisions(the_repository, &revs, NULL);
save_commit_buffer = 0; save_commit_buffer = 0;
setup_revisions(ac, av, &revs, NULL); setup_revisions_from_strvec(argv, &revs, NULL);
if (prepare_revision_walk(&revs)) if (prepare_revision_walk(&revs))
die("revision walk setup failed"); die("revision walk setup failed");

View File

@@ -7,6 +7,7 @@
#include "strbuf.h" #include "strbuf.h"
struct oid_array; struct oid_array;
struct strvec;
void set_alternate_shallow_file(struct repository *r, const char *path, int override); void set_alternate_shallow_file(struct repository *r, const char *path, int override);
int register_shallow(struct repository *r, const struct object_id *oid); 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);
struct commit_list *get_shallow_commits(struct object_array *heads, struct commit_list *get_shallow_commits(struct object_array *heads,
int depth, int shallow_flag, int not_shallow_flag); int depth, int shallow_flag, int not_shallow_flag);
struct commit_list *get_shallow_commits_by_rev_list( struct commit_list *get_shallow_commits_by_rev_list(struct strvec *argv,
int ac, const char **av, int shallow_flag, int not_shallow_flag); int shallow_flag, int not_shallow_flag);
int write_shallow_commits(struct strbuf *out, int use_pack_protocol, int write_shallow_commits(struct strbuf *out, int use_pack_protocol,
const struct oid_array *extra); const struct oid_array *extra);

View File

@@ -914,13 +914,12 @@ static void deepen(struct upload_pack_data *data, int depth)
} }
static void deepen_by_rev_list(struct upload_pack_data *data, static void deepen_by_rev_list(struct upload_pack_data *data,
int ac, struct strvec *argv)
const char **av)
{ {
struct commit_list *result; struct commit_list *result;
disable_commit_graph(the_repository); disable_commit_graph(the_repository);
result = get_shallow_commits_by_rev_list(ac, av, SHALLOW, NOT_SHALLOW); result = get_shallow_commits_by_rev_list(argv, SHALLOW, NOT_SHALLOW);
send_shallow(data, result); send_shallow(data, result);
free_commit_list(result); free_commit_list(result);
send_unshallow(data); send_unshallow(data);
@@ -956,7 +955,7 @@ static int send_shallow_list(struct upload_pack_data *data)
struct object *o = data->want_obj.objects[i].item; struct object *o = data->want_obj.objects[i].item;
strvec_push(&av, oid_to_hex(&o->oid)); strvec_push(&av, oid_to_hex(&o->oid));
} }
deepen_by_rev_list(data, av.nr, av.v); deepen_by_rev_list(data, &av);
strvec_clear(&av); strvec_clear(&av);
ret = 1; ret = 1;
} else { } else {