Skip to content

Commit 5300e52

Browse files
authored
Merge pull request #2786 from derrickstolee/strvec
Replace argv_array with strvec
2 parents 77982ca + 839e784 commit 5300e52

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

105 files changed

+1620
-1621
lines changed

Documentation/technical/api-parse-options.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -232,9 +232,9 @@ There are some macros to easily define options:
232232
will be overwritten, so this should only be used for options where
233233
the last one specified on the command line wins.
234234

235-
`OPT_PASSTHRU_ARGV(short, long, &argv_array_var, arg_str, description, flags)`::
235+
`OPT_PASSTHRU_ARGV(short, long, &strvec_var, arg_str, description, flags)`::
236236
Introduce an option where all instances of it on the command-line will
237-
be reconstructed into an argv_array. This is useful when you need to
237+
be reconstructed into a strvec. This is useful when you need to
238238
pass the command-line option, which can be specified multiple times,
239239
to another command.
240240

Makefile

+1-1
Original file line numberDiff line numberDiff line change
@@ -830,7 +830,6 @@ LIB_OBJS += apply.o
830830
LIB_OBJS += archive-tar.o
831831
LIB_OBJS += archive-zip.o
832832
LIB_OBJS += archive.o
833-
LIB_OBJS += argv-array.o
834833
LIB_OBJS += attr.o
835834
LIB_OBJS += base85.o
836835
LIB_OBJS += bisect.o
@@ -988,6 +987,7 @@ LIB_OBJS += sigchain.o
988987
LIB_OBJS += split-index.o
989988
LIB_OBJS += stable-qsort.o
990989
LIB_OBJS += strbuf.o
990+
LIB_OBJS += strvec.o
991991
LIB_OBJS += streaming.o
992992
LIB_OBJS += string-list.o
993993
LIB_OBJS += sub-process.o

add-interactive.c

+14-14
Original file line numberDiff line numberDiff line change
@@ -935,18 +935,18 @@ static int run_patch(struct add_i_state *s, const struct pathspec *ps,
935935
opts->prompt = N_("Patch update");
936936
count = list_and_choose(s, files, opts);
937937
if (count > 0) {
938-
struct argv_array args = ARGV_ARRAY_INIT;
938+
struct strvec args = STRVEC_INIT;
939939
struct pathspec ps_selected = { 0 };
940940

941941
for (i = 0; i < files->items.nr; i++)
942942
if (files->selected[i])
943-
argv_array_push(&args,
944-
files->items.items[i].string);
943+
strvec_push(&args,
944+
files->items.items[i].string);
945945
parse_pathspec(&ps_selected,
946946
PATHSPEC_ALL_MAGIC & ~PATHSPEC_LITERAL,
947-
PATHSPEC_LITERAL_PATH, "", args.argv);
947+
PATHSPEC_LITERAL_PATH, "", args.v);
948948
res = run_add_p(s->r, ADD_P_ADD, NULL, &ps_selected);
949-
argv_array_clear(&args);
949+
strvec_clear(&args);
950950
clear_pathspec(&ps_selected);
951951
}
952952

@@ -976,18 +976,18 @@ static int run_diff(struct add_i_state *s, const struct pathspec *ps,
976976
count = list_and_choose(s, files, opts);
977977
opts->flags = 0;
978978
if (count > 0) {
979-
struct argv_array args = ARGV_ARRAY_INIT;
979+
struct strvec args = STRVEC_INIT;
980980

981-
argv_array_pushl(&args, "git", "diff", "-p", "--cached",
982-
oid_to_hex(!is_initial ? &oid :
983-
s->r->hash_algo->empty_tree),
984-
"--", NULL);
981+
strvec_pushl(&args, "git", "diff", "-p", "--cached",
982+
oid_to_hex(!is_initial ? &oid :
983+
s->r->hash_algo->empty_tree),
984+
"--", NULL);
985985
for (i = 0; i < files->items.nr; i++)
986986
if (files->selected[i])
987-
argv_array_push(&args,
988-
files->items.items[i].string);
989-
res = run_command_v_opt(args.argv, 0);
990-
argv_array_clear(&args);
987+
strvec_push(&args,
988+
files->items.items[i].string);
989+
res = run_command_v_opt(args.v, 0);
990+
strvec_clear(&args);
991991
}
992992

993993
putchar('\n');

add-patch.c

+24-24
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
#include "add-interactive.h"
33
#include "strbuf.h"
44
#include "run-command.h"
5-
#include "argv-array.h"
5+
#include "strvec.h"
66
#include "pathspec.h"
77
#include "color.h"
88
#include "diff.h"
@@ -286,12 +286,12 @@ static void setup_child_process(struct add_p_state *s,
286286

287287
va_start(ap, cp);
288288
while ((arg = va_arg(ap, const char *)))
289-
argv_array_push(&cp->args, arg);
289+
strvec_push(&cp->args, arg);
290290
va_end(ap);
291291

292292
cp->git_cmd = 1;
293-
argv_array_pushf(&cp->env_array,
294-
INDEX_ENVIRONMENT "=%s", s->s.r->index_file);
293+
strvec_pushf(&cp->env_array,
294+
INDEX_ENVIRONMENT "=%s", s->s.r->index_file);
295295
}
296296

297297
static int parse_range(const char **p,
@@ -370,7 +370,7 @@ static int is_octal(const char *p, size_t len)
370370

371371
static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
372372
{
373-
struct argv_array args = ARGV_ARRAY_INIT;
373+
struct strvec args = STRVEC_INIT;
374374
const char *diff_algorithm = s->s.interactive_diff_algorithm;
375375
struct strbuf *plain = &s->plain, *colored = NULL;
376376
struct child_process cp = CHILD_PROCESS_INIT;
@@ -380,32 +380,32 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
380380
struct hunk *hunk = NULL;
381381
int res;
382382

383-
argv_array_pushv(&args, s->mode->diff_cmd);
383+
strvec_pushv(&args, s->mode->diff_cmd);
384384
if (diff_algorithm)
385-
argv_array_pushf(&args, "--diff-algorithm=%s", diff_algorithm);
385+
strvec_pushf(&args, "--diff-algorithm=%s", diff_algorithm);
386386
if (s->revision) {
387387
struct object_id oid;
388-
argv_array_push(&args,
389-
/* could be on an unborn branch */
390-
!strcmp("HEAD", s->revision) &&
391-
get_oid("HEAD", &oid) ?
392-
empty_tree_oid_hex() : s->revision);
388+
strvec_push(&args,
389+
/* could be on an unborn branch */
390+
!strcmp("HEAD", s->revision) &&
391+
get_oid("HEAD", &oid) ?
392+
empty_tree_oid_hex() : s->revision);
393393
}
394-
color_arg_index = args.argc;
394+
color_arg_index = args.nr;
395395
/* Use `--no-color` explicitly, just in case `diff.color = always`. */
396-
argv_array_pushl(&args, "--no-color", "-p", "--", NULL);
396+
strvec_pushl(&args, "--no-color", "-p", "--", NULL);
397397
for (i = 0; i < ps->nr; i++)
398-
argv_array_push(&args, ps->items[i].original);
398+
strvec_push(&args, ps->items[i].original);
399399

400400
setup_child_process(s, &cp, NULL);
401-
cp.argv = args.argv;
401+
cp.argv = args.v;
402402
res = capture_command(&cp, plain, 0);
403403
if (res) {
404-
argv_array_clear(&args);
404+
strvec_clear(&args);
405405
return error(_("could not parse diff"));
406406
}
407407
if (!plain->len) {
408-
argv_array_clear(&args);
408+
strvec_clear(&args);
409409
return 0;
410410
}
411411
strbuf_complete_line(plain);
@@ -415,11 +415,11 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
415415
const char *diff_filter = s->s.interactive_diff_filter;
416416

417417
setup_child_process(s, &colored_cp, NULL);
418-
xsnprintf((char *)args.argv[color_arg_index], 8, "--color");
419-
colored_cp.argv = args.argv;
418+
xsnprintf((char *)args.v[color_arg_index], 8, "--color");
419+
colored_cp.argv = args.v;
420420
colored = &s->colored;
421421
res = capture_command(&colored_cp, colored, 0);
422-
argv_array_clear(&args);
422+
strvec_clear(&args);
423423
if (res)
424424
return error(_("could not parse colored diff"));
425425

@@ -444,7 +444,7 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
444444
colored_p = colored->buf;
445445
colored_pend = colored_p + colored->len;
446446
}
447-
argv_array_clear(&args);
447+
strvec_clear(&args);
448448

449449
/* parse files and hunks */
450450
p = plain->buf;
@@ -1158,7 +1158,7 @@ static int run_apply_check(struct add_p_state *s,
11581158

11591159
setup_child_process(s, &cp,
11601160
"apply", "--check", NULL);
1161-
argv_array_pushv(&cp.args, s->mode->apply_check_args);
1161+
strvec_pushv(&cp.args, s->mode->apply_check_args);
11621162
if (pipe_command(&cp, s->buf.buf, s->buf.len, NULL, 0, NULL, 0))
11631163
return error(_("'git apply --cached' failed"));
11641164

@@ -1619,7 +1619,7 @@ static int patch_update_file(struct add_p_state *s,
16191619
s->mode->is_reverse);
16201620
else {
16211621
setup_child_process(s, &cp, "apply", NULL);
1622-
argv_array_pushv(&cp.args, s->mode->apply_args);
1622+
strvec_pushv(&cp.args, s->mode->apply_args);
16231623
if (pipe_command(&cp, s->buf.buf, s->buf.len,
16241624
NULL, 0, NULL, 0))
16251625
error(_("'git apply' failed"));

argv-array.c

-109
This file was deleted.

bisect.c

+10-10
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
#include "log-tree.h"
1212
#include "bisect.h"
1313
#include "oid-array.h"
14-
#include "argv-array.h"
14+
#include "strvec.h"
1515
#include "commit-slab.h"
1616
#include "commit-reach.h"
1717
#include "object-store.h"
@@ -456,15 +456,15 @@ static GIT_PATH_FUNC(git_path_bisect_log, "BISECT_LOG")
456456
static GIT_PATH_FUNC(git_path_bisect_terms, "BISECT_TERMS")
457457
static GIT_PATH_FUNC(git_path_head_name, "head-name")
458458

459-
static void read_bisect_paths(struct argv_array *array)
459+
static void read_bisect_paths(struct strvec *array)
460460
{
461461
struct strbuf str = STRBUF_INIT;
462462
const char *filename = git_path_bisect_names();
463463
FILE *fp = xfopen(filename, "r");
464464

465465
while (strbuf_getline_lf(&str, fp) != EOF) {
466466
strbuf_trim(&str);
467-
if (sq_dequote_to_argv_array(str.buf, array))
467+
if (sq_dequote_to_strvec(str.buf, array))
468468
die(_("Badly quoted content in file '%s': %s"),
469469
filename, str.buf);
470470
}
@@ -632,24 +632,24 @@ static void bisect_rev_setup(struct repository *r, struct rev_info *revs,
632632
const char *bad_format, const char *good_format,
633633
int read_paths)
634634
{
635-
struct argv_array rev_argv = ARGV_ARRAY_INIT;
635+
struct strvec rev_argv = STRVEC_INIT;
636636
int i;
637637

638638
repo_init_revisions(r, revs, prefix);
639639
revs->abbrev = 0;
640640
revs->commit_format = CMIT_FMT_UNSPECIFIED;
641641

642642
/* rev_argv.argv[0] will be ignored by setup_revisions */
643-
argv_array_push(&rev_argv, "bisect_rev_setup");
644-
argv_array_pushf(&rev_argv, bad_format, oid_to_hex(current_bad_oid));
643+
strvec_push(&rev_argv, "bisect_rev_setup");
644+
strvec_pushf(&rev_argv, bad_format, oid_to_hex(current_bad_oid));
645645
for (i = 0; i < good_revs.nr; i++)
646-
argv_array_pushf(&rev_argv, good_format,
647-
oid_to_hex(good_revs.oid + i));
648-
argv_array_push(&rev_argv, "--");
646+
strvec_pushf(&rev_argv, good_format,
647+
oid_to_hex(good_revs.oid + i));
648+
strvec_push(&rev_argv, "--");
649649
if (read_paths)
650650
read_bisect_paths(&rev_argv);
651651

652-
setup_revisions(rev_argv.argc, rev_argv.argv, revs, NULL);
652+
setup_revisions(rev_argv.nr, rev_argv.v, revs, NULL);
653653
/* XXX leak rev_argv, as "revs" may still be pointing to it */
654654
}
655655

0 commit comments

Comments
 (0)