Skip to content

Commit 1806813

Browse files
peffgitster
authored andcommitted
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>
1 parent b553332 commit 1806813

File tree

7 files changed

+18
-18
lines changed

7 files changed

+18
-18
lines changed

builtin/pack-objects.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4650,7 +4650,7 @@ static void get_object_list_path_walk(struct rev_info *revs)
46504650
die(_("failed to pack objects via path-walk"));
46514651
}
46524652

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)
46544654
{
46554655
struct setup_revision_opt s_r_opt = {
46564656
.allow_exclude_promisor_objects = 1,
@@ -4660,7 +4660,7 @@ static void get_object_list(struct rev_info *revs, int ac, const char **av)
46604660
int save_warning;
46614661

46624662
save_commit_buffer = 0;
4663-
setup_revisions(ac, av, revs, &s_r_opt);
4663+
setup_revisions_from_strvec(argv, revs, &s_r_opt);
46644664

46654665
/* make sure shallows are read */
46664666
is_repository_shallow(the_repository);
@@ -5229,7 +5229,7 @@ int cmd_pack_objects(int argc,
52295229
revs.include_check = is_not_in_promisor_pack;
52305230
revs.include_check_obj = is_not_in_promisor_pack_obj;
52315231
}
5232-
get_object_list(&revs, rp.nr, rp.v);
5232+
get_object_list(&revs, &rp);
52335233
release_revisions(&revs);
52345234
}
52355235
cleanup_preferred_base();

builtin/rebase.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -299,8 +299,7 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags)
299299
oid_to_hex(&opts->restrict_revision->object.oid));
300300

301301
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);
304303
if (ret) {
305304
error(_("could not generate todo list"));
306305
goto cleanup;

sequencer.c

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6063,8 +6063,8 @@ static int make_script_with_merges(struct pretty_print_context *pp,
60636063
return 0;
60646064
}
60656065

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)
60686068
{
60696069
char *format = NULL;
60706070
struct pretty_print_context pp = {0};
@@ -6105,7 +6105,8 @@ int sequencer_make_script(struct repository *r, struct strbuf *out, int argc,
61056105
pp.fmt = revs.commit_format;
61066106
pp.output_encoding = get_log_output_encoding();
61076107

6108-
if (setup_revisions(argc, argv, &revs, NULL) > 1) {
6108+
setup_revisions_from_strvec(argv, &revs, NULL);
6109+
if (argv->nr > 1) {
61096110
ret = error(_("make_script: unhandled options"));
61106111
goto cleanup;
61116112
}

sequencer.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -186,8 +186,8 @@ int sequencer_remove_state(struct replay_opts *opts);
186186
#define TODO_LIST_REAPPLY_CHERRY_PICKS (1U << 7)
187187
#define TODO_LIST_WARN_SKIPPED_CHERRY_PICKS (1U << 8)
188188

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);
191191

192192
int complete_action(struct repository *r, struct replay_opts *opts, unsigned flags,
193193
const char *shortrevisions, const char *onto_name,

shallow.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ static void show_commit(struct commit *commit, void *data)
213213
* are marked with shallow_flag. The list of border/shallow commits
214214
* are also returned.
215215
*/
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,
217217
int shallow_flag,
218218
int not_shallow_flag)
219219
{
@@ -232,7 +232,7 @@ struct commit_list *get_shallow_commits_by_rev_list(int ac, const char **av,
232232

233233
repo_init_revisions(the_repository, &revs, NULL);
234234
save_commit_buffer = 0;
235-
setup_revisions(ac, av, &revs, NULL);
235+
setup_revisions_from_strvec(argv, &revs, NULL);
236236

237237
if (prepare_revision_walk(&revs))
238238
die("revision walk setup failed");

shallow.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
#include "strbuf.h"
88

99
struct oid_array;
10+
struct strvec;
1011

1112
void set_alternate_shallow_file(struct repository *r, const char *path, int override);
1213
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);
3637

3738
struct commit_list *get_shallow_commits(struct object_array *heads,
3839
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);
4142
int write_shallow_commits(struct strbuf *out, int use_pack_protocol,
4243
const struct oid_array *extra);
4344

upload-pack.c

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -914,13 +914,12 @@ static void deepen(struct upload_pack_data *data, int depth)
914914
}
915915

916916
static void deepen_by_rev_list(struct upload_pack_data *data,
917-
int ac,
918-
const char **av)
917+
struct strvec *argv)
919918
{
920919
struct commit_list *result;
921920

922921
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);
924923
send_shallow(data, result);
925924
free_commit_list(result);
926925
send_unshallow(data);
@@ -956,7 +955,7 @@ static int send_shallow_list(struct upload_pack_data *data)
956955
struct object *o = data->want_obj.objects[i].item;
957956
strvec_push(&av, oid_to_hex(&o->oid));
958957
}
959-
deepen_by_rev_list(data, av.nr, av.v);
958+
deepen_by_rev_list(data, &av);
960959
strvec_clear(&av);
961960
ret = 1;
962961
} else {

0 commit comments

Comments
 (0)