Skip to content

Commit

Permalink
Merge branch 'jk/strvec'
Browse files Browse the repository at this point in the history
The argv_array API is useful for not just managing argv but any
"vector" (NULL-terminated array) of strings, and has seen adoption
to a certain degree.  It has been renamed to "strvec" to reduce the
barrier to adoption.

* jk/strvec:
  strvec: rename struct fields
  strvec: drop argv_array compatibility layer
  strvec: update documention to avoid argv_array
  strvec: fix indentation in renamed calls
  strvec: convert remaining callers away from argv_array name
  strvec: convert more callers away from argv_array name
  strvec: convert builtin/ callers away from argv_array name
  quote: rename sq_dequote_to_argv_array to mention strvec
  strvec: rename files from argv-array to strvec
  argv-array: rename to strvec
  argv-array: use size_t for count and alloc
  • Loading branch information
gitster committed Aug 10, 2020
2 parents dc04167 + d70a9eb commit 46b225f
Showing 105 changed files with 1,619 additions and 1,620 deletions.
4 changes: 2 additions & 2 deletions Documentation/technical/api-parse-options.txt
Original file line number Diff line number Diff line change
@@ -232,9 +232,9 @@ There are some macros to easily define options:
will be overwritten, so this should only be used for options where
the last one specified on the command line wins.

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

2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -828,7 +828,6 @@ LIB_OBJS += apply.o
LIB_OBJS += archive-tar.o
LIB_OBJS += archive-zip.o
LIB_OBJS += archive.o
LIB_OBJS += argv-array.o
LIB_OBJS += attr.o
LIB_OBJS += base85.o
LIB_OBJS += bisect.o
@@ -986,6 +985,7 @@ LIB_OBJS += sigchain.o
LIB_OBJS += split-index.o
LIB_OBJS += stable-qsort.o
LIB_OBJS += strbuf.o
LIB_OBJS += strvec.o
LIB_OBJS += streaming.o
LIB_OBJS += string-list.o
LIB_OBJS += sub-process.o
28 changes: 14 additions & 14 deletions add-interactive.c
Original file line number Diff line number Diff line change
@@ -935,18 +935,18 @@ static int run_patch(struct add_i_state *s, const struct pathspec *ps,
opts->prompt = N_("Patch update");
count = list_and_choose(s, files, opts);
if (count > 0) {
struct argv_array args = ARGV_ARRAY_INIT;
struct strvec args = STRVEC_INIT;
struct pathspec ps_selected = { 0 };

for (i = 0; i < files->items.nr; i++)
if (files->selected[i])
argv_array_push(&args,
files->items.items[i].string);
strvec_push(&args,
files->items.items[i].string);
parse_pathspec(&ps_selected,
PATHSPEC_ALL_MAGIC & ~PATHSPEC_LITERAL,
PATHSPEC_LITERAL_PATH, "", args.argv);
PATHSPEC_LITERAL_PATH, "", args.v);
res = run_add_p(s->r, ADD_P_ADD, NULL, &ps_selected);
argv_array_clear(&args);
strvec_clear(&args);
clear_pathspec(&ps_selected);
}

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

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

putchar('\n');
48 changes: 24 additions & 24 deletions add-patch.c
Original file line number Diff line number Diff line change
@@ -2,7 +2,7 @@
#include "add-interactive.h"
#include "strbuf.h"
#include "run-command.h"
#include "argv-array.h"
#include "strvec.h"
#include "pathspec.h"
#include "color.h"
#include "diff.h"
@@ -286,12 +286,12 @@ static void setup_child_process(struct add_p_state *s,

va_start(ap, cp);
while ((arg = va_arg(ap, const char *)))
argv_array_push(&cp->args, arg);
strvec_push(&cp->args, arg);
va_end(ap);

cp->git_cmd = 1;
argv_array_pushf(&cp->env_array,
INDEX_ENVIRONMENT "=%s", s->s.r->index_file);
strvec_pushf(&cp->env_array,
INDEX_ENVIRONMENT "=%s", s->s.r->index_file);
}

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

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

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

setup_child_process(s, &cp, NULL);
cp.argv = args.argv;
cp.argv = args.v;
res = capture_command(&cp, plain, 0);
if (res) {
argv_array_clear(&args);
strvec_clear(&args);
return error(_("could not parse diff"));
}
if (!plain->len) {
argv_array_clear(&args);
strvec_clear(&args);
return 0;
}
strbuf_complete_line(plain);
@@ -415,11 +415,11 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps)
const char *diff_filter = s->s.interactive_diff_filter;

setup_child_process(s, &colored_cp, NULL);
xsnprintf((char *)args.argv[color_arg_index], 8, "--color");
colored_cp.argv = args.argv;
xsnprintf((char *)args.v[color_arg_index], 8, "--color");
colored_cp.argv = args.v;
colored = &s->colored;
res = capture_command(&colored_cp, colored, 0);
argv_array_clear(&args);
strvec_clear(&args);
if (res)
return error(_("could not parse colored diff"));

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

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

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

@@ -1619,7 +1619,7 @@ static int patch_update_file(struct add_p_state *s,
s->mode->is_reverse);
else {
setup_child_process(s, &cp, "apply", NULL);
argv_array_pushv(&cp.args, s->mode->apply_args);
strvec_pushv(&cp.args, s->mode->apply_args);
if (pipe_command(&cp, s->buf.buf, s->buf.len,
NULL, 0, NULL, 0))
error(_("'git apply' failed"));
109 changes: 0 additions & 109 deletions argv-array.c

This file was deleted.

20 changes: 10 additions & 10 deletions bisect.c
Original file line number Diff line number Diff line change
@@ -11,7 +11,7 @@
#include "log-tree.h"
#include "bisect.h"
#include "oid-array.h"
#include "argv-array.h"
#include "strvec.h"
#include "commit-slab.h"
#include "commit-reach.h"
#include "object-store.h"
@@ -456,15 +456,15 @@ static GIT_PATH_FUNC(git_path_bisect_log, "BISECT_LOG")
static GIT_PATH_FUNC(git_path_bisect_terms, "BISECT_TERMS")
static GIT_PATH_FUNC(git_path_head_name, "head-name")

static void read_bisect_paths(struct argv_array *array)
static void read_bisect_paths(struct strvec *array)
{
struct strbuf str = STRBUF_INIT;
const char *filename = git_path_bisect_names();
FILE *fp = xfopen(filename, "r");

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

repo_init_revisions(r, revs, prefix);
revs->abbrev = 0;
revs->commit_format = CMIT_FMT_UNSPECIFIED;

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

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

Loading
Oops, something went wrong.

0 comments on commit 46b225f

Please sign in to comment.