Git fork

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>

authored by

Jeff King and committed by
Junio C Hamano
18068139 b553332f

+18 -18
+3 -3
builtin/pack-objects.c
··· 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) 4654 { 4655 struct setup_revision_opt s_r_opt = { 4656 .allow_exclude_promisor_objects = 1, ··· 4660 int save_warning; 4661 4662 save_commit_buffer = 0; 4663 - setup_revisions(ac, av, revs, &s_r_opt); 4664 4665 /* make sure shallows are read */ 4666 is_repository_shallow(the_repository); ··· 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); 5233 release_revisions(&revs); 5234 } 5235 cleanup_preferred_base();
··· 4650 die(_("failed to pack objects via path-walk")); 4651 } 4652 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 int save_warning; 4661 4662 save_commit_buffer = 0; 4663 + setup_revisions_from_strvec(argv, revs, &s_r_opt); 4664 4665 /* make sure shallows are read */ 4666 is_repository_shallow(the_repository); ··· 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); 5233 release_revisions(&revs); 5234 } 5235 cleanup_preferred_base();
+1 -2
builtin/rebase.c
··· 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); 304 if (ret) { 305 error(_("could not generate todo list")); 306 goto cleanup;
··· 299 oid_to_hex(&opts->restrict_revision->object.oid)); 300 301 ret = sequencer_make_script(the_repository, &todo_list.buf, 302 + &make_script_args, flags); 303 if (ret) { 304 error(_("could not generate todo list")); 305 goto cleanup;
+4 -3
sequencer.c
··· 6063 return 0; 6064 } 6065 6066 - int sequencer_make_script(struct repository *r, struct strbuf *out, int argc, 6067 - const char **argv, unsigned flags) 6068 { 6069 char *format = NULL; 6070 struct pretty_print_context pp = {0}; ··· 6105 pp.fmt = revs.commit_format; 6106 pp.output_encoding = get_log_output_encoding(); 6107 6108 - if (setup_revisions(argc, argv, &revs, NULL) > 1) { 6109 ret = error(_("make_script: unhandled options")); 6110 goto cleanup; 6111 }
··· 6063 return 0; 6064 } 6065 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 pp.fmt = revs.commit_format; 6106 pp.output_encoding = get_log_output_encoding(); 6107 6108 + setup_revisions_from_strvec(argv, &revs, NULL); 6109 + if (argv->nr > 1) { 6110 ret = error(_("make_script: unhandled options")); 6111 goto cleanup; 6112 }
+2 -2
sequencer.h
··· 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); 191 192 int complete_action(struct repository *r, struct replay_opts *opts, unsigned flags, 193 const char *shortrevisions, const char *onto_name,
··· 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, 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,
+2 -2
shallow.c
··· 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, 217 int shallow_flag, 218 int not_shallow_flag) 219 { ··· 232 233 repo_init_revisions(the_repository, &revs, NULL); 234 save_commit_buffer = 0; 235 - setup_revisions(ac, av, &revs, NULL); 236 237 if (prepare_revision_walk(&revs)) 238 die("revision walk setup failed");
··· 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(struct strvec *argv, 217 int shallow_flag, 218 int not_shallow_flag) 219 { ··· 232 233 repo_init_revisions(the_repository, &revs, NULL); 234 save_commit_buffer = 0; 235 + setup_revisions_from_strvec(argv, &revs, NULL); 236 237 if (prepare_revision_walk(&revs)) 238 die("revision walk setup failed");
+3 -2
shallow.h
··· 7 #include "strbuf.h" 8 9 struct oid_array; 10 11 void set_alternate_shallow_file(struct repository *r, const char *path, int override); 12 int register_shallow(struct repository *r, const struct object_id *oid); ··· 36 37 struct commit_list *get_shallow_commits(struct object_array *heads, 38 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); 41 int write_shallow_commits(struct strbuf *out, int use_pack_protocol, 42 const struct oid_array *extra); 43
··· 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); ··· 37 38 struct commit_list *get_shallow_commits(struct object_array *heads, 39 int depth, 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
+3 -4
upload-pack.c
··· 914 } 915 916 static void deepen_by_rev_list(struct upload_pack_data *data, 917 - int ac, 918 - const char **av) 919 { 920 struct commit_list *result; 921 922 disable_commit_graph(the_repository); 923 - result = get_shallow_commits_by_rev_list(ac, av, SHALLOW, NOT_SHALLOW); 924 send_shallow(data, result); 925 free_commit_list(result); 926 send_unshallow(data); ··· 956 struct object *o = data->want_obj.objects[i].item; 957 strvec_push(&av, oid_to_hex(&o->oid)); 958 } 959 - deepen_by_rev_list(data, av.nr, av.v); 960 strvec_clear(&av); 961 ret = 1; 962 } else {
··· 914 } 915 916 static void deepen_by_rev_list(struct upload_pack_data *data, 917 + struct strvec *argv) 918 { 919 struct commit_list *result; 920 921 disable_commit_graph(the_repository); 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); ··· 955 struct object *o = data->want_obj.objects[i].item; 956 strvec_push(&av, oid_to_hex(&o->oid)); 957 } 958 + deepen_by_rev_list(data, &av); 959 strvec_clear(&av); 960 ret = 1; 961 } else {