]> git.ipfire.org Git - thirdparty/git.git/commitdiff
treewide: pass strvecs around for setup_revisions_from_strvec()
authorJeff King <peff@peff.net>
Fri, 19 Sep 2025 22:50:48 +0000 (18:50 -0400)
committerJunio C Hamano <gitster@pobox.com>
Mon, 22 Sep 2025 21:27:03 +0000 (14:27 -0700)
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>
builtin/pack-objects.c
builtin/rebase.c
sequencer.c
sequencer.h
shallow.c
shallow.h
upload-pack.c

index 53a225625039eae43a0d5aef6538f13b2a40d6de..691935a2a4dc6b05b03092116265d8ecbea359dc 100644 (file)
@@ -4650,7 +4650,7 @@ static void get_object_list_path_walk(struct rev_info *revs)
                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 = {
                .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;
 
        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 */
        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_obj = is_not_in_promisor_pack_obj;
                }
-               get_object_list(&revs, rp.nr, rp.v);
+               get_object_list(&revs, &rp);
                release_revisions(&revs);
        }
        cleanup_preferred_base();
index 3c85768d29ef799539c7f067ae7d0065cf398dc5..286df7bd249ad4cb71f2d42945f4c1f6a2295d14 100644 (file)
@@ -299,8 +299,7 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)
                             oid_to_hex(&opts->restrict_revision->object.oid));
 
        ret = sequencer_make_script(the_repository, &todo_list.buf,
-                                   make_script_args.nr, make_script_args.v,
-                                   flags);
+                                   &make_script_args, flags);
        if (ret) {
                error(_("could not generate todo list"));
                goto cleanup;
index aaf2e4df64ed0bf93a1c6c3c319845bdf6c27595..0d0fd84aecc9c3fe39fbe45006b4aead85bae42f 100644 (file)
@@ -6063,8 +6063,8 @@ static int make_script_with_merges(struct pretty_print_context *pp,
        return 0;
 }
 
-int sequencer_make_script(struct repository *r, struct strbuf *out, int argc,
-                         const char **argv, unsigned flags)
+int sequencer_make_script(struct repository *r, struct strbuf *out,
+                         struct strvec *argv, unsigned flags)
 {
        char *format = NULL;
        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.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"));
                goto cleanup;
        }
index 304ba4b4d358352b50fa090986aaeb63705a7b19..719684c8a9fb2e5ab10464e3edf1726097fe33c8 100644 (file)
@@ -186,8 +186,8 @@ int sequencer_remove_state(struct replay_opts *opts);
 #define TODO_LIST_REAPPLY_CHERRY_PICKS (1U << 7)
 #define TODO_LIST_WARN_SKIPPED_CHERRY_PICKS (1U << 8)
 
-int sequencer_make_script(struct repository *r, struct strbuf *out, int argc,
-                         const char **argv, unsigned flags);
+int sequencer_make_script(struct repository *r, struct strbuf *out,
+                         struct strvec *argv, unsigned flags);
 
 int complete_action(struct repository *r, struct replay_opts *opts, unsigned flags,
                    const char *shortrevisions, const char *onto_name,
index ef3adb635fdb9ca625ed10bd30a760962f140471..d9cd4e219cb07dcce18356668420362086deb745 100644 (file)
--- a/shallow.c
+++ b/shallow.c
@@ -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 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 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);
        save_commit_buffer = 0;
-       setup_revisions(ac, av, &revs, NULL);
+       setup_revisions_from_strvec(argv, &revs, NULL);
 
        if (prepare_revision_walk(&revs))
                die("revision walk setup failed");
index 9bfeade93ead7421d7f2991862dde88ba546fc64..ad591bd13968540dba3dd8aa28d0009b89145b8e 100644 (file)
--- a/shallow.h
+++ b/shallow.h
@@ -7,6 +7,7 @@
 #include "strbuf.h"
 
 struct oid_array;
+struct strvec;
 
 void set_alternate_shallow_file(struct repository *r, const char *path, int override);
 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,
                                        int depth, int shallow_flag, int not_shallow_flag);
-struct commit_list *get_shallow_commits_by_rev_list(
-               int ac, const char **av, int shallow_flag, int not_shallow_flag);
+struct commit_list *get_shallow_commits_by_rev_list(struct strvec *argv,
+                                                   int shallow_flag, int not_shallow_flag);
 int write_shallow_commits(struct strbuf *out, int use_pack_protocol,
                          const struct oid_array *extra);
 
index 4f26f6afc77106ead4ba04bae6f529ed39af7e02..9fcacb2d1a3689dea07db1cfdc0c2a0b497c110e 100644 (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,
-                              int ac,
-                              const char **av)
+                              struct strvec *argv)
 {
        struct commit_list *result;
 
        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);
        free_commit_list(result);
        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;
                        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);
                ret = 1;
        } else {