From 819f0e76b110458488c41741b0dcd538483848c0 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 28 Jul 2020 16:21:52 -0400 Subject: argv-array: use size_t for count and alloc On most 64-bit platforms, "int" is significantly smaller than a size_t, which could lead to integer overflow and under-allocation of the array. It's probably impossible to trigger in practice, as it would imply on the order of 2^32 individual allocations. Even if was possible to grow an array in that way (and we typically only use it for sets of strings, like command line options), each allocation needs a pointer, malloc overhead, etc. You'd quite likely run out of RAM before succeeding in such an overflow. But all that hand-waving aside, it's easy enough to use the correct type, so let's do so. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano diff --git a/argv-array.h b/argv-array.h index a7d3b10..4fc57b6 100644 --- a/argv-array.h +++ b/argv-array.h @@ -29,8 +29,8 @@ extern const char *empty_argv[]; */ struct argv_array { const char **argv; - int argc; - int alloc; + size_t argc; + size_t alloc; }; #define ARGV_ARRAY_INIT { empty_argv, 0, 0 } -- cgit v0.10.2-6-g49f6 From 873cd28a8b17ff21908c78c7929a7615f8c94992 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 28 Jul 2020 16:23:25 -0400 Subject: argv-array: rename to strvec The name "argv-array" isn't very good, because it describes what the data type can be used for (program argument arrays), not what it actually is (a dynamically-growing string array that maintains a NULL-terminator invariant). This leads to people being hesitant to use it for other cases where it would actually be a good fit. The existing name is also clunky to use. It's overly long, and the name often leads to saying things like "argv.argv" (i.e., the field names overlap with variable names, since they're describing the use, not the type). Let's give it a more neutral name. I settled on "strvec" because "vector" is the name for a dynamic array type in many programming languages. "strarray" would work, too, but it's longer and a bit more awkward to say (and don't we all say these things in our mind as we type them?). A more extreme direction would be a generic data structure which stores a NULL-terminated of _any_ type. That would be easy to do with void pointers, but we'd lose some type safety for the existing cases. Plus it raises questions about memory allocation and ownership. So I limited myself here to changing names only, and not semantics. If we do find a use for that more generic data type, we could perhaps implement it at a lower level and then provide type-safe wrappers around it for strings. But that can come later. This patch does the minimum to convert the struct and function names in the header and implementation, leaving a few things for follow-on patches: - files retain their original names for now - struct field names are retained for now - there's a preprocessor compat layer that lets most users remain the same for now. The exception is headers which made a manual forward declaration of the struct. I've converted them (and their dependent function declarations) here. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano diff --git a/argv-array.c b/argv-array.c index 61ef8c0..b7461c4 100644 --- a/argv-array.c +++ b/argv-array.c @@ -2,18 +2,18 @@ #include "argv-array.h" #include "strbuf.h" -const char *empty_argv[] = { NULL }; +const char *empty_strvec[] = { NULL }; -void argv_array_init(struct argv_array *array) +void strvec_init(struct strvec *array) { - array->argv = empty_argv; + array->argv = empty_strvec; array->argc = 0; array->alloc = 0; } -static void argv_array_push_nodup(struct argv_array *array, const char *value) +static void strvec_push_nodup(struct strvec *array, const char *value) { - if (array->argv == empty_argv) + if (array->argv == empty_strvec) array->argv = NULL; ALLOC_GROW(array->argv, array->argc + 2, array->alloc); @@ -21,13 +21,13 @@ static void argv_array_push_nodup(struct argv_array *array, const char *value) array->argv[array->argc] = NULL; } -const char *argv_array_push(struct argv_array *array, const char *value) +const char *strvec_push(struct strvec *array, const char *value) { - argv_array_push_nodup(array, xstrdup(value)); + strvec_push_nodup(array, xstrdup(value)); return array->argv[array->argc - 1]; } -const char *argv_array_pushf(struct argv_array *array, const char *fmt, ...) +const char *strvec_pushf(struct strvec *array, const char *fmt, ...) { va_list ap; struct strbuf v = STRBUF_INIT; @@ -36,28 +36,28 @@ const char *argv_array_pushf(struct argv_array *array, const char *fmt, ...) strbuf_vaddf(&v, fmt, ap); va_end(ap); - argv_array_push_nodup(array, strbuf_detach(&v, NULL)); + strvec_push_nodup(array, strbuf_detach(&v, NULL)); return array->argv[array->argc - 1]; } -void argv_array_pushl(struct argv_array *array, ...) +void strvec_pushl(struct strvec *array, ...) { va_list ap; const char *arg; va_start(ap, array); while ((arg = va_arg(ap, const char *))) - argv_array_push(array, arg); + strvec_push(array, arg); va_end(ap); } -void argv_array_pushv(struct argv_array *array, const char **argv) +void strvec_pushv(struct strvec *array, const char **argv) { for (; *argv; argv++) - argv_array_push(array, *argv); + strvec_push(array, *argv); } -void argv_array_pop(struct argv_array *array) +void strvec_pop(struct strvec *array) { if (!array->argc) return; @@ -66,7 +66,7 @@ void argv_array_pop(struct argv_array *array) array->argc--; } -void argv_array_split(struct argv_array *array, const char *to_split) +void strvec_split(struct strvec *array, const char *to_split) { while (isspace(*to_split)) to_split++; @@ -78,7 +78,7 @@ void argv_array_split(struct argv_array *array, const char *to_split) while (*p && !isspace(*p)) p++; - argv_array_push_nodup(array, xstrndup(to_split, p - to_split)); + strvec_push_nodup(array, xstrndup(to_split, p - to_split)); while (isspace(*p)) p++; @@ -86,24 +86,24 @@ void argv_array_split(struct argv_array *array, const char *to_split) } } -void argv_array_clear(struct argv_array *array) +void strvec_clear(struct strvec *array) { - if (array->argv != empty_argv) { + if (array->argv != empty_strvec) { int i; for (i = 0; i < array->argc; i++) free((char *)array->argv[i]); free(array->argv); } - argv_array_init(array); + strvec_init(array); } -const char **argv_array_detach(struct argv_array *array) +const char **strvec_detach(struct strvec *array) { - if (array->argv == empty_argv) + if (array->argv == empty_strvec) return xcalloc(1, sizeof(const char *)); else { const char **ret = array->argv; - argv_array_init(array); + strvec_init(array); return ret; } } diff --git a/argv-array.h b/argv-array.h index 4fc57b6..ca66a33 100644 --- a/argv-array.h +++ b/argv-array.h @@ -14,42 +14,42 @@ * it contains an item structure with a `util` field that is not compatible * with the traditional argv interface. * - * Each `argv_array` manages its own memory. Any strings pushed into the - * array are duplicated, and all memory is freed by argv_array_clear(). + * Each `strvec` manages its own memory. Any strings pushed into the + * array are duplicated, and all memory is freed by strvec_clear(). */ -extern const char *empty_argv[]; +extern const char *empty_strvec[]; /** * A single array. This should be initialized by assignment from - * `ARGV_ARRAY_INIT`, or by calling `argv_array_init`. The `argv` + * `STRVEC_INIT`, or by calling `strvec_init`. The `argv` * member contains the actual array; the `argc` member contains the * number of elements in the array, not including the terminating * NULL. */ -struct argv_array { +struct strvec { const char **argv; size_t argc; size_t alloc; }; -#define ARGV_ARRAY_INIT { empty_argv, 0, 0 } +#define STRVEC_INIT { empty_strvec, 0, 0 } /** * Initialize an array. This is no different than assigning from - * `ARGV_ARRAY_INIT`. + * `STRVEC_INIT`. */ -void argv_array_init(struct argv_array *); +void strvec_init(struct strvec *); /* Push a copy of a string onto the end of the array. */ -const char *argv_array_push(struct argv_array *, const char *); +const char *strvec_push(struct strvec *, const char *); /** * Format a string and push it onto the end of the array. This is a - * convenience wrapper combining `strbuf_addf` and `argv_array_push`. + * convenience wrapper combining `strbuf_addf` and `strvec_push`. */ __attribute__((format (printf,2,3))) -const char *argv_array_pushf(struct argv_array *, const char *fmt, ...); +const char *strvec_pushf(struct strvec *, const char *fmt, ...); /** * Push a list of strings onto the end of the array. The arguments @@ -57,33 +57,46 @@ const char *argv_array_pushf(struct argv_array *, const char *fmt, ...); * argument. */ LAST_ARG_MUST_BE_NULL -void argv_array_pushl(struct argv_array *, ...); +void strvec_pushl(struct strvec *, ...); /* Push a null-terminated array of strings onto the end of the array. */ -void argv_array_pushv(struct argv_array *, const char **); +void strvec_pushv(struct strvec *, const char **); /** * Remove the final element from the array. If there are no * elements in the array, do nothing. */ -void argv_array_pop(struct argv_array *); +void strvec_pop(struct strvec *); /* Splits by whitespace; does not handle quoted arguments! */ -void argv_array_split(struct argv_array *, const char *); +void strvec_split(struct strvec *, const char *); /** * Free all memory associated with the array and return it to the * initial, empty state. */ -void argv_array_clear(struct argv_array *); +void strvec_clear(struct strvec *); /** - * Disconnect the `argv` member from the `argv_array` struct and + * Disconnect the `argv` member from the `strvec` struct and * return it. The caller is responsible for freeing the memory used * by the array, and by the strings it references. After detaching, - * the `argv_array` is in a reinitialized state and can be pushed + * the `strvec` is in a reinitialized state and can be pushed * into again. */ -const char **argv_array_detach(struct argv_array *); +const char **strvec_detach(struct strvec *); + +/* compatibility for historic argv_array interface */ +#define argv_array strvec +#define ARGV_ARRAY_INIT STRVEC_INIT +#define argv_array_init strvec_init +#define argv_array_push strvec_push +#define argv_array_pushf strvec_pushf +#define argv_array_pushl strvec_pushl +#define argv_array_pushv strvec_pushv +#define argv_array_pop strvec_pop +#define argv_array_split strvec_split +#define argv_array_clear strvec_clear +#define argv_array_detach strvec_detach #endif /* ARGV_ARRAY_H */ diff --git a/exec-cmd.h b/exec-cmd.h index 8cd1df2..330b41d 100644 --- a/exec-cmd.h +++ b/exec-cmd.h @@ -1,13 +1,13 @@ #ifndef GIT_EXEC_CMD_H #define GIT_EXEC_CMD_H -struct argv_array; +struct strvec; void git_set_exec_path(const char *exec_path); void git_resolve_executable_dir(const char *path); const char *git_exec_path(void); void setup_path(void); -const char **prepare_git_cmd(struct argv_array *out, const char **argv); +const char **prepare_git_cmd(struct strvec *out, const char **argv); int execv_git_cmd(const char **argv); /* NULL terminated */ LAST_ARG_MUST_BE_NULL int execl_git_cmd(const char *cmd, ...); diff --git a/ls-refs.h b/ls-refs.h index 7e5646f..7b33a7c 100644 --- a/ls-refs.h +++ b/ls-refs.h @@ -2,9 +2,9 @@ #define LS_REFS_H struct repository; -struct argv_array; +struct strvec; struct packet_reader; -int ls_refs(struct repository *r, struct argv_array *keys, +int ls_refs(struct repository *r, struct strvec *keys, struct packet_reader *request); #endif /* LS_REFS_H */ diff --git a/quote.h b/quote.h index ca8ee31..210d580 100644 --- a/quote.h +++ b/quote.h @@ -60,8 +60,8 @@ int sq_dequote_to_argv(char *arg, const char ***argv, int *nr, int *alloc); * still modify arg in place, but unlike sq_dequote_to_argv, the argv_array * will duplicate and take ownership of the strings. */ -struct argv_array; -int sq_dequote_to_argv_array(char *arg, struct argv_array *); +struct strvec; +int sq_dequote_to_argv_array(char *arg, struct strvec *); int unquote_c_style(struct strbuf *, const char *quoted, const char **endp); size_t quote_c_style(const char *name, struct strbuf *, FILE *, int no_dq); diff --git a/refs.h b/refs.h index f212f89..29e2812 100644 --- a/refs.h +++ b/refs.h @@ -145,8 +145,8 @@ int refname_match(const char *abbrev_name, const char *full_name); * Given a 'prefix' expand it by the rules in 'ref_rev_parse_rules' and add * the results to 'prefixes' */ -struct argv_array; -void expand_ref_prefix(struct argv_array *prefixes, const char *prefix); +struct strvec; +void expand_ref_prefix(struct strvec *prefixes, const char *prefix); int expand_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref); int repo_dwim_ref(struct repository *r, const char *str, int len, struct object_id *oid, char **ref); diff --git a/refspec.h b/refspec.h index 3f2bd4a..23e1555 100644 --- a/refspec.h +++ b/refspec.h @@ -60,12 +60,12 @@ void refspec_clear(struct refspec *rs); int valid_fetch_refspec(const char *refspec); -struct argv_array; +struct strvec; /* * Determine what values to pass to the peer in ref-prefix lines * (see Documentation/technical/protocol-v2.txt). */ void refspec_ref_prefixes(const struct refspec *rs, - struct argv_array *ref_prefixes); + struct strvec *ref_prefixes); #endif /* REFSPEC_H */ diff --git a/remote.h b/remote.h index 5cc26c1..5e3ea5a 100644 --- a/remote.h +++ b/remote.h @@ -168,7 +168,7 @@ void free_refs(struct ref *ref); struct oid_array; struct packet_reader; -struct argv_array; +struct strvec; struct string_list; struct ref **get_remote_heads(struct packet_reader *reader, struct ref **list, unsigned int flags, @@ -178,7 +178,7 @@ struct ref **get_remote_heads(struct packet_reader *reader, /* Used for protocol v2 in order to retrieve refs from a remote */ struct ref **get_remote_refs(int fd_out, struct packet_reader *reader, struct ref **list, int for_push, - const struct argv_array *ref_prefixes, + const struct strvec *ref_prefixes, const struct string_list *server_options, int stateless_rpc); diff --git a/serve.h b/serve.h index 42ddca7..fc2683e 100644 --- a/serve.h +++ b/serve.h @@ -1,8 +1,8 @@ #ifndef SERVE_H #define SERVE_H -struct argv_array; -int has_capability(const struct argv_array *keys, const char *capability, +struct strvec; +int has_capability(const struct strvec *keys, const char *capability, const char **value); struct serve_options { diff --git a/submodule.h b/submodule.h index 4dad649..9ce85c0 100644 --- a/submodule.h +++ b/submodule.h @@ -1,7 +1,7 @@ #ifndef SUBMODULE_H #define SUBMODULE_H -struct argv_array; +struct strvec; struct cache_entry; struct diff_options; struct index_state; @@ -84,7 +84,7 @@ int should_update_submodules(void); const struct submodule *submodule_from_ce(const struct cache_entry *ce); void check_for_new_submodule_commits(struct object_id *oid); int fetch_populated_submodules(struct repository *r, - const struct argv_array *options, + const struct strvec *options, const char *prefix, int command_line_option, int default_option, @@ -143,7 +143,7 @@ void submodule_unset_core_worktree(const struct submodule *sub); * a submodule by clearing any repo-specific environment variables, but * retaining any config in the environment. */ -void prepare_submodule_repo_env(struct argv_array *out); +void prepare_submodule_repo_env(struct strvec *out); #define ABSORB_GITDIR_RECURSE_SUBMODULES (1<<0) void absorb_git_dir_into_superproject(const char *path, diff --git a/transport-internal.h b/transport-internal.h index 1cde625..284784a 100644 --- a/transport-internal.h +++ b/transport-internal.h @@ -3,7 +3,7 @@ struct ref; struct transport; -struct argv_array; +struct strvec; struct transport_vtable { /** diff --git a/upload-pack.h b/upload-pack.h index 4bafe16..27ddcdc 100644 --- a/upload-pack.h +++ b/upload-pack.h @@ -11,9 +11,9 @@ struct upload_pack_options { void upload_pack(struct upload_pack_options *options); struct repository; -struct argv_array; +struct strvec; struct packet_reader; -int upload_pack_v2(struct repository *r, struct argv_array *keys, +int upload_pack_v2(struct repository *r, struct strvec *keys, struct packet_reader *request); struct strbuf; -- cgit v0.10.2-6-g49f6 From dbbcd44fb47347a3fdbee88ea21805b7f4ac0b98 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 28 Jul 2020 16:23:39 -0400 Subject: strvec: rename files from argv-array to strvec This requires updating #include lines across the code-base, but that's all fairly mechanical, and was done with: git ls-files '*.c' '*.h' | xargs perl -i -pe 's/argv-array.h/strvec.h/' Signed-off-by: Jeff King Signed-off-by: Junio C Hamano diff --git a/Makefile b/Makefile index 372139f..65f8cfb 100644 --- a/Makefile +++ b/Makefile @@ -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 diff --git a/add-patch.c b/add-patch.c index f899389..09d00c5 100644 --- a/add-patch.c +++ b/add-patch.c @@ -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" diff --git a/argv-array.c b/argv-array.c deleted file mode 100644 index b7461c4..0000000 --- a/argv-array.c +++ /dev/null @@ -1,109 +0,0 @@ -#include "cache.h" -#include "argv-array.h" -#include "strbuf.h" - -const char *empty_strvec[] = { NULL }; - -void strvec_init(struct strvec *array) -{ - array->argv = empty_strvec; - array->argc = 0; - array->alloc = 0; -} - -static void strvec_push_nodup(struct strvec *array, const char *value) -{ - if (array->argv == empty_strvec) - array->argv = NULL; - - ALLOC_GROW(array->argv, array->argc + 2, array->alloc); - array->argv[array->argc++] = value; - array->argv[array->argc] = NULL; -} - -const char *strvec_push(struct strvec *array, const char *value) -{ - strvec_push_nodup(array, xstrdup(value)); - return array->argv[array->argc - 1]; -} - -const char *strvec_pushf(struct strvec *array, const char *fmt, ...) -{ - va_list ap; - struct strbuf v = STRBUF_INIT; - - va_start(ap, fmt); - strbuf_vaddf(&v, fmt, ap); - va_end(ap); - - strvec_push_nodup(array, strbuf_detach(&v, NULL)); - return array->argv[array->argc - 1]; -} - -void strvec_pushl(struct strvec *array, ...) -{ - va_list ap; - const char *arg; - - va_start(ap, array); - while ((arg = va_arg(ap, const char *))) - strvec_push(array, arg); - va_end(ap); -} - -void strvec_pushv(struct strvec *array, const char **argv) -{ - for (; *argv; argv++) - strvec_push(array, *argv); -} - -void strvec_pop(struct strvec *array) -{ - if (!array->argc) - return; - free((char *)array->argv[array->argc - 1]); - array->argv[array->argc - 1] = NULL; - array->argc--; -} - -void strvec_split(struct strvec *array, const char *to_split) -{ - while (isspace(*to_split)) - to_split++; - for (;;) { - const char *p = to_split; - - if (!*p) - break; - - while (*p && !isspace(*p)) - p++; - strvec_push_nodup(array, xstrndup(to_split, p - to_split)); - - while (isspace(*p)) - p++; - to_split = p; - } -} - -void strvec_clear(struct strvec *array) -{ - if (array->argv != empty_strvec) { - int i; - for (i = 0; i < array->argc; i++) - free((char *)array->argv[i]); - free(array->argv); - } - strvec_init(array); -} - -const char **strvec_detach(struct strvec *array) -{ - if (array->argv == empty_strvec) - return xcalloc(1, sizeof(const char *)); - else { - const char **ret = array->argv; - strvec_init(array); - return ret; - } -} diff --git a/argv-array.h b/argv-array.h deleted file mode 100644 index ca66a33..0000000 --- a/argv-array.h +++ /dev/null @@ -1,102 +0,0 @@ -#ifndef ARGV_ARRAY_H -#define ARGV_ARRAY_H - -/** - * The argv-array API allows one to dynamically build and store - * NULL-terminated lists. An argv-array maintains the invariant that the - * `argv` member always points to a non-NULL array, and that the array is - * always NULL-terminated at the element pointed to by `argv[argc]`. This - * makes the result suitable for passing to functions expecting to receive - * argv from main(). - * - * The string-list API (documented in string-list.h) is similar, but cannot be - * used for these purposes; instead of storing a straight string pointer, - * it contains an item structure with a `util` field that is not compatible - * with the traditional argv interface. - * - * Each `strvec` manages its own memory. Any strings pushed into the - * array are duplicated, and all memory is freed by strvec_clear(). - */ - -extern const char *empty_strvec[]; - -/** - * A single array. This should be initialized by assignment from - * `STRVEC_INIT`, or by calling `strvec_init`. The `argv` - * member contains the actual array; the `argc` member contains the - * number of elements in the array, not including the terminating - * NULL. - */ -struct strvec { - const char **argv; - size_t argc; - size_t alloc; -}; - -#define STRVEC_INIT { empty_strvec, 0, 0 } - -/** - * Initialize an array. This is no different than assigning from - * `STRVEC_INIT`. - */ -void strvec_init(struct strvec *); - -/* Push a copy of a string onto the end of the array. */ -const char *strvec_push(struct strvec *, const char *); - -/** - * Format a string and push it onto the end of the array. This is a - * convenience wrapper combining `strbuf_addf` and `strvec_push`. - */ -__attribute__((format (printf,2,3))) -const char *strvec_pushf(struct strvec *, const char *fmt, ...); - -/** - * Push a list of strings onto the end of the array. The arguments - * should be a list of `const char *` strings, terminated by a NULL - * argument. - */ -LAST_ARG_MUST_BE_NULL -void strvec_pushl(struct strvec *, ...); - -/* Push a null-terminated array of strings onto the end of the array. */ -void strvec_pushv(struct strvec *, const char **); - -/** - * Remove the final element from the array. If there are no - * elements in the array, do nothing. - */ -void strvec_pop(struct strvec *); - -/* Splits by whitespace; does not handle quoted arguments! */ -void strvec_split(struct strvec *, const char *); - -/** - * Free all memory associated with the array and return it to the - * initial, empty state. - */ -void strvec_clear(struct strvec *); - -/** - * Disconnect the `argv` member from the `strvec` struct and - * return it. The caller is responsible for freeing the memory used - * by the array, and by the strings it references. After detaching, - * the `strvec` is in a reinitialized state and can be pushed - * into again. - */ -const char **strvec_detach(struct strvec *); - -/* compatibility for historic argv_array interface */ -#define argv_array strvec -#define ARGV_ARRAY_INIT STRVEC_INIT -#define argv_array_init strvec_init -#define argv_array_push strvec_push -#define argv_array_pushf strvec_pushf -#define argv_array_pushl strvec_pushl -#define argv_array_pushv strvec_pushv -#define argv_array_pop strvec_pop -#define argv_array_split strvec_split -#define argv_array_clear strvec_clear -#define argv_array_detach strvec_detach - -#endif /* ARGV_ARRAY_H */ diff --git a/bisect.c b/bisect.c index d5e8304..3160e82 100644 --- a/bisect.c +++ b/bisect.c @@ -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" diff --git a/builtin/add.c b/builtin/add.c index 298e011..6cd9a4c 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -18,7 +18,7 @@ #include "diffcore.h" #include "revision.h" #include "bulk-checkin.h" -#include "argv-array.h" +#include "strvec.h" #include "submodule.h" #include "add-interactive.h" diff --git a/builtin/annotate.c b/builtin/annotate.c index da413ae..4353448 100644 --- a/builtin/annotate.c +++ b/builtin/annotate.c @@ -5,7 +5,7 @@ */ #include "git-compat-util.h" #include "builtin.h" -#include "argv-array.h" +#include "strvec.h" int cmd_annotate(int argc, const char **argv, const char *prefix) { diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c index ec49962..e929315 100644 --- a/builtin/bisect--helper.c +++ b/builtin/bisect--helper.c @@ -4,7 +4,7 @@ #include "bisect.h" #include "refs.h" #include "dir.h" -#include "argv-array.h" +#include "strvec.h" #include "run-command.h" #include "prompt.h" #include "quote.h" diff --git a/builtin/bundle.c b/builtin/bundle.c index f049d27..51fc6d9 100644 --- a/builtin/bundle.c +++ b/builtin/bundle.c @@ -1,5 +1,5 @@ #include "builtin.h" -#include "argv-array.h" +#include "strvec.h" #include "parse-options.h" #include "cache.h" #include "bundle.h" diff --git a/builtin/describe.c b/builtin/describe.c index 21d2cb9..32ad682 100644 --- a/builtin/describe.c +++ b/builtin/describe.c @@ -12,7 +12,7 @@ #include "revision.h" #include "diff.h" #include "hashmap.h" -#include "argv-array.h" +#include "strvec.h" #include "run-command.h" #include "object-store.h" #include "list-objects.h" diff --git a/builtin/difftool.c b/builtin/difftool.c index c280e68..c0608a7 100644 --- a/builtin/difftool.c +++ b/builtin/difftool.c @@ -18,7 +18,7 @@ #include "run-command.h" #include "exec-cmd.h" #include "parse-options.h" -#include "argv-array.h" +#include "strvec.h" #include "strbuf.h" #include "lockfile.h" #include "object-store.h" diff --git a/builtin/fetch.c b/builtin/fetch.c index 82ac4be..b183b55 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -19,7 +19,7 @@ #include "submodule-config.h" #include "submodule.h" #include "connected.h" -#include "argv-array.h" +#include "strvec.h" #include "utf8.h" #include "packfile.h" #include "list-objects-filter-options.h" diff --git a/builtin/gc.c b/builtin/gc.c index 8e0b9cf..27951ee 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -18,7 +18,7 @@ #include "parse-options.h" #include "run-command.h" #include "sigchain.h" -#include "argv-array.h" +#include "strvec.h" #include "commit.h" #include "commit-graph.h" #include "packfile.h" diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 7016b28..5f18f0e 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -27,7 +27,7 @@ #include "delta-islands.h" #include "reachable.h" #include "oid-array.h" -#include "argv-array.h" +#include "strvec.h" #include "list.h" #include "packfile.h" #include "object-store.h" diff --git a/builtin/rebase.c b/builtin/rebase.c index 37ba76a..38145a6 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -8,7 +8,7 @@ #include "builtin.h" #include "run-command.h" #include "exec-cmd.h" -#include "argv-array.h" +#include "strvec.h" #include "dir.h" #include "packfile.h" #include "refs.h" diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index d43663b..1285631 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -15,7 +15,7 @@ #include "string-list.h" #include "oid-array.h" #include "connected.h" -#include "argv-array.h" +#include "strvec.h" #include "version.h" #include "tag.h" #include "gpg-interface.h" diff --git a/builtin/remote.c b/builtin/remote.c index e837799..a9f35ba 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -10,7 +10,7 @@ #include "refs.h" #include "refspec.h" #include "object-store.h" -#include "argv-array.h" +#include "strvec.h" #include "commit-reach.h" static const char * const builtin_remote_usage[] = { diff --git a/builtin/repack.c b/builtin/repack.c index df28773..8bccb38 100644 --- a/builtin/repack.c +++ b/builtin/repack.c @@ -7,7 +7,7 @@ #include "sigchain.h" #include "strbuf.h" #include "string-list.h" -#include "argv-array.h" +#include "strvec.h" #include "midx.h" #include "packfile.h" #include "prune-packed.h" diff --git a/builtin/show-branch.c b/builtin/show-branch.c index 7e52ee9..f0a7053 100644 --- a/builtin/show-branch.c +++ b/builtin/show-branch.c @@ -4,7 +4,7 @@ #include "refs.h" #include "builtin.h" #include "color.h" -#include "argv-array.h" +#include "strvec.h" #include "parse-options.h" #include "dir.h" #include "commit-slab.h" diff --git a/builtin/stash.c b/builtin/stash.c index 0c52a3b..1acf216 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -7,7 +7,7 @@ #include "cache-tree.h" #include "unpack-trees.h" #include "merge-recursive.h" -#include "argv-array.h" +#include "strvec.h" #include "run-command.h" #include "dir.h" #include "rerere.h" diff --git a/builtin/update-ref.c b/builtin/update-ref.c index b74dd9a6..8a2df44 100644 --- a/builtin/update-ref.c +++ b/builtin/update-ref.c @@ -4,7 +4,7 @@ #include "builtin.h" #include "parse-options.h" #include "quote.h" -#include "argv-array.h" +#include "strvec.h" static const char * const git_update_ref_usage[] = { N_("git update-ref [] -d []"), diff --git a/builtin/upload-archive.c b/builtin/upload-archive.c index 0188797..7fc8e0e 100644 --- a/builtin/upload-archive.c +++ b/builtin/upload-archive.c @@ -7,7 +7,7 @@ #include "pkt-line.h" #include "sideband.h" #include "run-command.h" -#include "argv-array.h" +#include "strvec.h" static const char upload_archive_usage[] = "git upload-archive "; diff --git a/builtin/worktree.c b/builtin/worktree.c index f0cbdef..3594509 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -4,7 +4,7 @@ #include "builtin.h" #include "dir.h" #include "parse-options.h" -#include "argv-array.h" +#include "strvec.h" #include "branch.h" #include "refs.h" #include "run-command.h" diff --git a/bundle.c b/bundle.c index 2a0d744..d46a387 100644 --- a/bundle.c +++ b/bundle.c @@ -10,7 +10,7 @@ #include "list-objects.h" #include "run-command.h" #include "refs.h" -#include "argv-array.h" +#include "strvec.h" static const char bundle_signature[] = "# v2 git bundle\n"; diff --git a/bundle.h b/bundle.h index 2dc9442..2cf1270 100644 --- a/bundle.h +++ b/bundle.h @@ -1,7 +1,7 @@ #ifndef BUNDLE_H #define BUNDLE_H -#include "argv-array.h" +#include "strvec.h" #include "cache.h" struct ref_list { diff --git a/diff.c b/diff.c index d24aaa3..ee00815 100644 --- a/diff.c +++ b/diff.c @@ -20,7 +20,7 @@ #include "hashmap.h" #include "ll-merge.h" #include "string-list.h" -#include "argv-array.h" +#include "strvec.h" #include "graph.h" #include "packfile.h" #include "parse-options.h" diff --git a/environment.c b/environment.c index aaca0e9..75fe5f4 100644 --- a/environment.c +++ b/environment.c @@ -14,7 +14,7 @@ #include "refs.h" #include "fmt-merge-msg.h" #include "commit.h" -#include "argv-array.h" +#include "strvec.h" #include "object-store.h" #include "chdir-notify.h" #include "shallow.h" diff --git a/exec-cmd.c b/exec-cmd.c index 7deeab3..bb24c2f 100644 --- a/exec-cmd.c +++ b/exec-cmd.c @@ -1,7 +1,7 @@ #include "cache.h" #include "exec-cmd.h" #include "quote.h" -#include "argv-array.h" +#include "strvec.h" #if defined(RUNTIME_PREFIX) diff --git a/graph.c b/graph.c index 4cd9915..96af8f6 100644 --- a/graph.c +++ b/graph.c @@ -4,7 +4,7 @@ #include "color.h" #include "graph.h" #include "revision.h" -#include "argv-array.h" +#include "strvec.h" /* Internal API */ diff --git a/http-backend.c b/http-backend.c index ec3144b..6a42bad 100644 --- a/http-backend.c +++ b/http-backend.c @@ -9,7 +9,7 @@ #include "run-command.h" #include "string-list.h" #include "url.h" -#include "argv-array.h" +#include "strvec.h" #include "packfile.h" #include "object-store.h" #include "protocol.h" diff --git a/http-push.c b/http-push.c index 1ff1883..3a47921 100644 --- a/http-push.c +++ b/http-push.c @@ -11,7 +11,7 @@ #include "remote.h" #include "list-objects.h" #include "sigchain.h" -#include "argv-array.h" +#include "strvec.h" #include "packfile.h" #include "object-store.h" #include "commit-reach.h" diff --git a/line-log.c b/line-log.c index c536928..05d077b 100644 --- a/line-log.c +++ b/line-log.c @@ -14,7 +14,7 @@ #include "graph.h" #include "userdiff.h" #include "line-log.h" -#include "argv-array.h" +#include "strvec.h" #include "bloom.h" static void range_set_grow(struct range_set *rs, size_t extra) diff --git a/list-objects-filter-options.c b/list-objects-filter-options.c index 3553ad7..3667766 100644 --- a/list-objects-filter-options.c +++ b/list-objects-filter-options.c @@ -2,7 +2,7 @@ #include "commit.h" #include "config.h" #include "revision.h" -#include "argv-array.h" +#include "strvec.h" #include "list-objects.h" #include "list-objects-filter.h" #include "list-objects-filter-options.h" diff --git a/ls-refs.c b/ls-refs.c index 50d8686..98fb190 100644 --- a/ls-refs.c +++ b/ls-refs.c @@ -2,7 +2,7 @@ #include "repository.h" #include "refs.h" #include "remote.h" -#include "argv-array.h" +#include "strvec.h" #include "ls-refs.h" #include "pkt-line.h" #include "config.h" diff --git a/parse-options-cb.c b/parse-options-cb.c index 86cd393..7cba964 100644 --- a/parse-options-cb.c +++ b/parse-options-cb.c @@ -4,7 +4,7 @@ #include "commit.h" #include "color.h" #include "string-list.h" -#include "argv-array.h" +#include "strvec.h" #include "oid-array.h" /*----- some often used options -----*/ diff --git a/pathspec.c b/pathspec.c index 8243e06..57c9b58 100644 --- a/pathspec.c +++ b/pathspec.c @@ -3,7 +3,7 @@ #include "dir.h" #include "pathspec.h" #include "attr.h" -#include "argv-array.h" +#include "strvec.h" #include "quote.h" /* diff --git a/quote.c b/quote.c index bcc0dbc..dac8b4e 100644 --- a/quote.c +++ b/quote.c @@ -1,6 +1,6 @@ #include "cache.h" #include "quote.h" -#include "argv-array.h" +#include "strvec.h" int quote_path_fully = 1; diff --git a/range-diff.c b/range-diff.c index 40af086..b4d1d56 100644 --- a/range-diff.c +++ b/range-diff.c @@ -2,7 +2,7 @@ #include "range-diff.h" #include "string-list.h" #include "run-command.h" -#include "argv-array.h" +#include "strvec.h" #include "hashmap.h" #include "xdiff-interface.h" #include "linear-assignment.h" diff --git a/range-diff.h b/range-diff.h index e11976d..916f18b 100644 --- a/range-diff.h +++ b/range-diff.h @@ -2,7 +2,7 @@ #define RANGE_DIFF_H #include "diff.h" -#include "argv-array.h" +#include "strvec.h" #define RANGE_DIFF_CREATION_FACTOR_DEFAULT 60 diff --git a/ref-filter.c b/ref-filter.c index 8447cb0..81c4399 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -22,7 +22,7 @@ #include "commit-reach.h" #include "worktree.h" #include "hashmap.h" -#include "argv-array.h" +#include "strvec.h" static struct ref_msg { const char *gone; diff --git a/refs.c b/refs.c index 639cba9..0067926 100644 --- a/refs.c +++ b/refs.c @@ -15,7 +15,7 @@ #include "tag.h" #include "submodule.h" #include "worktree.h" -#include "argv-array.h" +#include "strvec.h" #include "repository.h" #include "sigchain.h" diff --git a/refspec.c b/refspec.c index 9a9bf21..f9fb67d 100644 --- a/refspec.c +++ b/refspec.c @@ -1,5 +1,5 @@ #include "cache.h" -#include "argv-array.h" +#include "strvec.h" #include "refs.h" #include "refspec.h" diff --git a/remote-curl.c b/remote-curl.c index 5cbc6e5..05fb794 100644 --- a/remote-curl.c +++ b/remote-curl.c @@ -10,7 +10,7 @@ #include "pkt-line.h" #include "string-list.h" #include "sideband.h" -#include "argv-array.h" +#include "strvec.h" #include "credential.h" #include "oid-array.h" #include "send-pack.h" diff --git a/remote-testsvn.c b/remote-testsvn.c index cde39b9..809b290 100644 --- a/remote-testsvn.c +++ b/remote-testsvn.c @@ -8,7 +8,7 @@ #include "run-command.h" #include "vcs-svn/svndump.h" #include "notes.h" -#include "argv-array.h" +#include "strvec.h" static const char *url; static int dump_from_file; diff --git a/remote.c b/remote.c index bc46413..ba1a386 100644 --- a/remote.c +++ b/remote.c @@ -11,7 +11,7 @@ #include "tag.h" #include "string-list.h" #include "mergesort.h" -#include "argv-array.h" +#include "strvec.h" #include "commit-reach.h" #include "advice.h" diff --git a/revision.c b/revision.c index 6aa7f4f..07e16ed 100644 --- a/revision.c +++ b/revision.c @@ -23,7 +23,7 @@ #include "bisect.h" #include "packfile.h" #include "worktree.h" -#include "argv-array.h" +#include "strvec.h" #include "commit-reach.h" #include "commit-graph.h" #include "prio-queue.h" diff --git a/run-command.c b/run-command.c index a735e38..8f57661 100644 --- a/run-command.c +++ b/run-command.c @@ -2,7 +2,7 @@ #include "run-command.h" #include "exec-cmd.h" #include "sigchain.h" -#include "argv-array.h" +#include "strvec.h" #include "thread-utils.h" #include "strbuf.h" #include "string-list.h" diff --git a/run-command.h b/run-command.h index ef3071a..f5e05d3 100644 --- a/run-command.h +++ b/run-command.h @@ -3,7 +3,7 @@ #include "thread-utils.h" -#include "argv-array.h" +#include "strvec.h" /** * The run-command API offers a versatile tool to run sub-processes with diff --git a/sequencer.c b/sequencer.c index fd7701c..9e7f868 100644 --- a/sequencer.c +++ b/sequencer.c @@ -16,7 +16,7 @@ #include "rerere.h" #include "merge-recursive.h" #include "refs.h" -#include "argv-array.h" +#include "strvec.h" #include "quote.h" #include "trailer.h" #include "log-tree.h" diff --git a/serve.c b/serve.c index fbd2fcd..8d9a345 100644 --- a/serve.c +++ b/serve.c @@ -3,7 +3,7 @@ #include "config.h" #include "pkt-line.h" #include "version.h" -#include "argv-array.h" +#include "strvec.h" #include "ls-refs.h" #include "serve.h" #include "upload-pack.h" diff --git a/strvec.c b/strvec.c new file mode 100644 index 0000000..9e76ab9 --- /dev/null +++ b/strvec.c @@ -0,0 +1,109 @@ +#include "cache.h" +#include "strvec.h" +#include "strbuf.h" + +const char *empty_strvec[] = { NULL }; + +void strvec_init(struct strvec *array) +{ + array->argv = empty_strvec; + array->argc = 0; + array->alloc = 0; +} + +static void strvec_push_nodup(struct strvec *array, const char *value) +{ + if (array->argv == empty_strvec) + array->argv = NULL; + + ALLOC_GROW(array->argv, array->argc + 2, array->alloc); + array->argv[array->argc++] = value; + array->argv[array->argc] = NULL; +} + +const char *strvec_push(struct strvec *array, const char *value) +{ + strvec_push_nodup(array, xstrdup(value)); + return array->argv[array->argc - 1]; +} + +const char *strvec_pushf(struct strvec *array, const char *fmt, ...) +{ + va_list ap; + struct strbuf v = STRBUF_INIT; + + va_start(ap, fmt); + strbuf_vaddf(&v, fmt, ap); + va_end(ap); + + strvec_push_nodup(array, strbuf_detach(&v, NULL)); + return array->argv[array->argc - 1]; +} + +void strvec_pushl(struct strvec *array, ...) +{ + va_list ap; + const char *arg; + + va_start(ap, array); + while ((arg = va_arg(ap, const char *))) + strvec_push(array, arg); + va_end(ap); +} + +void strvec_pushv(struct strvec *array, const char **argv) +{ + for (; *argv; argv++) + strvec_push(array, *argv); +} + +void strvec_pop(struct strvec *array) +{ + if (!array->argc) + return; + free((char *)array->argv[array->argc - 1]); + array->argv[array->argc - 1] = NULL; + array->argc--; +} + +void strvec_split(struct strvec *array, const char *to_split) +{ + while (isspace(*to_split)) + to_split++; + for (;;) { + const char *p = to_split; + + if (!*p) + break; + + while (*p && !isspace(*p)) + p++; + strvec_push_nodup(array, xstrndup(to_split, p - to_split)); + + while (isspace(*p)) + p++; + to_split = p; + } +} + +void strvec_clear(struct strvec *array) +{ + if (array->argv != empty_strvec) { + int i; + for (i = 0; i < array->argc; i++) + free((char *)array->argv[i]); + free(array->argv); + } + strvec_init(array); +} + +const char **strvec_detach(struct strvec *array) +{ + if (array->argv == empty_strvec) + return xcalloc(1, sizeof(const char *)); + else { + const char **ret = array->argv; + strvec_init(array); + return ret; + } +} diff --git a/strvec.h b/strvec.h new file mode 100644 index 0000000..4be39c8 --- /dev/null +++ b/strvec.h @@ -0,0 +1,102 @@ +#ifndef STRVEC_H +#define STRVEC_H + +/** + * The argv-array API allows one to dynamically build and store + * NULL-terminated lists. An argv-array maintains the invariant that the + * `argv` member always points to a non-NULL array, and that the array is + * always NULL-terminated at the element pointed to by `argv[argc]`. This + * makes the result suitable for passing to functions expecting to receive + * argv from main(). + * + * The string-list API (documented in string-list.h) is similar, but cannot be + * used for these purposes; instead of storing a straight string pointer, + * it contains an item structure with a `util` field that is not compatible + * with the traditional argv interface. + * + * Each `strvec` manages its own memory. Any strings pushed into the + * array are duplicated, and all memory is freed by strvec_clear(). + */ + +extern const char *empty_strvec[]; + +/** + * A single array. This should be initialized by assignment from + * `STRVEC_INIT`, or by calling `strvec_init`. The `argv` + * member contains the actual array; the `argc` member contains the + * number of elements in the array, not including the terminating + * NULL. + */ +struct strvec { + const char **argv; + size_t argc; + size_t alloc; +}; + +#define STRVEC_INIT { empty_strvec, 0, 0 } + +/** + * Initialize an array. This is no different than assigning from + * `STRVEC_INIT`. + */ +void strvec_init(struct strvec *); + +/* Push a copy of a string onto the end of the array. */ +const char *strvec_push(struct strvec *, const char *); + +/** + * Format a string and push it onto the end of the array. This is a + * convenience wrapper combining `strbuf_addf` and `strvec_push`. + */ +__attribute__((format (printf,2,3))) +const char *strvec_pushf(struct strvec *, const char *fmt, ...); + +/** + * Push a list of strings onto the end of the array. The arguments + * should be a list of `const char *` strings, terminated by a NULL + * argument. + */ +LAST_ARG_MUST_BE_NULL +void strvec_pushl(struct strvec *, ...); + +/* Push a null-terminated array of strings onto the end of the array. */ +void strvec_pushv(struct strvec *, const char **); + +/** + * Remove the final element from the array. If there are no + * elements in the array, do nothing. + */ +void strvec_pop(struct strvec *); + +/* Splits by whitespace; does not handle quoted arguments! */ +void strvec_split(struct strvec *, const char *); + +/** + * Free all memory associated with the array and return it to the + * initial, empty state. + */ +void strvec_clear(struct strvec *); + +/** + * Disconnect the `argv` member from the `strvec` struct and + * return it. The caller is responsible for freeing the memory used + * by the array, and by the strings it references. After detaching, + * the `strvec` is in a reinitialized state and can be pushed + * into again. + */ +const char **strvec_detach(struct strvec *); + +/* compatibility for historic argv_array interface */ +#define argv_array strvec +#define ARGV_ARRAY_INIT STRVEC_INIT +#define argv_array_init strvec_init +#define argv_array_push strvec_push +#define argv_array_pushf strvec_pushf +#define argv_array_pushl strvec_pushl +#define argv_array_pushv strvec_pushv +#define argv_array_pop strvec_pop +#define argv_array_split strvec_split +#define argv_array_clear strvec_clear +#define argv_array_detach strvec_detach + +#endif /* STRVEC_H */ diff --git a/submodule.c b/submodule.c index e2ef569..874db5c 100644 --- a/submodule.c +++ b/submodule.c @@ -13,7 +13,7 @@ #include "refs.h" #include "string-list.h" #include "oid-array.h" -#include "argv-array.h" +#include "strvec.h" #include "blob.h" #include "thread-utils.h" #include "quote.h" diff --git a/t/helper/test-run-command.c b/t/helper/test-run-command.c index 1646aa2..8d3f6d5 100644 --- a/t/helper/test-run-command.c +++ b/t/helper/test-run-command.c @@ -12,7 +12,7 @@ #include "git-compat-util.h" #include "cache.h" #include "run-command.h" -#include "argv-array.h" +#include "strvec.h" #include "strbuf.h" #include "parse-options.h" #include "string-list.h" diff --git a/t/helper/test-trace2.c b/t/helper/test-trace2.c index 197819c..823f33c 100644 --- a/t/helper/test-trace2.c +++ b/t/helper/test-trace2.c @@ -1,6 +1,6 @@ #include "test-tool.h" #include "cache.h" -#include "argv-array.h" +#include "strvec.h" #include "run-command.h" #include "exec-cmd.h" #include "config.h" diff --git a/tmp-objdir.c b/tmp-objdir.c index 91c0056..06924a7 100644 --- a/tmp-objdir.c +++ b/tmp-objdir.c @@ -4,7 +4,7 @@ #include "sigchain.h" #include "string-list.h" #include "strbuf.h" -#include "argv-array.h" +#include "strvec.h" #include "quote.h" #include "object-store.h" diff --git a/transport-helper.c b/transport-helper.c index c6b753b..441763f 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -9,7 +9,7 @@ #include "string-list.h" #include "thread-utils.h" #include "sigchain.h" -#include "argv-array.h" +#include "strvec.h" #include "refs.h" #include "refspec.h" #include "transport-internal.h" diff --git a/unpack-trees.c b/unpack-trees.c index 4be5fc3..65c3395 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -1,5 +1,5 @@ #include "cache.h" -#include "argv-array.h" +#include "strvec.h" #include "repository.h" #include "config.h" #include "dir.h" diff --git a/unpack-trees.h b/unpack-trees.h index 9c2f082..f8a904a 100644 --- a/unpack-trees.h +++ b/unpack-trees.h @@ -2,7 +2,7 @@ #define UNPACK_TREES_H #include "cache.h" -#include "argv-array.h" +#include "strvec.h" #include "string-list.h" #include "tree-walk.h" diff --git a/upload-pack.c b/upload-pack.c index 951a2b2..b435dae 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -18,7 +18,7 @@ #include "sigchain.h" #include "version.h" #include "string-list.h" -#include "argv-array.h" +#include "strvec.h" #include "prio-queue.h" #include "protocol.h" #include "quote.h" diff --git a/wt-status.c b/wt-status.c index c560cbe..9817161 100644 --- a/wt-status.c +++ b/wt-status.c @@ -8,7 +8,7 @@ #include "diffcore.h" #include "quote.h" #include "run-command.h" -#include "argv-array.h" +#include "strvec.h" #include "remote.h" #include "refs.h" #include "submodule.h" -- cgit v0.10.2-6-g49f6 From 2745b6b4505ae11d6821c1d451169727b558a079 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 28 Jul 2020 16:24:02 -0400 Subject: quote: rename sq_dequote_to_argv_array to mention strvec We want to eventually drop the use of the "argv_array" name in favor of "strvec." Unlike most other uses of the name, this one is embedded in a function name, so the definition and all of the callers need to be updated at the same time. We don't technically need to update the parameter types here (our preprocessor compat macros make the two names interchangeable), but let's do so to keep the site consistent for now. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano diff --git a/bisect.c b/bisect.c index 3160e82..77e35dd 100644 --- a/bisect.c +++ b/bisect.c @@ -464,7 +464,7 @@ static void read_bisect_paths(struct argv_array *array) 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); } diff --git a/builtin/am.c b/builtin/am.c index 69e50de..0641316 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -399,7 +399,7 @@ static void am_load(struct am_state *state) read_state_file(&sb, state, "apply-opt", 1); argv_array_clear(&state->git_apply_opts); - if (sq_dequote_to_argv_array(sb.buf, &state->git_apply_opts) < 0) + if (sq_dequote_to_strvec(sb.buf, &state->git_apply_opts) < 0) die(_("could not parse %s"), am_path(state, "apply-opt")); state->rebasing = !!file_exists(am_path(state, "rebasing")); diff --git a/quote.c b/quote.c index dac8b4e..10b383c 100644 --- a/quote.c +++ b/quote.c @@ -198,7 +198,7 @@ int sq_dequote_to_argv(char *arg, const char ***argv, int *nr, int *alloc) return sq_dequote_to_argv_internal(arg, argv, nr, alloc, NULL); } -int sq_dequote_to_argv_array(char *arg, struct argv_array *array) +int sq_dequote_to_strvec(char *arg, struct strvec *array) { return sq_dequote_to_argv_internal(arg, NULL, NULL, NULL, array); } diff --git a/quote.h b/quote.h index 210d580..fa09309 100644 --- a/quote.h +++ b/quote.h @@ -56,12 +56,12 @@ char *sq_dequote(char *); int sq_dequote_to_argv(char *arg, const char ***argv, int *nr, int *alloc); /* - * Same as above, but store the unquoted strings in an argv_array. We will - * still modify arg in place, but unlike sq_dequote_to_argv, the argv_array + * Same as above, but store the unquoted strings in a strvec. We will + * still modify arg in place, but unlike sq_dequote_to_argv, the strvec * will duplicate and take ownership of the strings. */ struct strvec; -int sq_dequote_to_argv_array(char *arg, struct strvec *); +int sq_dequote_to_strvec(char *arg, struct strvec *); int unquote_c_style(struct strbuf *, const char *quoted, const char **endp); size_t quote_c_style(const char *name, struct strbuf *, FILE *, int no_dq); -- cgit v0.10.2-6-g49f6 From 22f9b7f3f59549735a480042a4b9ce292eedfae0 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 28 Jul 2020 16:24:27 -0400 Subject: strvec: convert builtin/ callers away from argv_array name We eventually want to drop the argv_array name and just use strvec consistently. There's no particular reason we have to do it all at once, or care about interactions between converted and unconverted bits. Because of our preprocessor compat layer, the names are interchangeable to the compiler (so even a definition and declaration using different names is OK). This patch converts all of the files in builtin/ to keep the diff to a manageable size. The conversion was done purely mechanically with: git ls-files '*.c' '*.h' | xargs perl -i -pe ' s/ARGV_ARRAY/STRVEC/g; s/argv_array/strvec/g; ' and then selectively staging files with "git add builtin/". We'll deal with any indentation/style fallouts separately. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano diff --git a/builtin/add.c b/builtin/add.c index 6cd9a4c..6185dd1 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -188,7 +188,7 @@ int run_add_interactive(const char *revision, const char *patch_mode, const struct pathspec *pathspec) { int status, i; - struct argv_array argv = ARGV_ARRAY_INIT; + struct strvec argv = STRVEC_INIT; int use_builtin_add_i = git_env_bool("GIT_TEST_ADD_I_USE_BUILTIN", -1); @@ -218,18 +218,18 @@ int run_add_interactive(const char *revision, const char *patch_mode, return !!run_add_p(the_repository, mode, revision, pathspec); } - argv_array_push(&argv, "add--interactive"); + strvec_push(&argv, "add--interactive"); if (patch_mode) - argv_array_push(&argv, patch_mode); + strvec_push(&argv, patch_mode); if (revision) - argv_array_push(&argv, revision); - argv_array_push(&argv, "--"); + strvec_push(&argv, revision); + strvec_push(&argv, "--"); for (i = 0; i < pathspec->nr; i++) /* pass original pathspec, to be re-parsed */ - argv_array_push(&argv, pathspec->items[i].original); + strvec_push(&argv, pathspec->items[i].original); status = run_command_v_opt(argv.argv, RUN_GIT_CMD); - argv_array_clear(&argv); + strvec_clear(&argv); return status; } diff --git a/builtin/am.c b/builtin/am.c index 0641316..992ab3c 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -116,7 +116,7 @@ struct am_state { int keep; /* enum keep_type */ int message_id; int scissors; /* enum scissors_type */ - struct argv_array git_apply_opts; + struct strvec git_apply_opts; const char *resolvemsg; int committer_date_is_author_date; int ignore_date; @@ -146,7 +146,7 @@ static void am_state_init(struct am_state *state) state->scissors = SCISSORS_UNSET; - argv_array_init(&state->git_apply_opts); + strvec_init(&state->git_apply_opts); if (!git_config_get_bool("commit.gpgsign", &gpgsign)) state->sign_commit = gpgsign ? "" : NULL; @@ -162,7 +162,7 @@ static void am_state_release(struct am_state *state) free(state->author_email); free(state->author_date); free(state->msg); - argv_array_clear(&state->git_apply_opts); + strvec_clear(&state->git_apply_opts); } /** @@ -398,7 +398,7 @@ static void am_load(struct am_state *state) state->scissors = SCISSORS_UNSET; read_state_file(&sb, state, "apply-opt", 1); - argv_array_clear(&state->git_apply_opts); + strvec_clear(&state->git_apply_opts); if (sq_dequote_to_strvec(sb.buf, &state->git_apply_opts) < 0) die(_("could not parse %s"), am_path(state, "apply-opt")); @@ -452,8 +452,8 @@ static int run_post_rewrite_hook(const struct am_state *state) if (!hook) return 0; - argv_array_push(&cp.args, hook); - argv_array_push(&cp.args, "rebase"); + strvec_push(&cp.args, hook); + strvec_push(&cp.args, "rebase"); cp.in = xopen(am_path(state, "rewritten"), O_RDONLY); cp.stdout_to_stderr = 1; @@ -651,16 +651,16 @@ static int split_mail_mbox(struct am_state *state, const char **paths, int ret; cp.git_cmd = 1; - argv_array_push(&cp.args, "mailsplit"); - argv_array_pushf(&cp.args, "-d%d", state->prec); - argv_array_pushf(&cp.args, "-o%s", state->dir); - argv_array_push(&cp.args, "-b"); + strvec_push(&cp.args, "mailsplit"); + strvec_pushf(&cp.args, "-d%d", state->prec); + strvec_pushf(&cp.args, "-o%s", state->dir); + strvec_push(&cp.args, "-b"); if (keep_cr) - argv_array_push(&cp.args, "--keep-cr"); + strvec_push(&cp.args, "--keep-cr"); if (mboxrd) - argv_array_push(&cp.args, "--mboxrd"); - argv_array_push(&cp.args, "--"); - argv_array_pushv(&cp.args, paths); + strvec_push(&cp.args, "--mboxrd"); + strvec_push(&cp.args, "--"); + strvec_pushv(&cp.args, paths); ret = capture_command(&cp, &last, 8); if (ret) @@ -787,7 +787,7 @@ static int split_mail_stgit_series(struct am_state *state, const char **paths, const char *series_dir; char *series_dir_buf; FILE *fp; - struct argv_array patches = ARGV_ARRAY_INIT; + struct strvec patches = STRVEC_INIT; struct strbuf sb = STRBUF_INIT; int ret; @@ -805,7 +805,7 @@ static int split_mail_stgit_series(struct am_state *state, const char **paths, if (*sb.buf == '#') continue; /* skip comment lines */ - argv_array_push(&patches, mkpath("%s/%s", series_dir, sb.buf)); + strvec_push(&patches, mkpath("%s/%s", series_dir, sb.buf)); } fclose(fp); @@ -814,7 +814,7 @@ static int split_mail_stgit_series(struct am_state *state, const char **paths, ret = split_mail_conv(stgit_patch_to_mail, state, patches.argv, keep_cr); - argv_array_clear(&patches); + strvec_clear(&patches); return ret; } @@ -1390,8 +1390,8 @@ static int parse_mail_rebase(struct am_state *state, const char *mail) */ static int run_apply(const struct am_state *state, const char *index_file) { - struct argv_array apply_paths = ARGV_ARRAY_INIT; - struct argv_array apply_opts = ARGV_ARRAY_INIT; + struct strvec apply_paths = STRVEC_INIT; + struct strvec apply_opts = STRVEC_INIT; struct apply_state apply_state; int res, opts_left; int force_apply = 0; @@ -1400,8 +1400,8 @@ static int run_apply(const struct am_state *state, const char *index_file) if (init_apply_state(&apply_state, the_repository, NULL)) BUG("init_apply_state() failed"); - argv_array_push(&apply_opts, "apply"); - argv_array_pushv(&apply_opts, state->git_apply_opts.argv); + strvec_push(&apply_opts, "apply"); + strvec_pushv(&apply_opts, state->git_apply_opts.argv); opts_left = apply_parse_options(apply_opts.argc, apply_opts.argv, &apply_state, &force_apply, &options, @@ -1426,12 +1426,12 @@ static int run_apply(const struct am_state *state, const char *index_file) if (check_apply_state(&apply_state, force_apply)) BUG("check_apply_state() failed"); - argv_array_push(&apply_paths, am_path(state, "patch")); + strvec_push(&apply_paths, am_path(state, "patch")); res = apply_all_patches(&apply_state, apply_paths.argc, apply_paths.argv, options); - argv_array_clear(&apply_paths); - argv_array_clear(&apply_opts); + strvec_clear(&apply_paths); + strvec_clear(&apply_opts); clear_apply_state(&apply_state); if (res) @@ -1454,10 +1454,10 @@ static int build_fake_ancestor(const struct am_state *state, const char *index_f struct child_process cp = CHILD_PROCESS_INIT; cp.git_cmd = 1; - argv_array_push(&cp.args, "apply"); - argv_array_pushv(&cp.args, state->git_apply_opts.argv); - argv_array_pushf(&cp.args, "--build-fake-ancestor=%s", index_file); - argv_array_push(&cp.args, am_path(state, "patch")); + strvec_push(&cp.args, "apply"); + strvec_pushv(&cp.args, state->git_apply_opts.argv); + strvec_pushf(&cp.args, "--build-fake-ancestor=%s", index_file); + strvec_push(&cp.args, am_path(state, "patch")); if (run_command(&cp)) return -1; @@ -1676,7 +1676,7 @@ static int do_interactive(struct am_state *state) if (!pager) pager = "cat"; prepare_pager_args(&cp, pager); - argv_array_push(&cp.args, am_path(state, "patch")); + strvec_push(&cp.args, am_path(state, "patch")); run_command(&cp); } } @@ -2346,7 +2346,7 @@ int cmd_am(int argc, const char **argv, const char *prefix) if (state.signoff == SIGNOFF_EXPLICIT) am_append_signoff(&state); } else { - struct argv_array paths = ARGV_ARRAY_INIT; + struct strvec paths = STRVEC_INIT; int i; /* @@ -2371,9 +2371,9 @@ int cmd_am(int argc, const char **argv, const char *prefix) for (i = 0; i < argc; i++) { if (is_absolute_path(argv[i]) || !prefix) - argv_array_push(&paths, argv[i]); + strvec_push(&paths, argv[i]); else - argv_array_push(&paths, mkpath("%s/%s", prefix, argv[i])); + strvec_push(&paths, mkpath("%s/%s", prefix, argv[i])); } if (state.interactive && !paths.argc) @@ -2381,7 +2381,7 @@ int cmd_am(int argc, const char **argv, const char *prefix) am_setup(&state, patch_format, paths.argv, keep_cr); - argv_array_clear(&paths); + strvec_clear(&paths); } switch (resume.mode) { diff --git a/builtin/annotate.c b/builtin/annotate.c index 4353448..7b7ecd3 100644 --- a/builtin/annotate.c +++ b/builtin/annotate.c @@ -9,13 +9,13 @@ int cmd_annotate(int argc, const char **argv, const char *prefix) { - struct argv_array args = ARGV_ARRAY_INIT; + struct strvec args = STRVEC_INIT; int i; - argv_array_pushl(&args, "annotate", "-c", NULL); + strvec_pushl(&args, "annotate", "-c", NULL); for (i = 1; i < argc; i++) { - argv_array_push(&args, argv[i]); + strvec_push(&args, argv[i]); } return cmd_blame(args.argc, args.argv, prefix); diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c index e929315..9815e78 100644 --- a/builtin/bisect--helper.c +++ b/builtin/bisect--helper.c @@ -165,18 +165,18 @@ static int bisect_reset(const char *commit) } if (!file_exists(git_path_bisect_head())) { - struct argv_array argv = ARGV_ARRAY_INIT; + struct strvec argv = STRVEC_INIT; - argv_array_pushl(&argv, "checkout", branch.buf, "--", NULL); + strvec_pushl(&argv, "checkout", branch.buf, "--", NULL); if (run_command_v_opt(argv.argv, RUN_GIT_CMD)) { error(_("could not check out original" " HEAD '%s'. Try 'git bisect" " reset '."), branch.buf); strbuf_release(&branch); - argv_array_clear(&argv); + strvec_clear(&argv); return -1; } - argv_array_clear(&argv); + strvec_clear(&argv); } strbuf_release(&branch); @@ -526,9 +526,9 @@ static int bisect_start(struct bisect_terms *terms, int no_checkout, strbuf_read_file(&start_head, git_path_bisect_start(), 0); strbuf_trim(&start_head); if (!no_checkout) { - struct argv_array argv = ARGV_ARRAY_INIT; + struct strvec argv = STRVEC_INIT; - argv_array_pushl(&argv, "checkout", start_head.buf, + strvec_pushl(&argv, "checkout", start_head.buf, "--", NULL); if (run_command_v_opt(argv.argv, RUN_GIT_CMD)) { res = error(_("checking out '%s' failed." diff --git a/builtin/bundle.c b/builtin/bundle.c index 51fc6d9..750630b 100644 --- a/builtin/bundle.c +++ b/builtin/bundle.c @@ -59,7 +59,7 @@ static int parse_options_cmd_bundle(int argc, static int cmd_bundle_create(int argc, const char **argv, const char *prefix) { int all_progress_implied = 0; int progress = isatty(STDERR_FILENO); - struct argv_array pack_opts; + struct strvec pack_opts; struct option options[] = { OPT_SET_INT('q', "quiet", &progress, @@ -79,15 +79,15 @@ static int cmd_bundle_create(int argc, const char **argv, const char *prefix) { builtin_bundle_create_usage, options, &bundle_file); /* bundle internals use argv[1] as further parameters */ - argv_array_init(&pack_opts); + strvec_init(&pack_opts); if (progress == 0) - argv_array_push(&pack_opts, "--quiet"); + strvec_push(&pack_opts, "--quiet"); else if (progress == 1) - argv_array_push(&pack_opts, "--progress"); + strvec_push(&pack_opts, "--progress"); else if (progress == 2) - argv_array_push(&pack_opts, "--all-progress"); + strvec_push(&pack_opts, "--all-progress"); if (progress && all_progress_implied) - argv_array_push(&pack_opts, "--all-progress-implied"); + strvec_push(&pack_opts, "--all-progress-implied"); if (!startup_info->have_repository) die(_("Need a repository to create a bundle.")); diff --git a/builtin/clone.c b/builtin/clone.c index bef7074..e26bd82 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -742,9 +742,9 @@ static void update_head(const struct ref *our, const struct ref *remote, static int git_sparse_checkout_init(const char *repo) { - struct argv_array argv = ARGV_ARRAY_INIT; + struct strvec argv = STRVEC_INIT; int result = 0; - argv_array_pushl(&argv, "-C", repo, "sparse-checkout", "init", NULL); + strvec_pushl(&argv, "-C", repo, "sparse-checkout", "init", NULL); /* * We must apply the setting in the current process @@ -757,7 +757,7 @@ static int git_sparse_checkout_init(const char *repo) result = 1; } - argv_array_clear(&argv); + strvec_clear(&argv); return result; } @@ -819,33 +819,33 @@ static int checkout(int submodule_progress) oid_to_hex(&oid), "1", NULL); if (!err && (option_recurse_submodules.nr > 0)) { - struct argv_array args = ARGV_ARRAY_INIT; - argv_array_pushl(&args, "submodule", "update", "--require-init", "--recursive", NULL); + struct strvec args = STRVEC_INIT; + strvec_pushl(&args, "submodule", "update", "--require-init", "--recursive", NULL); if (option_shallow_submodules == 1) - argv_array_push(&args, "--depth=1"); + strvec_push(&args, "--depth=1"); if (max_jobs != -1) - argv_array_pushf(&args, "--jobs=%d", max_jobs); + strvec_pushf(&args, "--jobs=%d", max_jobs); if (submodule_progress) - argv_array_push(&args, "--progress"); + strvec_push(&args, "--progress"); if (option_verbosity < 0) - argv_array_push(&args, "--quiet"); + strvec_push(&args, "--quiet"); if (option_remote_submodules) { - argv_array_push(&args, "--remote"); - argv_array_push(&args, "--no-fetch"); + strvec_push(&args, "--remote"); + strvec_push(&args, "--no-fetch"); } if (option_single_branch >= 0) - argv_array_push(&args, option_single_branch ? + strvec_push(&args, option_single_branch ? "--single-branch" : "--no-single-branch"); err = run_command_v_opt(args.argv, RUN_GIT_CMD); - argv_array_clear(&args); + strvec_clear(&args); } return err; @@ -961,7 +961,7 @@ int cmd_clone(int argc, const char **argv, const char *prefix) int err = 0, complete_refs_before_fetch = 1; int submodule_progress; - struct argv_array ref_prefixes = ARGV_ARRAY_INIT; + struct strvec ref_prefixes = STRVEC_INIT; packet_trace_identity("clone"); argc = parse_options(argc, argv, prefix, builtin_clone_options, @@ -1211,12 +1211,12 @@ int cmd_clone(int argc, const char **argv, const char *prefix) transport->smart_options->check_self_contained_and_connected = 1; - argv_array_push(&ref_prefixes, "HEAD"); + strvec_push(&ref_prefixes, "HEAD"); refspec_ref_prefixes(&remote->fetch, &ref_prefixes); if (option_branch) expand_ref_prefix(&ref_prefixes, option_branch); if (!option_no_tags) - argv_array_push(&ref_prefixes, "refs/tags/"); + strvec_push(&ref_prefixes, "refs/tags/"); refs = transport_get_remote_refs(transport, &ref_prefixes); @@ -1327,6 +1327,6 @@ int cmd_clone(int argc, const char **argv, const char *prefix) strbuf_release(&default_refspec); junk_mode = JUNK_LEAVE_ALL; - argv_array_clear(&ref_prefixes); + strvec_clear(&ref_prefixes); return err; } diff --git a/builtin/commit.c b/builtin/commit.c index d1b7396..c3f4067 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1005,15 +1005,15 @@ static int prepare_to_commit(const char *index_file, const char *prefix, return 0; if (use_editor) { - struct argv_array env = ARGV_ARRAY_INIT; + struct strvec env = STRVEC_INIT; - argv_array_pushf(&env, "GIT_INDEX_FILE=%s", index_file); + strvec_pushf(&env, "GIT_INDEX_FILE=%s", index_file); if (launch_editor(git_path_commit_editmsg(), NULL, env.argv)) { fprintf(stderr, _("Please supply the message using either -m or -F option.\n")); exit(1); } - argv_array_clear(&env); + strvec_clear(&env); } if (!no_verify && diff --git a/builtin/describe.c b/builtin/describe.c index 32ad682..ff3c169 100644 --- a/builtin/describe.c +++ b/builtin/describe.c @@ -501,10 +501,10 @@ static void process_object(struct object *obj, const char *path, void *data) static void describe_blob(struct object_id oid, struct strbuf *dst) { struct rev_info revs; - struct argv_array args = ARGV_ARRAY_INIT; + struct strvec args = STRVEC_INIT; struct process_commit_data pcd = { null_oid, oid, dst, &revs}; - argv_array_pushl(&args, "internal: The first arg is not parsed", + strvec_pushl(&args, "internal: The first arg is not parsed", "--objects", "--in-commit-order", "--reverse", "HEAD", NULL); @@ -594,25 +594,25 @@ int cmd_describe(int argc, const char **argv, const char *prefix) if (contains) { struct string_list_item *item; - struct argv_array args; + struct strvec args; - argv_array_init(&args); - argv_array_pushl(&args, "name-rev", + strvec_init(&args); + strvec_pushl(&args, "name-rev", "--peel-tag", "--name-only", "--no-undefined", NULL); if (always) - argv_array_push(&args, "--always"); + strvec_push(&args, "--always"); if (!all) { - argv_array_push(&args, "--tags"); + strvec_push(&args, "--tags"); for_each_string_list_item(item, &patterns) - argv_array_pushf(&args, "--refs=refs/tags/%s", item->string); + strvec_pushf(&args, "--refs=refs/tags/%s", item->string); for_each_string_list_item(item, &exclude_patterns) - argv_array_pushf(&args, "--exclude=refs/tags/%s", item->string); + strvec_pushf(&args, "--exclude=refs/tags/%s", item->string); } if (argc) - argv_array_pushv(&args, argv); + strvec_pushv(&args, argv); else - argv_array_push(&args, "HEAD"); + strvec_push(&args, "HEAD"); return cmd_name_rev(args.argc, args.argv, prefix); } @@ -624,7 +624,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix) if (argc == 0) { if (broken) { struct child_process cp = CHILD_PROCESS_INIT; - argv_array_pushv(&cp.args, diff_index_args); + strvec_pushv(&cp.args, diff_index_args); cp.git_cmd = 1; cp.no_stdin = 1; cp.no_stdout = 1; @@ -646,7 +646,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix) } else if (dirty) { struct lock_file index_lock = LOCK_INIT; struct rev_info revs; - struct argv_array args = ARGV_ARRAY_INIT; + struct strvec args = STRVEC_INIT; int fd, result; setup_work_tree(); @@ -658,7 +658,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix) repo_update_index_if_able(the_repository, &index_lock); repo_init_revisions(the_repository, &revs, prefix); - argv_array_pushv(&args, diff_index_args); + strvec_pushv(&args, diff_index_args); if (setup_revisions(args.argc, args.argv, &revs, NULL) != 1) BUG("malformed internal diff-index command line"); result = run_diff_index(&revs, 0); diff --git a/builtin/difftool.c b/builtin/difftool.c index c0608a7..40c4d7b 100644 --- a/builtin/difftool.c +++ b/builtin/difftool.c @@ -210,7 +210,7 @@ static void changed_files(struct hashmap *result, const char *index_path, strbuf_addf(&index_env, "GIT_INDEX_FILE=%s", index_path); env[0] = index_env.buf; - argv_array_pushl(&update_index.args, + strvec_pushl(&update_index.args, "--git-dir", git_dir, "--work-tree", workdir, "update-index", "--really-refresh", "-q", "--unmerged", NULL); @@ -225,7 +225,7 @@ static void changed_files(struct hashmap *result, const char *index_path, /* Ignore any errors of update-index */ run_command(&update_index); - argv_array_pushl(&diff_files.args, + strvec_pushl(&diff_files.args, "--git-dir", git_dir, "--work-tree", workdir, "diff-files", "--name-only", "-z", NULL); diff_files.no_stdin = 1; @@ -393,10 +393,10 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix, child.clean_on_exit = 1; child.dir = prefix; child.out = -1; - argv_array_pushl(&child.args, "diff", "--raw", "--no-abbrev", "-z", + strvec_pushl(&child.args, "diff", "--raw", "--no-abbrev", "-z", NULL); for (i = 0; i < argc; i++) - argv_array_push(&child.args, argv[i]); + strvec_push(&child.args, argv[i]); if (start_command(&child)) die("could not obtain raw diff"); fp = xfdopen(child.out, "r"); @@ -667,7 +667,7 @@ finish: static int run_file_diff(int prompt, const char *prefix, int argc, const char **argv) { - struct argv_array args = ARGV_ARRAY_INIT; + struct strvec args = STRVEC_INIT; const char *env[] = { "GIT_PAGER=", "GIT_EXTERNAL_DIFF=git-difftool--helper", NULL, NULL @@ -680,9 +680,9 @@ static int run_file_diff(int prompt, const char *prefix, env[2] = "GIT_DIFFTOOL_NO_PROMPT=true"; - argv_array_push(&args, "diff"); + strvec_push(&args, "diff"); for (i = 0; i < argc; i++) - argv_array_push(&args, argv[i]); + strvec_push(&args, argv[i]); ret = run_command_v_opt_cd_env(args.argv, RUN_GIT_CMD, prefix, env); exit(ret); } diff --git a/builtin/fetch.c b/builtin/fetch.c index b183b55..cc63618 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -1316,7 +1316,7 @@ static int do_fetch(struct transport *transport, int autotags = (transport->remote->fetch_tags == 1); int retcode = 0; const struct ref *remote_refs; - struct argv_array ref_prefixes = ARGV_ARRAY_INIT; + struct strvec ref_prefixes = STRVEC_INIT; int must_list_refs = 1; if (tags == TAGS_DEFAULT) { @@ -1355,7 +1355,7 @@ static int do_fetch(struct transport *transport, if (tags == TAGS_SET || tags == TAGS_DEFAULT) { must_list_refs = 1; if (ref_prefixes.argc) - argv_array_push(&ref_prefixes, "refs/tags/"); + strvec_push(&ref_prefixes, "refs/tags/"); } if (must_list_refs) { @@ -1365,7 +1365,7 @@ static int do_fetch(struct transport *transport, } else remote_refs = NULL; - argv_array_clear(&ref_prefixes); + strvec_clear(&ref_prefixes); ref_map = get_ref_map(transport->remote, remote_refs, rs, tags, &autotags); @@ -1503,34 +1503,34 @@ static int add_remote_or_group(const char *name, struct string_list *list) return 1; } -static void add_options_to_argv(struct argv_array *argv) +static void add_options_to_argv(struct strvec *argv) { if (dry_run) - argv_array_push(argv, "--dry-run"); + strvec_push(argv, "--dry-run"); if (prune != -1) - argv_array_push(argv, prune ? "--prune" : "--no-prune"); + strvec_push(argv, prune ? "--prune" : "--no-prune"); if (prune_tags != -1) - argv_array_push(argv, prune_tags ? "--prune-tags" : "--no-prune-tags"); + strvec_push(argv, prune_tags ? "--prune-tags" : "--no-prune-tags"); if (update_head_ok) - argv_array_push(argv, "--update-head-ok"); + strvec_push(argv, "--update-head-ok"); if (force) - argv_array_push(argv, "--force"); + strvec_push(argv, "--force"); if (keep) - argv_array_push(argv, "--keep"); + strvec_push(argv, "--keep"); if (recurse_submodules == RECURSE_SUBMODULES_ON) - argv_array_push(argv, "--recurse-submodules"); + strvec_push(argv, "--recurse-submodules"); else if (recurse_submodules == RECURSE_SUBMODULES_ON_DEMAND) - argv_array_push(argv, "--recurse-submodules=on-demand"); + strvec_push(argv, "--recurse-submodules=on-demand"); if (tags == TAGS_SET) - argv_array_push(argv, "--tags"); + strvec_push(argv, "--tags"); else if (tags == TAGS_UNSET) - argv_array_push(argv, "--no-tags"); + strvec_push(argv, "--no-tags"); if (verbosity >= 2) - argv_array_push(argv, "-v"); + strvec_push(argv, "-v"); if (verbosity >= 1) - argv_array_push(argv, "-v"); + strvec_push(argv, "-v"); else if (verbosity < 0) - argv_array_push(argv, "-q"); + strvec_push(argv, "-q"); } @@ -1554,8 +1554,8 @@ static int fetch_next_remote(struct child_process *cp, struct strbuf *out, remote = state->remotes->items[state->next++].string; *task_cb = remote; - argv_array_pushv(&cp->args, state->argv); - argv_array_push(&cp->args, remote); + strvec_pushv(&cp->args, state->argv); + strvec_push(&cp->args, remote); cp->git_cmd = 1; if (verbosity >= 0) @@ -1592,7 +1592,7 @@ static int fetch_finished(int result, struct strbuf *out, static int fetch_multiple(struct string_list *list, int max_children) { int i, result = 0; - struct argv_array argv = ARGV_ARRAY_INIT; + struct strvec argv = STRVEC_INIT; if (!append && !dry_run) { int errcode = truncate_fetch_head(); @@ -1600,14 +1600,14 @@ static int fetch_multiple(struct string_list *list, int max_children) return errcode; } - argv_array_pushl(&argv, "fetch", "--append", "--no-auto-gc", + strvec_pushl(&argv, "fetch", "--append", "--no-auto-gc", "--no-write-commit-graph", NULL); add_options_to_argv(&argv); if (max_children != 1 && list->nr != 1) { struct parallel_fetch_state state = { argv.argv, list, 0, 0 }; - argv_array_push(&argv, "--end-of-options"); + strvec_push(&argv, "--end-of-options"); result = run_processes_parallel_tr2(max_children, &fetch_next_remote, &fetch_failed_to_start, @@ -1620,17 +1620,17 @@ static int fetch_multiple(struct string_list *list, int max_children) } else for (i = 0; i < list->nr; i++) { const char *name = list->items[i].string; - argv_array_push(&argv, name); + strvec_push(&argv, name); if (verbosity >= 0) printf(_("Fetching %s\n"), name); if (run_command_v_opt(argv.argv, RUN_GIT_CMD)) { error(_("Could not fetch %s"), name); result = 1; } - argv_array_pop(&argv); + strvec_pop(&argv); } - argv_array_clear(&argv); + strvec_clear(&argv); return !!result; } @@ -1844,7 +1844,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix) } if (!result && (recurse_submodules != RECURSE_SUBMODULES_OFF)) { - struct argv_array options = ARGV_ARRAY_INIT; + struct strvec options = STRVEC_INIT; int max_children = max_jobs; if (max_children < 0) @@ -1860,7 +1860,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix) recurse_submodules_default, verbosity < 0, max_children); - argv_array_clear(&options); + strvec_clear(&options); } string_list_clear(&list, 0); diff --git a/builtin/gc.c b/builtin/gc.c index 27951ee..89742e1 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -50,12 +50,12 @@ static const char *prune_worktrees_expire = "3.months.ago"; static unsigned long big_pack_threshold; static unsigned long max_delta_cache_size = DEFAULT_DELTA_CACHE_SIZE; -static struct argv_array pack_refs_cmd = ARGV_ARRAY_INIT; -static struct argv_array reflog = ARGV_ARRAY_INIT; -static struct argv_array repack = ARGV_ARRAY_INIT; -static struct argv_array prune = ARGV_ARRAY_INIT; -static struct argv_array prune_worktrees = ARGV_ARRAY_INIT; -static struct argv_array rerere = ARGV_ARRAY_INIT; +static struct strvec pack_refs_cmd = STRVEC_INIT; +static struct strvec reflog = STRVEC_INIT; +static struct strvec repack = STRVEC_INIT; +static struct strvec prune = STRVEC_INIT; +static struct strvec prune_worktrees = STRVEC_INIT; +static struct strvec rerere = STRVEC_INIT; static struct tempfile *pidfile; static struct lock_file log_lock; @@ -311,18 +311,18 @@ static uint64_t estimate_repack_memory(struct packed_git *pack) static int keep_one_pack(struct string_list_item *item, void *data) { - argv_array_pushf(&repack, "--keep-pack=%s", basename(item->string)); + strvec_pushf(&repack, "--keep-pack=%s", basename(item->string)); return 0; } static void add_repack_all_option(struct string_list *keep_pack) { if (prune_expire && !strcmp(prune_expire, "now")) - argv_array_push(&repack, "-a"); + strvec_push(&repack, "-a"); else { - argv_array_push(&repack, "-A"); + strvec_push(&repack, "-A"); if (prune_expire) - argv_array_pushf(&repack, "--unpack-unreachable=%s", prune_expire); + strvec_pushf(&repack, "--unpack-unreachable=%s", prune_expire); } if (keep_pack) @@ -331,7 +331,7 @@ static void add_repack_all_option(struct string_list *keep_pack) static void add_repack_incremental_option(void) { - argv_array_push(&repack, "--no-write-bitmap-index"); + strvec_push(&repack, "--no-write-bitmap-index"); } static int need_to_gc(void) @@ -552,12 +552,12 @@ int cmd_gc(int argc, const char **argv, const char *prefix) if (argc == 2 && !strcmp(argv[1], "-h")) usage_with_options(builtin_gc_usage, builtin_gc_options); - argv_array_pushl(&pack_refs_cmd, "pack-refs", "--all", "--prune", NULL); - argv_array_pushl(&reflog, "reflog", "expire", "--all", NULL); - argv_array_pushl(&repack, "repack", "-d", "-l", NULL); - argv_array_pushl(&prune, "prune", "--expire", NULL); - argv_array_pushl(&prune_worktrees, "worktree", "prune", "--expire", NULL); - argv_array_pushl(&rerere, "rerere", "gc", NULL); + strvec_pushl(&pack_refs_cmd, "pack-refs", "--all", "--prune", NULL); + strvec_pushl(&reflog, "reflog", "expire", "--all", NULL); + strvec_pushl(&repack, "repack", "-d", "-l", NULL); + strvec_pushl(&prune, "prune", "--expire", NULL); + strvec_pushl(&prune_worktrees, "worktree", "prune", "--expire", NULL); + strvec_pushl(&rerere, "rerere", "gc", NULL); /* default expiry time, overwritten in gc_config */ gc_config(); @@ -576,14 +576,14 @@ int cmd_gc(int argc, const char **argv, const char *prefix) die(_("failed to parse prune expiry value %s"), prune_expire); if (aggressive) { - argv_array_push(&repack, "-f"); + strvec_push(&repack, "-f"); if (aggressive_depth > 0) - argv_array_pushf(&repack, "--depth=%d", aggressive_depth); + strvec_pushf(&repack, "--depth=%d", aggressive_depth); if (aggressive_window > 0) - argv_array_pushf(&repack, "--window=%d", aggressive_window); + strvec_pushf(&repack, "--window=%d", aggressive_window); } if (quiet) - argv_array_push(&repack, "-q"); + strvec_push(&repack, "-q"); if (auto_gc) { /* @@ -657,11 +657,11 @@ int cmd_gc(int argc, const char **argv, const char *prefix) die(FAILED_RUN, repack.argv[0]); if (prune_expire) { - argv_array_push(&prune, prune_expire); + strvec_push(&prune, prune_expire); if (quiet) - argv_array_push(&prune, "--no-progress"); + strvec_push(&prune, "--no-progress"); if (has_promisor_remote()) - argv_array_push(&prune, + strvec_push(&prune, "--exclude-promisor-objects"); if (run_command_v_opt(prune.argv, RUN_GIT_CMD)) die(FAILED_RUN, prune.argv[0]); @@ -669,7 +669,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix) } if (prune_worktrees_expire) { - argv_array_push(&prune_worktrees, prune_worktrees_expire); + strvec_push(&prune_worktrees, prune_worktrees_expire); if (run_command_v_opt(prune_worktrees.argv, RUN_GIT_CMD)) die(FAILED_RUN, prune_worktrees.argv[0]); } diff --git a/builtin/grep.c b/builtin/grep.c index a5056f3..2ae77eb 100644 --- a/builtin/grep.c +++ b/builtin/grep.c @@ -397,7 +397,7 @@ static void run_pager(struct grep_opt *opt, const char *prefix) int i, status; for (i = 0; i < path_list->nr; i++) - argv_array_push(&child.args, path_list->items[i].string); + strvec_push(&child.args, path_list->items[i].string); child.dir = prefix; child.use_shell = 1; diff --git a/builtin/log.c b/builtin/log.c index d104d5c..33528fe 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -1128,18 +1128,18 @@ do_pp: static int get_notes_refs(struct string_list_item *item, void *arg) { - argv_array_pushf(arg, "--notes=%s", item->string); + strvec_pushf(arg, "--notes=%s", item->string); return 0; } -static void get_notes_args(struct argv_array *arg, struct rev_info *rev) +static void get_notes_args(struct strvec *arg, struct rev_info *rev) { if (!rev->show_notes) { - argv_array_push(arg, "--no-notes"); + strvec_push(arg, "--no-notes"); } else if (rev->notes_opt.use_default_notes > 0 || (rev->notes_opt.use_default_notes == -1 && !rev->notes_opt.extra_notes_refs.nr)) { - argv_array_push(arg, "--notes"); + strvec_push(arg, "--notes"); } else { for_each_string_list(&rev->notes_opt.extra_notes_refs, get_notes_refs, arg); } @@ -1217,7 +1217,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout, * can be added later if deemed desirable. */ struct diff_options opts; - struct argv_array other_arg = ARGV_ARRAY_INIT; + struct strvec other_arg = STRVEC_INIT; diff_setup(&opts); opts.file = rev->diffopt.file; opts.use_color = rev->diffopt.use_color; @@ -1226,7 +1226,7 @@ static void make_cover_letter(struct rev_info *rev, int use_stdout, get_notes_args(&other_arg, rev); show_range_diff(rev->rdiff1, rev->rdiff2, rev->creation_factor, 1, &opts, &other_arg); - argv_array_clear(&other_arg); + strvec_clear(&other_arg); } } diff --git a/builtin/ls-remote.c b/builtin/ls-remote.c index 3a4dd12..ea91679 100644 --- a/builtin/ls-remote.c +++ b/builtin/ls-remote.c @@ -45,7 +45,7 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix) int show_symref_target = 0; const char *uploadpack = NULL; const char **pattern = NULL; - struct argv_array ref_prefixes = ARGV_ARRAY_INIT; + struct strvec ref_prefixes = STRVEC_INIT; int i; struct string_list server_options = STRING_LIST_INIT_DUP; @@ -92,9 +92,9 @@ int cmd_ls_remote(int argc, const char **argv, const char *prefix) } if (flags & REF_TAGS) - argv_array_push(&ref_prefixes, "refs/tags/"); + strvec_push(&ref_prefixes, "refs/tags/"); if (flags & REF_HEADS) - argv_array_push(&ref_prefixes, "refs/heads/"); + strvec_push(&ref_prefixes, "refs/heads/"); remote = remote_get(dest); if (!remote) { diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 5f18f0e..323f8bc 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -3439,7 +3439,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix) int use_internal_rev_list = 0; int shallow = 0; int all_progress_implied = 0; - struct argv_array rp = ARGV_ARRAY_INIT; + struct strvec rp = STRVEC_INIT; int rev_list_unpacked = 0, rev_list_all = 0, rev_list_reflog = 0; int rev_list_index = 0; struct string_list keep_pack_list = STRING_LIST_INIT_NODUP; @@ -3575,36 +3575,36 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix) cache_max_small_delta_size = (1U << OE_Z_DELTA_BITS) - 1; } - argv_array_push(&rp, "pack-objects"); + strvec_push(&rp, "pack-objects"); if (thin) { use_internal_rev_list = 1; - argv_array_push(&rp, shallow + strvec_push(&rp, shallow ? "--objects-edge-aggressive" : "--objects-edge"); } else - argv_array_push(&rp, "--objects"); + strvec_push(&rp, "--objects"); if (rev_list_all) { use_internal_rev_list = 1; - argv_array_push(&rp, "--all"); + strvec_push(&rp, "--all"); } if (rev_list_reflog) { use_internal_rev_list = 1; - argv_array_push(&rp, "--reflog"); + strvec_push(&rp, "--reflog"); } if (rev_list_index) { use_internal_rev_list = 1; - argv_array_push(&rp, "--indexed-objects"); + strvec_push(&rp, "--indexed-objects"); } if (rev_list_unpacked) { use_internal_rev_list = 1; - argv_array_push(&rp, "--unpacked"); + strvec_push(&rp, "--unpacked"); } if (exclude_promisor_objects) { use_internal_rev_list = 1; fetch_if_missing = 0; - argv_array_push(&rp, "--exclude-promisor-objects"); + strvec_push(&rp, "--exclude-promisor-objects"); } if (unpack_unreachable || keep_unreachable || pack_loose_unreachable) use_internal_rev_list = 1; @@ -3666,7 +3666,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix) write_bitmap_index = 0; if (use_delta_islands) - argv_array_push(&rp, "--topo-order"); + strvec_push(&rp, "--topo-order"); if (progress && all_progress_implied) progress = 2; @@ -3705,7 +3705,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix) read_object_list_from_stdin(); else { get_object_list(rp.argc, rp.argv); - argv_array_clear(&rp); + strvec_clear(&rp); } cleanup_preferred_base(); if (include_tag && nr_result) diff --git a/builtin/pull.c b/builtin/pull.c index 8159c5d..8a8d30e 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -87,8 +87,8 @@ static char *opt_verify_signatures; static int opt_autostash = -1; static int config_autostash; static int check_trust_level = 1; -static struct argv_array opt_strategies = ARGV_ARRAY_INIT; -static struct argv_array opt_strategy_opts = ARGV_ARRAY_INIT; +static struct strvec opt_strategies = STRVEC_INIT; +static struct strvec opt_strategy_opts = STRVEC_INIT; static char *opt_gpg_sign; static int opt_allow_unrelated_histories; @@ -110,7 +110,7 @@ static char *opt_ipv4; static char *opt_ipv6; static int opt_show_forced_updates = -1; static char *set_upstream; -static struct argv_array opt_fetch = ARGV_ARRAY_INIT; +static struct strvec opt_fetch = STRVEC_INIT; static struct option pull_options[] = { /* Shared options */ @@ -251,25 +251,25 @@ static struct option pull_options[] = { /** * Pushes "-q" or "-v" switches into arr to match the opt_verbosity level. */ -static void argv_push_verbosity(struct argv_array *arr) +static void argv_push_verbosity(struct strvec *arr) { int verbosity; for (verbosity = opt_verbosity; verbosity > 0; verbosity--) - argv_array_push(arr, "-v"); + strvec_push(arr, "-v"); for (verbosity = opt_verbosity; verbosity < 0; verbosity++) - argv_array_push(arr, "-q"); + strvec_push(arr, "-q"); } /** * Pushes "-f" switches into arr to match the opt_force level. */ -static void argv_push_force(struct argv_array *arr) +static void argv_push_force(struct strvec *arr) { int force = opt_force; while (force-- > 0) - argv_array_push(arr, "-f"); + strvec_push(arr, "-f"); } /** @@ -524,75 +524,75 @@ static void parse_repo_refspecs(int argc, const char **argv, const char **repo, */ static int run_fetch(const char *repo, const char **refspecs) { - struct argv_array args = ARGV_ARRAY_INIT; + struct strvec args = STRVEC_INIT; int ret; - argv_array_pushl(&args, "fetch", "--update-head-ok", NULL); + strvec_pushl(&args, "fetch", "--update-head-ok", NULL); /* Shared options */ argv_push_verbosity(&args); if (opt_progress) - argv_array_push(&args, opt_progress); + strvec_push(&args, opt_progress); /* Options passed to git-fetch */ if (opt_all) - argv_array_push(&args, opt_all); + strvec_push(&args, opt_all); if (opt_append) - argv_array_push(&args, opt_append); + strvec_push(&args, opt_append); if (opt_upload_pack) - argv_array_push(&args, opt_upload_pack); + strvec_push(&args, opt_upload_pack); argv_push_force(&args); if (opt_tags) - argv_array_push(&args, opt_tags); + strvec_push(&args, opt_tags); if (opt_prune) - argv_array_push(&args, opt_prune); + strvec_push(&args, opt_prune); if (recurse_submodules != RECURSE_SUBMODULES_DEFAULT) switch (recurse_submodules) { case RECURSE_SUBMODULES_ON: - argv_array_push(&args, "--recurse-submodules=on"); + strvec_push(&args, "--recurse-submodules=on"); break; case RECURSE_SUBMODULES_OFF: - argv_array_push(&args, "--recurse-submodules=no"); + strvec_push(&args, "--recurse-submodules=no"); break; case RECURSE_SUBMODULES_ON_DEMAND: - argv_array_push(&args, "--recurse-submodules=on-demand"); + strvec_push(&args, "--recurse-submodules=on-demand"); break; default: BUG("submodule recursion option not understood"); } if (max_children) - argv_array_push(&args, max_children); + strvec_push(&args, max_children); if (opt_dry_run) - argv_array_push(&args, "--dry-run"); + strvec_push(&args, "--dry-run"); if (opt_keep) - argv_array_push(&args, opt_keep); + strvec_push(&args, opt_keep); if (opt_depth) - argv_array_push(&args, opt_depth); + strvec_push(&args, opt_depth); if (opt_unshallow) - argv_array_push(&args, opt_unshallow); + strvec_push(&args, opt_unshallow); if (opt_update_shallow) - argv_array_push(&args, opt_update_shallow); + strvec_push(&args, opt_update_shallow); if (opt_refmap) - argv_array_push(&args, opt_refmap); + strvec_push(&args, opt_refmap); if (opt_ipv4) - argv_array_push(&args, opt_ipv4); + strvec_push(&args, opt_ipv4); if (opt_ipv6) - argv_array_push(&args, opt_ipv6); + strvec_push(&args, opt_ipv6); if (opt_show_forced_updates > 0) - argv_array_push(&args, "--show-forced-updates"); + strvec_push(&args, "--show-forced-updates"); else if (opt_show_forced_updates == 0) - argv_array_push(&args, "--no-show-forced-updates"); + strvec_push(&args, "--no-show-forced-updates"); if (set_upstream) - argv_array_push(&args, set_upstream); - argv_array_pushv(&args, opt_fetch.argv); + strvec_push(&args, set_upstream); + strvec_pushv(&args, opt_fetch.argv); if (repo) { - argv_array_push(&args, repo); - argv_array_pushv(&args, refspecs); + strvec_push(&args, repo); + strvec_pushv(&args, refspecs); } else if (*refspecs) BUG("refspecs without repo?"); ret = run_command_v_opt(args.argv, RUN_GIT_CMD); - argv_array_clear(&args); + strvec_clear(&args); return ret; } @@ -637,7 +637,7 @@ static int rebase_submodules(void) cp.git_cmd = 1; cp.no_stdin = 1; - argv_array_pushl(&cp.args, "submodule", "update", + strvec_pushl(&cp.args, "submodule", "update", "--recursive", "--rebase", NULL); argv_push_verbosity(&cp.args); @@ -650,7 +650,7 @@ static int update_submodules(void) cp.git_cmd = 1; cp.no_stdin = 1; - argv_array_pushl(&cp.args, "submodule", "update", + strvec_pushl(&cp.args, "submodule", "update", "--recursive", "--checkout", NULL); argv_push_verbosity(&cp.args); @@ -663,48 +663,48 @@ static int update_submodules(void) static int run_merge(void) { int ret; - struct argv_array args = ARGV_ARRAY_INIT; + struct strvec args = STRVEC_INIT; - argv_array_pushl(&args, "merge", NULL); + strvec_pushl(&args, "merge", NULL); /* Shared options */ argv_push_verbosity(&args); if (opt_progress) - argv_array_push(&args, opt_progress); + strvec_push(&args, opt_progress); /* Options passed to git-merge */ if (opt_diffstat) - argv_array_push(&args, opt_diffstat); + strvec_push(&args, opt_diffstat); if (opt_log) - argv_array_push(&args, opt_log); + strvec_push(&args, opt_log); if (opt_signoff) - argv_array_push(&args, opt_signoff); + strvec_push(&args, opt_signoff); if (opt_squash) - argv_array_push(&args, opt_squash); + strvec_push(&args, opt_squash); if (opt_commit) - argv_array_push(&args, opt_commit); + strvec_push(&args, opt_commit); if (opt_edit) - argv_array_push(&args, opt_edit); + strvec_push(&args, opt_edit); if (cleanup_arg) - argv_array_pushf(&args, "--cleanup=%s", cleanup_arg); + strvec_pushf(&args, "--cleanup=%s", cleanup_arg); if (opt_ff) - argv_array_push(&args, opt_ff); + strvec_push(&args, opt_ff); if (opt_verify_signatures) - argv_array_push(&args, opt_verify_signatures); - argv_array_pushv(&args, opt_strategies.argv); - argv_array_pushv(&args, opt_strategy_opts.argv); + strvec_push(&args, opt_verify_signatures); + strvec_pushv(&args, opt_strategies.argv); + strvec_pushv(&args, opt_strategy_opts.argv); if (opt_gpg_sign) - argv_array_push(&args, opt_gpg_sign); + strvec_push(&args, opt_gpg_sign); if (opt_autostash == 0) - argv_array_push(&args, "--no-autostash"); + strvec_push(&args, "--no-autostash"); else if (opt_autostash == 1) - argv_array_push(&args, "--autostash"); + strvec_push(&args, "--autostash"); if (opt_allow_unrelated_histories > 0) - argv_array_push(&args, "--allow-unrelated-histories"); + strvec_push(&args, "--allow-unrelated-histories"); - argv_array_push(&args, "FETCH_HEAD"); + strvec_push(&args, "FETCH_HEAD"); ret = run_command_v_opt(args.argv, RUN_GIT_CMD); - argv_array_clear(&args); + strvec_clear(&args); return ret; } @@ -801,7 +801,7 @@ static int get_rebase_fork_point(struct object_id *fork_point, const char *repo, if (!remote_branch) return -1; - argv_array_pushl(&cp.args, "merge-base", "--fork-point", + strvec_pushl(&cp.args, "merge-base", "--fork-point", remote_branch, curr_branch->name, NULL); cp.no_stdin = 1; cp.no_stderr = 1; @@ -862,48 +862,48 @@ static int run_rebase(const struct object_id *curr_head, { int ret; struct object_id oct_merge_base; - struct argv_array args = ARGV_ARRAY_INIT; + struct strvec args = STRVEC_INIT; if (!get_octopus_merge_base(&oct_merge_base, curr_head, merge_head, fork_point)) if (!is_null_oid(fork_point) && oideq(&oct_merge_base, fork_point)) fork_point = NULL; - argv_array_push(&args, "rebase"); + strvec_push(&args, "rebase"); /* Shared options */ argv_push_verbosity(&args); /* Options passed to git-rebase */ if (opt_rebase == REBASE_MERGES) - argv_array_push(&args, "--rebase-merges"); + strvec_push(&args, "--rebase-merges"); else if (opt_rebase == REBASE_PRESERVE) - argv_array_push(&args, "--preserve-merges"); + strvec_push(&args, "--preserve-merges"); else if (opt_rebase == REBASE_INTERACTIVE) - argv_array_push(&args, "--interactive"); + strvec_push(&args, "--interactive"); if (opt_diffstat) - argv_array_push(&args, opt_diffstat); - argv_array_pushv(&args, opt_strategies.argv); - argv_array_pushv(&args, opt_strategy_opts.argv); + strvec_push(&args, opt_diffstat); + strvec_pushv(&args, opt_strategies.argv); + strvec_pushv(&args, opt_strategy_opts.argv); if (opt_gpg_sign) - argv_array_push(&args, opt_gpg_sign); + strvec_push(&args, opt_gpg_sign); if (opt_autostash == 0) - argv_array_push(&args, "--no-autostash"); + strvec_push(&args, "--no-autostash"); else if (opt_autostash == 1) - argv_array_push(&args, "--autostash"); + strvec_push(&args, "--autostash"); if (opt_verify_signatures && !strcmp(opt_verify_signatures, "--verify-signatures")) warning(_("ignoring --verify-signatures for rebase")); - argv_array_push(&args, "--onto"); - argv_array_push(&args, oid_to_hex(merge_head)); + strvec_push(&args, "--onto"); + strvec_push(&args, oid_to_hex(merge_head)); if (fork_point && !is_null_oid(fork_point)) - argv_array_push(&args, oid_to_hex(fork_point)); + strvec_push(&args, oid_to_hex(fork_point)); else - argv_array_push(&args, oid_to_hex(merge_head)); + strvec_push(&args, oid_to_hex(merge_head)); ret = run_command_v_opt(args.argv, RUN_GIT_CMD); - argv_array_clear(&args); + strvec_clear(&args); return ret; } diff --git a/builtin/range-diff.c b/builtin/range-diff.c index d8a4670..24c4162 100644 --- a/builtin/range-diff.c +++ b/builtin/range-diff.c @@ -15,7 +15,7 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix) { int creation_factor = RANGE_DIFF_CREATION_FACTOR_DEFAULT; struct diff_options diffopt = { NULL }; - struct argv_array other_arg = ARGV_ARRAY_INIT; + struct strvec other_arg = STRVEC_INIT; int simple_color = -1; struct option range_diff_options[] = { OPT_INTEGER(0, "creation-factor", &creation_factor, @@ -84,7 +84,7 @@ int cmd_range_diff(int argc, const char **argv, const char *prefix) res = show_range_diff(range1.buf, range2.buf, creation_factor, simple_color < 1, &diffopt, &other_arg); - argv_array_clear(&other_arg); + strvec_clear(&other_arg); strbuf_release(&range1); strbuf_release(&range2); diff --git a/builtin/rebase.c b/builtin/rebase.c index 38145a6..fb56b9e 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -84,7 +84,7 @@ struct rebase_options { REBASE_FORCE = 1<<3, REBASE_INTERACTIVE_EXPLICIT = 1<<4, } flags; - struct argv_array git_am_opts; + struct strvec git_am_opts; const char *action; int signoff; int allow_rerere_autoupdate; @@ -108,7 +108,7 @@ struct rebase_options { .keep_empty = 1, \ .default_backend = "merge", \ .flags = REBASE_NO_QUIET, \ - .git_am_opts = ARGV_ARRAY_INIT, \ + .git_am_opts = STRVEC_INIT, \ .git_format_patch_opt = STRBUF_INIT \ } @@ -323,7 +323,7 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags) int ret; const char *head_hash = NULL; char *revisions = NULL, *shortrevisions = NULL; - struct argv_array make_script_args = ARGV_ARRAY_INIT; + struct strvec make_script_args = STRVEC_INIT; struct todo_list todo_list = TODO_LIST_INIT; struct replay_opts replay = get_replay_opts(opts); struct string_list commands = STRING_LIST_INIT_DUP; @@ -345,9 +345,9 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags) write_file(path_squash_onto(), "%s\n", oid_to_hex(opts->squash_onto)); - argv_array_pushl(&make_script_args, "", revisions, NULL); + strvec_pushl(&make_script_args, "", revisions, NULL); if (opts->restrict_revision) - argv_array_pushf(&make_script_args, "^%s", + strvec_pushf(&make_script_args, "^%s", oid_to_hex(&opts->restrict_revision->object.oid)); ret = sequencer_make_script(the_repository, &todo_list.buf, @@ -372,7 +372,7 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags) free(revisions); free(shortrevisions); todo_list_release(&todo_list); - argv_array_clear(&make_script_args); + strvec_clear(&make_script_args); return ret; } @@ -420,7 +420,7 @@ static int run_sequencer_rebase(struct rebase_options *opts, struct child_process cmd = CHILD_PROCESS_INIT; cmd.git_cmd = 1; - argv_array_pushl(&cmd.args, "show", "REBASE_HEAD", "--", NULL); + strvec_pushl(&cmd.args, "show", "REBASE_HEAD", "--", NULL); ret = run_command(&cmd); break; @@ -811,13 +811,13 @@ static int run_am(struct rebase_options *opts) char *rebased_patches; am.git_cmd = 1; - argv_array_push(&am.args, "am"); + strvec_push(&am.args, "am"); if (opts->action && !strcmp("continue", opts->action)) { - argv_array_push(&am.args, "--resolved"); - argv_array_pushf(&am.args, "--resolvemsg=%s", resolvemsg); + strvec_push(&am.args, "--resolved"); + strvec_pushf(&am.args, "--resolvemsg=%s", resolvemsg); if (opts->gpg_sign_opt) - argv_array_push(&am.args, opts->gpg_sign_opt); + strvec_push(&am.args, opts->gpg_sign_opt); status = run_command(&am); if (status) return status; @@ -825,8 +825,8 @@ static int run_am(struct rebase_options *opts) return move_to_original_branch(opts); } if (opts->action && !strcmp("skip", opts->action)) { - argv_array_push(&am.args, "--skip"); - argv_array_pushf(&am.args, "--resolvemsg=%s", resolvemsg); + strvec_push(&am.args, "--skip"); + strvec_pushf(&am.args, "--resolvemsg=%s", resolvemsg); status = run_command(&am); if (status) return status; @@ -834,7 +834,7 @@ static int run_am(struct rebase_options *opts) return move_to_original_branch(opts); } if (opts->action && !strcmp("show-current-patch", opts->action)) { - argv_array_push(&am.args, "--show-current-patch"); + strvec_push(&am.args, "--show-current-patch"); return run_command(&am); } @@ -852,29 +852,29 @@ static int run_am(struct rebase_options *opts) status = error_errno(_("could not open '%s' for writing"), rebased_patches); free(rebased_patches); - argv_array_clear(&am.args); + strvec_clear(&am.args); return status; } format_patch.git_cmd = 1; - argv_array_pushl(&format_patch.args, "format-patch", "-k", "--stdout", + strvec_pushl(&format_patch.args, "format-patch", "-k", "--stdout", "--full-index", "--cherry-pick", "--right-only", "--src-prefix=a/", "--dst-prefix=b/", "--no-renames", "--no-cover-letter", "--pretty=mboxrd", "--topo-order", "--no-base", NULL); if (opts->git_format_patch_opt.len) - argv_array_split(&format_patch.args, + strvec_split(&format_patch.args, opts->git_format_patch_opt.buf); - argv_array_push(&format_patch.args, revisions.buf); + strvec_push(&format_patch.args, revisions.buf); if (opts->restrict_revision) - argv_array_pushf(&format_patch.args, "^%s", + strvec_pushf(&format_patch.args, "^%s", oid_to_hex(&opts->restrict_revision->object.oid)); status = run_command(&format_patch); if (status) { unlink(rebased_patches); free(rebased_patches); - argv_array_clear(&am.args); + strvec_clear(&am.args); reset_head(the_repository, &opts->orig_head, "checkout", opts->head_name, 0, @@ -896,20 +896,20 @@ static int run_am(struct rebase_options *opts) status = error_errno(_("could not open '%s' for reading"), rebased_patches); free(rebased_patches); - argv_array_clear(&am.args); + strvec_clear(&am.args); return status; } - argv_array_pushv(&am.args, opts->git_am_opts.argv); - argv_array_push(&am.args, "--rebasing"); - argv_array_pushf(&am.args, "--resolvemsg=%s", resolvemsg); - argv_array_push(&am.args, "--patch-format=mboxrd"); + strvec_pushv(&am.args, opts->git_am_opts.argv); + strvec_push(&am.args, "--rebasing"); + strvec_pushf(&am.args, "--resolvemsg=%s", resolvemsg); + strvec_push(&am.args, "--patch-format=mboxrd"); if (opts->allow_rerere_autoupdate == RERERE_AUTOUPDATE) - argv_array_push(&am.args, "--rerere-autoupdate"); + strvec_push(&am.args, "--rerere-autoupdate"); else if (opts->allow_rerere_autoupdate == RERERE_NOAUTOUPDATE) - argv_array_push(&am.args, "--no-rerere-autoupdate"); + strvec_push(&am.args, "--no-rerere-autoupdate"); if (opts->gpg_sign_opt) - argv_array_push(&am.args, opts->gpg_sign_opt); + strvec_push(&am.args, opts->gpg_sign_opt); status = run_command(&am); unlink(rebased_patches); free(rebased_patches); @@ -1649,7 +1649,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) exit(1); if (!(options.flags & REBASE_NO_QUIET)) - argv_array_push(&options.git_am_opts, "-q"); + strvec_push(&options.git_am_opts, "-q"); if (options.empty != EMPTY_UNSPECIFIED) imply_merge(&options, "--empty"); @@ -1776,7 +1776,7 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) if (options.type == REBASE_PRESERVE_MERGES) die("cannot combine '--signoff' with " "'--preserve-merges'"); - argv_array_push(&options.git_am_opts, "--signoff"); + strvec_push(&options.git_am_opts, "--signoff"); options.flags |= REBASE_FORCE; } diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 1285631..7127423 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -667,23 +667,23 @@ static void prepare_push_cert_sha1(struct child_process *proc) nonce_status = check_nonce(push_cert.buf, bogs); } if (!is_null_oid(&push_cert_oid)) { - argv_array_pushf(&proc->env_array, "GIT_PUSH_CERT=%s", + strvec_pushf(&proc->env_array, "GIT_PUSH_CERT=%s", oid_to_hex(&push_cert_oid)); - argv_array_pushf(&proc->env_array, "GIT_PUSH_CERT_SIGNER=%s", + strvec_pushf(&proc->env_array, "GIT_PUSH_CERT_SIGNER=%s", sigcheck.signer ? sigcheck.signer : ""); - argv_array_pushf(&proc->env_array, "GIT_PUSH_CERT_KEY=%s", + strvec_pushf(&proc->env_array, "GIT_PUSH_CERT_KEY=%s", sigcheck.key ? sigcheck.key : ""); - argv_array_pushf(&proc->env_array, "GIT_PUSH_CERT_STATUS=%c", + strvec_pushf(&proc->env_array, "GIT_PUSH_CERT_STATUS=%c", sigcheck.result); if (push_cert_nonce) { - argv_array_pushf(&proc->env_array, + strvec_pushf(&proc->env_array, "GIT_PUSH_CERT_NONCE=%s", push_cert_nonce); - argv_array_pushf(&proc->env_array, + strvec_pushf(&proc->env_array, "GIT_PUSH_CERT_NONCE_STATUS=%s", nonce_status); if (nonce_status == NONCE_SLOP) - argv_array_pushf(&proc->env_array, + strvec_pushf(&proc->env_array, "GIT_PUSH_CERT_NONCE_SLOP=%ld", nonce_stamp_slop); } @@ -720,16 +720,16 @@ static int run_and_feed_hook(const char *hook_name, feed_fn feed, if (feed_state->push_options) { int i; for (i = 0; i < feed_state->push_options->nr; i++) - argv_array_pushf(&proc.env_array, + strvec_pushf(&proc.env_array, "GIT_PUSH_OPTION_%d=%s", i, feed_state->push_options->items[i].string); - argv_array_pushf(&proc.env_array, "GIT_PUSH_OPTION_COUNT=%d", + strvec_pushf(&proc.env_array, "GIT_PUSH_OPTION_COUNT=%d", feed_state->push_options->nr); } else - argv_array_pushf(&proc.env_array, "GIT_PUSH_OPTION_COUNT"); + strvec_pushf(&proc.env_array, "GIT_PUSH_OPTION_COUNT"); if (tmp_objdir) - argv_array_pushv(&proc.env_array, tmp_objdir_env(tmp_objdir)); + strvec_pushv(&proc.env_array, tmp_objdir_env(tmp_objdir)); if (use_sideband) { memset(&muxer, 0, sizeof(muxer)); @@ -931,7 +931,7 @@ static int head_has_history(void) } static const char *push_to_deploy(unsigned char *sha1, - struct argv_array *env, + struct strvec *env, const char *work_tree) { const char *update_refresh[] = { @@ -1000,10 +1000,10 @@ static const char *push_to_deploy(unsigned char *sha1, static const char *push_to_checkout_hook = "push-to-checkout"; static const char *push_to_checkout(unsigned char *hash, - struct argv_array *env, + struct strvec *env, const char *work_tree) { - argv_array_pushf(env, "GIT_WORK_TREE=%s", absolute_path(work_tree)); + strvec_pushf(env, "GIT_WORK_TREE=%s", absolute_path(work_tree)); if (run_hook_le(env->argv, push_to_checkout_hook, hash_to_hex(hash), NULL)) return "push-to-checkout hook declined"; @@ -1014,7 +1014,7 @@ static const char *push_to_checkout(unsigned char *hash, static const char *update_worktree(unsigned char *sha1, const struct worktree *worktree) { const char *retval, *work_tree, *git_dir = NULL; - struct argv_array env = ARGV_ARRAY_INIT; + struct strvec env = STRVEC_INIT; if (worktree && worktree->path) work_tree = worktree->path; @@ -1030,14 +1030,14 @@ static const char *update_worktree(unsigned char *sha1, const struct worktree *w if (!git_dir) git_dir = get_git_dir(); - argv_array_pushf(&env, "GIT_DIR=%s", absolute_path(git_dir)); + strvec_pushf(&env, "GIT_DIR=%s", absolute_path(git_dir)); if (!find_hook(push_to_checkout_hook)) retval = push_to_deploy(sha1, &env, work_tree); else retval = push_to_checkout(sha1, &env, work_tree); - argv_array_clear(&env); + strvec_clear(&env); return retval; } @@ -1206,8 +1206,8 @@ static void run_update_post_hook(struct command *commands) if (cmd->error_string || cmd->did_not_exist) continue; if (!proc.args.argc) - argv_array_push(&proc.args, hook); - argv_array_push(&proc.args, cmd->ref_name); + strvec_push(&proc.args, hook); + strvec_push(&proc.args, cmd->ref_name); } if (!proc.args.argc) return; @@ -1715,9 +1715,9 @@ static const char *parse_pack_header(struct pack_header *hdr) static const char *pack_lockfile; -static void push_header_arg(struct argv_array *args, struct pack_header *hdr) +static void push_header_arg(struct strvec *args, struct pack_header *hdr) { - argv_array_pushf(args, "--pack_header=%"PRIu32",%"PRIu32, + strvec_pushf(args, "--pack_header=%"PRIu32",%"PRIu32, ntohl(hdr->hdr_version), ntohl(hdr->hdr_entries)); } @@ -1742,8 +1742,8 @@ static const char *unpack(int err_fd, struct shallow_info *si) if (si->nr_ours || si->nr_theirs) { alt_shallow_file = setup_temporary_shallow(si->shallow); - argv_array_push(&child.args, "--shallow-file"); - argv_array_push(&child.args, alt_shallow_file); + strvec_push(&child.args, "--shallow-file"); + strvec_push(&child.args, alt_shallow_file); } tmp_objdir = tmp_objdir_create(); @@ -1762,15 +1762,15 @@ static const char *unpack(int err_fd, struct shallow_info *si) tmp_objdir_add_as_alternate(tmp_objdir); if (ntohl(hdr.hdr_entries) < unpack_limit) { - argv_array_push(&child.args, "unpack-objects"); + strvec_push(&child.args, "unpack-objects"); push_header_arg(&child.args, &hdr); if (quiet) - argv_array_push(&child.args, "-q"); + strvec_push(&child.args, "-q"); if (fsck_objects) - argv_array_pushf(&child.args, "--strict%s", + strvec_pushf(&child.args, "--strict%s", fsck_msg_types.buf); if (max_input_size) - argv_array_pushf(&child.args, "--max-input-size=%"PRIuMAX, + strvec_pushf(&child.args, "--max-input-size=%"PRIuMAX, (uintmax_t)max_input_size); child.no_stdout = 1; child.err = err_fd; @@ -1781,27 +1781,27 @@ static const char *unpack(int err_fd, struct shallow_info *si) } else { char hostname[HOST_NAME_MAX + 1]; - argv_array_pushl(&child.args, "index-pack", "--stdin", NULL); + strvec_pushl(&child.args, "index-pack", "--stdin", NULL); push_header_arg(&child.args, &hdr); if (xgethostname(hostname, sizeof(hostname))) xsnprintf(hostname, sizeof(hostname), "localhost"); - argv_array_pushf(&child.args, + strvec_pushf(&child.args, "--keep=receive-pack %"PRIuMAX" on %s", (uintmax_t)getpid(), hostname); if (!quiet && err_fd) - argv_array_push(&child.args, "--show-resolving-progress"); + strvec_push(&child.args, "--show-resolving-progress"); if (use_sideband) - argv_array_push(&child.args, "--report-end-of-input"); + strvec_push(&child.args, "--report-end-of-input"); if (fsck_objects) - argv_array_pushf(&child.args, "--strict%s", + strvec_pushf(&child.args, "--strict%s", fsck_msg_types.buf); if (!reject_thin) - argv_array_push(&child.args, "--fix-thin"); + strvec_push(&child.args, "--fix-thin"); if (max_input_size) - argv_array_pushf(&child.args, "--max-input-size=%"PRIuMAX, + strvec_pushf(&child.args, "--max-input-size=%"PRIuMAX, (uintmax_t)max_input_size); child.out = -1; child.err = err_fd; diff --git a/builtin/remote-ext.c b/builtin/remote-ext.c index 6a9127a..fd3538d 100644 --- a/builtin/remote-ext.c +++ b/builtin/remote-ext.c @@ -117,12 +117,12 @@ static char *strip_escapes(const char *str, const char *service, } } -static void parse_argv(struct argv_array *out, const char *arg, const char *service) +static void parse_argv(struct strvec *out, const char *arg, const char *service) { while (*arg) { char *expanded = strip_escapes(arg, service, &arg); if (expanded) - argv_array_push(out, expanded); + strvec_push(out, expanded); free(expanded); } } diff --git a/builtin/remote.c b/builtin/remote.c index a9f35ba..a3b33c2 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -1451,35 +1451,35 @@ static int update(int argc, const char **argv) N_("prune remotes after fetching")), OPT_END() }; - struct argv_array fetch_argv = ARGV_ARRAY_INIT; + struct strvec fetch_argv = STRVEC_INIT; int default_defined = 0; int retval; argc = parse_options(argc, argv, NULL, options, builtin_remote_update_usage, PARSE_OPT_KEEP_ARGV0); - argv_array_push(&fetch_argv, "fetch"); + strvec_push(&fetch_argv, "fetch"); if (prune != -1) - argv_array_push(&fetch_argv, prune ? "--prune" : "--no-prune"); + strvec_push(&fetch_argv, prune ? "--prune" : "--no-prune"); if (verbose) - argv_array_push(&fetch_argv, "-v"); - argv_array_push(&fetch_argv, "--multiple"); + strvec_push(&fetch_argv, "-v"); + strvec_push(&fetch_argv, "--multiple"); if (argc < 2) - argv_array_push(&fetch_argv, "default"); + strvec_push(&fetch_argv, "default"); for (i = 1; i < argc; i++) - argv_array_push(&fetch_argv, argv[i]); + strvec_push(&fetch_argv, argv[i]); if (strcmp(fetch_argv.argv[fetch_argv.argc-1], "default") == 0) { git_config(get_remote_default, &default_defined); if (!default_defined) { - argv_array_pop(&fetch_argv); - argv_array_push(&fetch_argv, "--all"); + strvec_pop(&fetch_argv); + strvec_push(&fetch_argv, "--all"); } } retval = run_command_v_opt(fetch_argv.argv, RUN_GIT_CMD); - argv_array_clear(&fetch_argv); + strvec_clear(&fetch_argv); return retval; } diff --git a/builtin/repack.c b/builtin/repack.c index 8bccb38..7435ee9 100644 --- a/builtin/repack.c +++ b/builtin/repack.c @@ -153,28 +153,28 @@ struct pack_objects_args { static void prepare_pack_objects(struct child_process *cmd, const struct pack_objects_args *args) { - argv_array_push(&cmd->args, "pack-objects"); + strvec_push(&cmd->args, "pack-objects"); if (args->window) - argv_array_pushf(&cmd->args, "--window=%s", args->window); + strvec_pushf(&cmd->args, "--window=%s", args->window); if (args->window_memory) - argv_array_pushf(&cmd->args, "--window-memory=%s", args->window_memory); + strvec_pushf(&cmd->args, "--window-memory=%s", args->window_memory); if (args->depth) - argv_array_pushf(&cmd->args, "--depth=%s", args->depth); + strvec_pushf(&cmd->args, "--depth=%s", args->depth); if (args->threads) - argv_array_pushf(&cmd->args, "--threads=%s", args->threads); + strvec_pushf(&cmd->args, "--threads=%s", args->threads); if (args->max_pack_size) - argv_array_pushf(&cmd->args, "--max-pack-size=%s", args->max_pack_size); + strvec_pushf(&cmd->args, "--max-pack-size=%s", args->max_pack_size); if (args->no_reuse_delta) - argv_array_pushf(&cmd->args, "--no-reuse-delta"); + strvec_pushf(&cmd->args, "--no-reuse-delta"); if (args->no_reuse_object) - argv_array_pushf(&cmd->args, "--no-reuse-object"); + strvec_pushf(&cmd->args, "--no-reuse-object"); if (args->local) - argv_array_push(&cmd->args, "--local"); + strvec_push(&cmd->args, "--local"); if (args->quiet) - argv_array_push(&cmd->args, "--quiet"); + strvec_push(&cmd->args, "--quiet"); if (delta_base_offset) - argv_array_push(&cmd->args, "--delta-base-offset"); - argv_array_push(&cmd->args, packtmp); + strvec_push(&cmd->args, "--delta-base-offset"); + strvec_push(&cmd->args, packtmp); cmd->git_cmd = 1; cmd->out = -1; } @@ -361,24 +361,24 @@ int cmd_repack(int argc, const char **argv, const char *prefix) prepare_pack_objects(&cmd, &po_args); - argv_array_push(&cmd.args, "--keep-true-parents"); + strvec_push(&cmd.args, "--keep-true-parents"); if (!pack_kept_objects) - argv_array_push(&cmd.args, "--honor-pack-keep"); + strvec_push(&cmd.args, "--honor-pack-keep"); for (i = 0; i < keep_pack_list.nr; i++) - argv_array_pushf(&cmd.args, "--keep-pack=%s", + strvec_pushf(&cmd.args, "--keep-pack=%s", keep_pack_list.items[i].string); - argv_array_push(&cmd.args, "--non-empty"); - argv_array_push(&cmd.args, "--all"); - argv_array_push(&cmd.args, "--reflog"); - argv_array_push(&cmd.args, "--indexed-objects"); + strvec_push(&cmd.args, "--non-empty"); + strvec_push(&cmd.args, "--all"); + strvec_push(&cmd.args, "--reflog"); + strvec_push(&cmd.args, "--indexed-objects"); if (has_promisor_remote()) - argv_array_push(&cmd.args, "--exclude-promisor-objects"); + strvec_push(&cmd.args, "--exclude-promisor-objects"); if (write_bitmaps > 0) - argv_array_push(&cmd.args, "--write-bitmap-index"); + strvec_push(&cmd.args, "--write-bitmap-index"); else if (write_bitmaps < 0) - argv_array_push(&cmd.args, "--write-bitmap-index-quiet"); + strvec_push(&cmd.args, "--write-bitmap-index-quiet"); if (use_delta_islands) - argv_array_push(&cmd.args, "--delta-islands"); + strvec_push(&cmd.args, "--delta-islands"); if (pack_everything & ALL_INTO_ONE) { get_non_kept_pack_filenames(&existing_packs, &keep_pack_list); @@ -387,23 +387,23 @@ int cmd_repack(int argc, const char **argv, const char *prefix) if (existing_packs.nr && delete_redundant) { if (unpack_unreachable) { - argv_array_pushf(&cmd.args, + strvec_pushf(&cmd.args, "--unpack-unreachable=%s", unpack_unreachable); - argv_array_push(&cmd.env_array, "GIT_REF_PARANOIA=1"); + strvec_push(&cmd.env_array, "GIT_REF_PARANOIA=1"); } else if (pack_everything & LOOSEN_UNREACHABLE) { - argv_array_push(&cmd.args, + strvec_push(&cmd.args, "--unpack-unreachable"); } else if (keep_unreachable) { - argv_array_push(&cmd.args, "--keep-unreachable"); - argv_array_push(&cmd.args, "--pack-loose-unreachable"); + strvec_push(&cmd.args, "--keep-unreachable"); + strvec_push(&cmd.args, "--pack-loose-unreachable"); } else { - argv_array_push(&cmd.env_array, "GIT_REF_PARANOIA=1"); + strvec_push(&cmd.env_array, "GIT_REF_PARANOIA=1"); } } } else { - argv_array_push(&cmd.args, "--unpacked"); - argv_array_push(&cmd.args, "--incremental"); + strvec_push(&cmd.args, "--unpacked"); + strvec_push(&cmd.args, "--incremental"); } cmd.no_stdin = 1; diff --git a/builtin/replace.c b/builtin/replace.c index b36d17a..7bc5d66 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -228,13 +228,13 @@ static int export_object(const struct object_id *oid, enum object_type type, if (fd < 0) return error_errno(_("unable to open %s for writing"), filename); - argv_array_push(&cmd.args, "--no-replace-objects"); - argv_array_push(&cmd.args, "cat-file"); + strvec_push(&cmd.args, "--no-replace-objects"); + strvec_push(&cmd.args, "cat-file"); if (raw) - argv_array_push(&cmd.args, type_name(type)); + strvec_push(&cmd.args, type_name(type)); else - argv_array_push(&cmd.args, "-p"); - argv_array_push(&cmd.args, oid_to_hex(oid)); + strvec_push(&cmd.args, "-p"); + strvec_push(&cmd.args, oid_to_hex(oid)); cmd.git_cmd = 1; cmd.out = fd; @@ -502,7 +502,7 @@ static int convert_graft_file(int force) const char *graft_file = get_graft_file(the_repository); FILE *fp = fopen_or_warn(graft_file, "r"); struct strbuf buf = STRBUF_INIT, err = STRBUF_INIT; - struct argv_array args = ARGV_ARRAY_INIT; + struct strvec args = STRVEC_INIT; if (!fp) return -1; @@ -512,10 +512,10 @@ static int convert_graft_file(int force) if (*buf.buf == '#') continue; - argv_array_split(&args, buf.buf); + strvec_split(&args, buf.buf); if (args.argc && create_graft(args.argc, args.argv, force, 1)) strbuf_addf(&err, "\n\t%s", buf.buf); - argv_array_clear(&args); + strvec_clear(&args); } fclose(fp); diff --git a/builtin/show-branch.c b/builtin/show-branch.c index f0a7053..4c918ce 100644 --- a/builtin/show-branch.c +++ b/builtin/show-branch.c @@ -20,7 +20,7 @@ static const char* show_branch_usage[] = { static int showbranch_use_color = -1; -static struct argv_array default_args = ARGV_ARRAY_INIT; +static struct strvec default_args = STRVEC_INIT; /* * TODO: convert this use of commit->object.flags to commit-slab @@ -562,8 +562,8 @@ static int git_show_branch_config(const char *var, const char *value, void *cb) * mimic the real argv a bit better. */ if (!default_args.argc) - argv_array_push(&default_args, "show-branch"); - argv_array_push(&default_args, value); + strvec_push(&default_args, "show-branch"); + strvec_push(&default_args, value); return 0; } diff --git a/builtin/stash.c b/builtin/stash.c index 1acf216..05c086e 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -277,8 +277,8 @@ static int diff_tree_binary(struct strbuf *out, struct object_id *w_commit) * however it should be done together with apply_cached. */ cp.git_cmd = 1; - argv_array_pushl(&cp.args, "diff-tree", "--binary", NULL); - argv_array_pushf(&cp.args, "%s^2^..%s^2", w_commit_hex, w_commit_hex); + strvec_pushl(&cp.args, "diff-tree", "--binary", NULL); + strvec_pushf(&cp.args, "%s^2^..%s^2", w_commit_hex, w_commit_hex); return pipe_command(&cp, NULL, 0, out, 0, NULL, 0); } @@ -293,7 +293,7 @@ static int apply_cached(struct strbuf *out) * buffer. */ cp.git_cmd = 1; - argv_array_pushl(&cp.args, "apply", "--cached", NULL); + strvec_pushl(&cp.args, "apply", "--cached", NULL); return pipe_command(&cp, out->buf, out->len, NULL, 0, NULL, 0); } @@ -306,7 +306,7 @@ static int reset_head(void) * API for resetting. */ cp.git_cmd = 1; - argv_array_push(&cp.args, "reset"); + strvec_push(&cp.args, "reset"); return run_command(&cp); } @@ -335,9 +335,9 @@ static int get_newly_staged(struct strbuf *out, struct object_id *c_tree) * converted together with update_index. */ cp.git_cmd = 1; - argv_array_pushl(&cp.args, "diff-index", "--cached", "--name-only", + strvec_pushl(&cp.args, "diff-index", "--cached", "--name-only", "--diff-filter=A", NULL); - argv_array_push(&cp.args, c_tree_hex); + strvec_push(&cp.args, c_tree_hex); return pipe_command(&cp, NULL, 0, out, 0, NULL, 0); } @@ -350,7 +350,7 @@ static int update_index(struct strbuf *out) * function exposed in order to remove this forking. */ cp.git_cmd = 1; - argv_array_pushl(&cp.args, "update-index", "--add", "--stdin", NULL); + strvec_pushl(&cp.args, "update-index", "--add", "--stdin", NULL); return pipe_command(&cp, out->buf, out->len, NULL, 0, NULL, 0); } @@ -365,9 +365,9 @@ static int restore_untracked(struct object_id *u_tree) * run_command to fork processes that will not interfere. */ cp.git_cmd = 1; - argv_array_push(&cp.args, "read-tree"); - argv_array_push(&cp.args, oid_to_hex(u_tree)); - argv_array_pushf(&cp.env_array, "GIT_INDEX_FILE=%s", + strvec_push(&cp.args, "read-tree"); + strvec_push(&cp.args, oid_to_hex(u_tree)); + strvec_pushf(&cp.env_array, "GIT_INDEX_FILE=%s", stash_index_path.buf); if (run_command(&cp)) { remove_path(stash_index_path.buf); @@ -376,8 +376,8 @@ static int restore_untracked(struct object_id *u_tree) child_process_init(&cp); cp.git_cmd = 1; - argv_array_pushl(&cp.args, "checkout-index", "--all", NULL); - argv_array_pushf(&cp.env_array, "GIT_INDEX_FILE=%s", + strvec_pushl(&cp.args, "checkout-index", "--all", NULL); + strvec_pushf(&cp.env_array, "GIT_INDEX_FILE=%s", stash_index_path.buf); res = run_command(&cp); @@ -499,11 +499,11 @@ static int do_apply_stash(const char *prefix, struct stash_info *info, */ cp.git_cmd = 1; cp.dir = prefix; - argv_array_pushf(&cp.env_array, GIT_WORK_TREE_ENVIRONMENT"=%s", + strvec_pushf(&cp.env_array, GIT_WORK_TREE_ENVIRONMENT"=%s", absolute_path(get_git_work_tree())); - argv_array_pushf(&cp.env_array, GIT_DIR_ENVIRONMENT"=%s", + strvec_pushf(&cp.env_array, GIT_DIR_ENVIRONMENT"=%s", absolute_path(get_git_dir())); - argv_array_push(&cp.args, "status"); + strvec_push(&cp.args, "status"); run_command(&cp); } @@ -546,9 +546,9 @@ static int do_drop_stash(struct stash_info *info, int quiet) */ cp_reflog.git_cmd = 1; - argv_array_pushl(&cp_reflog.args, "reflog", "delete", "--updateref", + strvec_pushl(&cp_reflog.args, "reflog", "delete", "--updateref", "--rewrite", NULL); - argv_array_push(&cp_reflog.args, info->revision.buf); + strvec_push(&cp_reflog.args, info->revision.buf); ret = run_command(&cp_reflog); if (!ret) { if (!quiet) @@ -566,8 +566,8 @@ static int do_drop_stash(struct stash_info *info, int quiet) cp.git_cmd = 1; /* Even though --quiet is specified, rev-parse still outputs the hash */ cp.no_stdout = 1; - argv_array_pushl(&cp.args, "rev-parse", "--verify", "--quiet", NULL); - argv_array_pushf(&cp.args, "%s@{0}", ref_stash); + strvec_pushl(&cp.args, "rev-parse", "--verify", "--quiet", NULL); + strvec_pushf(&cp.args, "%s@{0}", ref_stash); ret = run_command(&cp); /* do_clear_stash if we just dropped the last stash entry */ @@ -663,9 +663,9 @@ static int branch_stash(int argc, const char **argv, const char *prefix) return -1; cp.git_cmd = 1; - argv_array_pushl(&cp.args, "checkout", "-b", NULL); - argv_array_push(&cp.args, branch); - argv_array_push(&cp.args, oid_to_hex(&info.b_commit)); + strvec_pushl(&cp.args, "checkout", "-b", NULL); + strvec_push(&cp.args, branch); + strvec_push(&cp.args, oid_to_hex(&info.b_commit)); ret = run_command(&cp); if (!ret) ret = do_apply_stash(prefix, &info, 1, 0); @@ -692,11 +692,11 @@ static int list_stash(int argc, const char **argv, const char *prefix) return 0; cp.git_cmd = 1; - argv_array_pushl(&cp.args, "log", "--format=%gd: %gs", "-g", + strvec_pushl(&cp.args, "log", "--format=%gd: %gs", "-g", "--first-parent", "-m", NULL); - argv_array_pushv(&cp.args, argv); - argv_array_push(&cp.args, ref_stash); - argv_array_push(&cp.args, "--"); + strvec_pushv(&cp.args, argv); + strvec_push(&cp.args, ref_stash); + strvec_push(&cp.args, "--"); return run_command(&cp); } @@ -727,8 +727,8 @@ static int show_stash(int argc, const char **argv, const char *prefix) int ret = 0; struct stash_info info; struct rev_info rev; - struct argv_array stash_args = ARGV_ARRAY_INIT; - struct argv_array revision_args = ARGV_ARRAY_INIT; + struct strvec stash_args = STRVEC_INIT; + struct strvec revision_args = STRVEC_INIT; struct option options[] = { OPT_END() }; @@ -737,16 +737,16 @@ static int show_stash(int argc, const char **argv, const char *prefix) git_config(git_diff_ui_config, NULL); init_revisions(&rev, prefix); - argv_array_push(&revision_args, argv[0]); + strvec_push(&revision_args, argv[0]); for (i = 1; i < argc; i++) { if (argv[i][0] != '-') - argv_array_push(&stash_args, argv[i]); + strvec_push(&stash_args, argv[i]); else - argv_array_push(&revision_args, argv[i]); + strvec_push(&revision_args, argv[i]); } ret = get_stash_info(&info, stash_args.argc, stash_args.argv); - argv_array_clear(&stash_args); + strvec_clear(&stash_args); if (ret) return -1; @@ -842,12 +842,12 @@ static int store_stash(int argc, const char **argv, const char *prefix) return do_store_stash(&obj, stash_msg, quiet); } -static void add_pathspecs(struct argv_array *args, +static void add_pathspecs(struct strvec *args, const struct pathspec *ps) { int i; for (i = 0; i < ps->nr; i++) - argv_array_push(args, ps->items[i].original); + strvec_push(args, ps->items[i].original); } /* @@ -960,9 +960,9 @@ static int save_untracked_files(struct stash_info *info, struct strbuf *msg, struct index_state istate = { NULL }; cp_upd_index.git_cmd = 1; - argv_array_pushl(&cp_upd_index.args, "update-index", "-z", "--add", + strvec_pushl(&cp_upd_index.args, "update-index", "-z", "--add", "--remove", "--stdin", NULL); - argv_array_pushf(&cp_upd_index.env_array, "GIT_INDEX_FILE=%s", + strvec_pushf(&cp_upd_index.env_array, "GIT_INDEX_FILE=%s", stash_index_path.buf); strbuf_addf(&untracked_msg, "untracked files on %s\n", msg->buf); @@ -1003,8 +1003,8 @@ static int stash_patch(struct stash_info *info, const struct pathspec *ps, remove_path(stash_index_path.buf); cp_read_tree.git_cmd = 1; - argv_array_pushl(&cp_read_tree.args, "read-tree", "HEAD", NULL); - argv_array_pushf(&cp_read_tree.env_array, "GIT_INDEX_FILE=%s", + strvec_pushl(&cp_read_tree.args, "read-tree", "HEAD", NULL); + strvec_pushf(&cp_read_tree.env_array, "GIT_INDEX_FILE=%s", stash_index_path.buf); if (run_command(&cp_read_tree)) { ret = -1; @@ -1034,7 +1034,7 @@ static int stash_patch(struct stash_info *info, const struct pathspec *ps, } cp_diff_tree.git_cmd = 1; - argv_array_pushl(&cp_diff_tree.args, "diff-tree", "-p", "-U1", "HEAD", + strvec_pushl(&cp_diff_tree.args, "diff-tree", "-p", "-U1", "HEAD", oid_to_hex(&info->w_tree), "--", NULL); if (pipe_command(&cp_diff_tree, NULL, 0, out_patch, 0, NULL, 0)) { ret = -1; @@ -1088,10 +1088,10 @@ static int stash_working_tree(struct stash_info *info, const struct pathspec *ps } cp_upd_index.git_cmd = 1; - argv_array_pushl(&cp_upd_index.args, "update-index", + strvec_pushl(&cp_upd_index.args, "update-index", "--ignore-skip-worktree-entries", "-z", "--add", "--remove", "--stdin", NULL); - argv_array_pushf(&cp_upd_index.env_array, "GIT_INDEX_FILE=%s", + strvec_pushf(&cp_upd_index.env_array, "GIT_INDEX_FILE=%s", stash_index_path.buf); if (pipe_command(&cp_upd_index, diff_output.buf, diff_output.len, @@ -1342,10 +1342,10 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q struct child_process cp = CHILD_PROCESS_INIT; cp.git_cmd = 1; - argv_array_pushl(&cp.args, "clean", "--force", + strvec_pushl(&cp.args, "clean", "--force", "--quiet", "-d", NULL); if (include_untracked == INCLUDE_ALL_FILES) - argv_array_push(&cp.args, "-x"); + strvec_push(&cp.args, "-x"); if (run_command(&cp)) { ret = -1; goto done; @@ -1359,12 +1359,12 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q struct strbuf out = STRBUF_INIT; cp_add.git_cmd = 1; - argv_array_push(&cp_add.args, "add"); + strvec_push(&cp_add.args, "add"); if (!include_untracked) - argv_array_push(&cp_add.args, "-u"); + strvec_push(&cp_add.args, "-u"); if (include_untracked == INCLUDE_ALL_FILES) - argv_array_push(&cp_add.args, "--force"); - argv_array_push(&cp_add.args, "--"); + strvec_push(&cp_add.args, "--force"); + strvec_push(&cp_add.args, "--"); add_pathspecs(&cp_add.args, ps); if (run_command(&cp_add)) { ret = -1; @@ -1372,7 +1372,7 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q } cp_diff.git_cmd = 1; - argv_array_pushl(&cp_diff.args, "diff-index", "-p", + strvec_pushl(&cp_diff.args, "diff-index", "-p", "--cached", "--binary", "HEAD", "--", NULL); add_pathspecs(&cp_diff.args, ps); @@ -1382,7 +1382,7 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q } cp_apply.git_cmd = 1; - argv_array_pushl(&cp_apply.args, "apply", "--index", + strvec_pushl(&cp_apply.args, "apply", "--index", "-R", NULL); if (pipe_command(&cp_apply, out.buf, out.len, NULL, 0, NULL, 0)) { @@ -1392,7 +1392,7 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q } else { struct child_process cp = CHILD_PROCESS_INIT; cp.git_cmd = 1; - argv_array_pushl(&cp.args, "reset", "--hard", "-q", + strvec_pushl(&cp.args, "reset", "--hard", "-q", "--no-recurse-submodules", NULL); if (run_command(&cp)) { ret = -1; @@ -1404,10 +1404,10 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q struct child_process cp = CHILD_PROCESS_INIT; cp.git_cmd = 1; - argv_array_pushl(&cp.args, "checkout", "--no-overlay", + strvec_pushl(&cp.args, "checkout", "--no-overlay", oid_to_hex(&info.i_tree), "--", NULL); if (!ps->nr) - argv_array_push(&cp.args, ":/"); + strvec_push(&cp.args, ":/"); else add_pathspecs(&cp.args, ps); if (run_command(&cp)) { @@ -1420,7 +1420,7 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q struct child_process cp = CHILD_PROCESS_INIT; cp.git_cmd = 1; - argv_array_pushl(&cp.args, "apply", "-R", NULL); + strvec_pushl(&cp.args, "apply", "-R", NULL); if (pipe_command(&cp, patch.buf, patch.len, NULL, 0, NULL, 0)) { if (!quiet) @@ -1434,7 +1434,7 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q struct child_process cp = CHILD_PROCESS_INIT; cp.git_cmd = 1; - argv_array_pushl(&cp.args, "reset", "-q", "--", NULL); + strvec_pushl(&cp.args, "reset", "-q", "--", NULL); add_pathspecs(&cp.args, ps); if (run_command(&cp)) { ret = -1; @@ -1560,7 +1560,7 @@ int cmd_stash(int argc, const char **argv, const char *prefix) { pid_t pid = getpid(); const char *index_file; - struct argv_array args = ARGV_ARRAY_INIT; + struct strvec args = STRVEC_INIT; struct option options[] = { OPT_END() @@ -1609,7 +1609,7 @@ int cmd_stash(int argc, const char **argv, const char *prefix) git_stash_usage, options); /* Assume 'stash push' */ - argv_array_push(&args, "push"); - argv_array_pushv(&args, argv); + strvec_push(&args, "push"); + strvec_pushv(&args, argv); return !!push_stash(args.argc, args.argv, prefix, 1); } diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index a1c7560..7705e8e 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -294,9 +294,9 @@ static char *compute_rev_name(const char *sub_path, const char* object_id) cp.git_cmd = 1; cp.no_stderr = 1; - argv_array_push(&cp.args, "describe"); - argv_array_pushv(&cp.args, *d); - argv_array_push(&cp.args, object_id); + strvec_push(&cp.args, "describe"); + strvec_pushv(&cp.args, *d); + strvec_push(&cp.args, object_id); if (!capture_command(&cp, &sb, 0)) { strbuf_strip_suffix(&sb, "\n"); @@ -495,12 +495,12 @@ static void runcommand_in_submodule_cb(const struct cache_entry *list_item, char *toplevel = xgetcwd(); struct strbuf sb = STRBUF_INIT; - argv_array_pushf(&cp.env_array, "name=%s", sub->name); - argv_array_pushf(&cp.env_array, "sm_path=%s", path); - argv_array_pushf(&cp.env_array, "displaypath=%s", displaypath); - argv_array_pushf(&cp.env_array, "sha1=%s", + strvec_pushf(&cp.env_array, "name=%s", sub->name); + strvec_pushf(&cp.env_array, "sm_path=%s", path); + strvec_pushf(&cp.env_array, "displaypath=%s", displaypath); + strvec_pushf(&cp.env_array, "sha1=%s", oid_to_hex(ce_oid)); - argv_array_pushf(&cp.env_array, "toplevel=%s", toplevel); + strvec_pushf(&cp.env_array, "toplevel=%s", toplevel); /* * Since the path variable was accessible from the script @@ -509,15 +509,15 @@ static void runcommand_in_submodule_cb(const struct cache_entry *list_item, * on windows. And since environment variables are * case-insensitive in windows, it interferes with the * existing PATH variable. Hence, to avoid that, we expose - * path via the args argv_array and not via env_array. + * path via the args strvec and not via env_array. */ sq_quote_buf(&sb, path); - argv_array_pushf(&cp.args, "path=%s; %s", + strvec_pushf(&cp.args, "path=%s; %s", sb.buf, info->argv[0]); strbuf_release(&sb); free(toplevel); } else { - argv_array_pushv(&cp.args, info->argv); + strvec_pushv(&cp.args, info->argv); } if (!info->quiet) @@ -534,16 +534,16 @@ static void runcommand_in_submodule_cb(const struct cache_entry *list_item, cpr.dir = path; prepare_submodule_repo_env(&cpr.env_array); - argv_array_pushl(&cpr.args, "--super-prefix", NULL); - argv_array_pushf(&cpr.args, "%s/", displaypath); - argv_array_pushl(&cpr.args, "submodule--helper", "foreach", "--recursive", + strvec_pushl(&cpr.args, "--super-prefix", NULL); + strvec_pushf(&cpr.args, "%s/", displaypath); + strvec_pushl(&cpr.args, "submodule--helper", "foreach", "--recursive", NULL); if (info->quiet) - argv_array_push(&cpr.args, "--quiet"); + strvec_push(&cpr.args, "--quiet"); - argv_array_push(&cpr.args, "--"); - argv_array_pushv(&cpr.args, info->argv); + strvec_push(&cpr.args, "--"); + strvec_pushv(&cpr.args, info->argv); if (run_command(&cpr)) die(_("run_command returned non-zero status while " @@ -779,7 +779,7 @@ static void status_submodule(const char *path, const struct object_id *ce_oid, unsigned int flags) { char *displaypath; - struct argv_array diff_files_args = ARGV_ARRAY_INIT; + struct strvec diff_files_args = STRVEC_INIT; struct rev_info rev; int diff_files_result; struct strbuf buf = STRBUF_INIT; @@ -809,7 +809,7 @@ static void status_submodule(const char *path, const struct object_id *ce_oid, } strbuf_release(&buf); - argv_array_pushl(&diff_files_args, "diff-files", + strvec_pushl(&diff_files_args, "diff-files", "--ignore-submodules=dirty", "--quiet", "--", path, NULL); @@ -849,23 +849,23 @@ static void status_submodule(const char *path, const struct object_id *ce_oid, cpr.dir = path; prepare_submodule_repo_env(&cpr.env_array); - argv_array_push(&cpr.args, "--super-prefix"); - argv_array_pushf(&cpr.args, "%s/", displaypath); - argv_array_pushl(&cpr.args, "submodule--helper", "status", + strvec_push(&cpr.args, "--super-prefix"); + strvec_pushf(&cpr.args, "%s/", displaypath); + strvec_pushl(&cpr.args, "submodule--helper", "status", "--recursive", NULL); if (flags & OPT_CACHED) - argv_array_push(&cpr.args, "--cached"); + strvec_push(&cpr.args, "--cached"); if (flags & OPT_QUIET) - argv_array_push(&cpr.args, "--quiet"); + strvec_push(&cpr.args, "--quiet"); if (run_command(&cpr)) die(_("failed to recurse into submodule '%s'"), path); } cleanup: - argv_array_clear(&diff_files_args); + strvec_clear(&diff_files_args); free(displaypath); } @@ -995,7 +995,7 @@ static void sync_submodule(const char *path, const char *prefix, prepare_submodule_repo_env(&cp.env_array); cp.git_cmd = 1; cp.dir = path; - argv_array_pushl(&cp.args, "submodule--helper", + strvec_pushl(&cp.args, "submodule--helper", "print-default-remote", NULL); strbuf_reset(&sb); @@ -1021,13 +1021,13 @@ static void sync_submodule(const char *path, const char *prefix, cpr.dir = path; prepare_submodule_repo_env(&cpr.env_array); - argv_array_push(&cpr.args, "--super-prefix"); - argv_array_pushf(&cpr.args, "%s/", displaypath); - argv_array_pushl(&cpr.args, "submodule--helper", "sync", + strvec_push(&cpr.args, "--super-prefix"); + strvec_pushf(&cpr.args, "%s/", displaypath); + strvec_pushl(&cpr.args, "submodule--helper", "sync", "--recursive", NULL); if (flags & OPT_QUIET) - argv_array_push(&cpr.args, "--quiet"); + strvec_push(&cpr.args, "--quiet"); if (run_command(&cpr)) die(_("failed to recurse into submodule '%s'"), @@ -1127,7 +1127,7 @@ static void deinit_submodule(const char *path, const char *prefix, if (!(flags & OPT_FORCE)) { struct child_process cp_rm = CHILD_PROCESS_INIT; cp_rm.git_cmd = 1; - argv_array_pushl(&cp_rm.args, "rm", "-qn", + strvec_pushl(&cp_rm.args, "rm", "-qn", path, NULL); if (run_command(&cp_rm)) @@ -1156,8 +1156,8 @@ static void deinit_submodule(const char *path, const char *prefix, displaypath); cp_config.git_cmd = 1; - argv_array_pushl(&cp_config.args, "config", "--get-regexp", NULL); - argv_array_pushf(&cp_config.args, "submodule.%s\\.", sub->name); + strvec_pushl(&cp_config.args, "config", "--get-regexp", NULL); + strvec_pushf(&cp_config.args, "submodule.%s\\.", sub->name); /* remove the .git/config entries (unless the user already did it) */ if (!capture_command(&cp_config, &sb_config, 0) && sb_config.len) { @@ -1239,32 +1239,32 @@ static int clone_submodule(const char *path, const char *gitdir, const char *url { struct child_process cp = CHILD_PROCESS_INIT; - argv_array_push(&cp.args, "clone"); - argv_array_push(&cp.args, "--no-checkout"); + strvec_push(&cp.args, "clone"); + strvec_push(&cp.args, "--no-checkout"); if (quiet) - argv_array_push(&cp.args, "--quiet"); + strvec_push(&cp.args, "--quiet"); if (progress) - argv_array_push(&cp.args, "--progress"); + strvec_push(&cp.args, "--progress"); if (depth && *depth) - argv_array_pushl(&cp.args, "--depth", depth, NULL); + strvec_pushl(&cp.args, "--depth", depth, NULL); if (reference->nr) { struct string_list_item *item; for_each_string_list_item(item, reference) - argv_array_pushl(&cp.args, "--reference", + strvec_pushl(&cp.args, "--reference", item->string, NULL); } if (dissociate) - argv_array_push(&cp.args, "--dissociate"); + strvec_push(&cp.args, "--dissociate"); if (gitdir && *gitdir) - argv_array_pushl(&cp.args, "--separate-git-dir", gitdir, NULL); + strvec_pushl(&cp.args, "--separate-git-dir", gitdir, NULL); if (single_branch >= 0) - argv_array_push(&cp.args, single_branch ? + strvec_push(&cp.args, single_branch ? "--single-branch" : "--no-single-branch"); - argv_array_push(&cp.args, "--"); - argv_array_push(&cp.args, url); - argv_array_push(&cp.args, path); + strvec_push(&cp.args, "--"); + strvec_push(&cp.args, url); + strvec_push(&cp.args, path); cp.git_cmd = 1; prepare_submodule_repo_env(&cp.env_array); @@ -1717,32 +1717,32 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce, child->no_stdin = 1; child->stdout_to_stderr = 1; child->err = -1; - argv_array_push(&child->args, "submodule--helper"); - argv_array_push(&child->args, "clone"); + strvec_push(&child->args, "submodule--helper"); + strvec_push(&child->args, "clone"); if (suc->progress) - argv_array_push(&child->args, "--progress"); + strvec_push(&child->args, "--progress"); if (suc->quiet) - argv_array_push(&child->args, "--quiet"); + strvec_push(&child->args, "--quiet"); if (suc->prefix) - argv_array_pushl(&child->args, "--prefix", suc->prefix, NULL); + strvec_pushl(&child->args, "--prefix", suc->prefix, NULL); if (suc->recommend_shallow && sub->recommend_shallow == 1) - argv_array_push(&child->args, "--depth=1"); + strvec_push(&child->args, "--depth=1"); if (suc->require_init) - argv_array_push(&child->args, "--require-init"); - argv_array_pushl(&child->args, "--path", sub->path, NULL); - argv_array_pushl(&child->args, "--name", sub->name, NULL); - argv_array_pushl(&child->args, "--url", url, NULL); + strvec_push(&child->args, "--require-init"); + strvec_pushl(&child->args, "--path", sub->path, NULL); + strvec_pushl(&child->args, "--name", sub->name, NULL); + strvec_pushl(&child->args, "--url", url, NULL); if (suc->references.nr) { struct string_list_item *item; for_each_string_list_item(item, &suc->references) - argv_array_pushl(&child->args, "--reference", item->string, NULL); + strvec_pushl(&child->args, "--reference", item->string, NULL); } if (suc->dissociate) - argv_array_push(&child->args, "--dissociate"); + strvec_push(&child->args, "--dissociate"); if (suc->depth) - argv_array_push(&child->args, suc->depth); + strvec_push(&child->args, suc->depth); if (suc->single_branch >= 0) - argv_array_push(&child->args, suc->single_branch ? + strvec_push(&child->args, suc->single_branch ? "--single-branch" : "--no-single-branch"); diff --git a/builtin/upload-archive.c b/builtin/upload-archive.c index 7fc8e0e..f02bb0e 100644 --- a/builtin/upload-archive.c +++ b/builtin/upload-archive.c @@ -19,7 +19,7 @@ static const char deadchild[] = int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix) { - struct argv_array sent_argv = ARGV_ARRAY_INIT; + struct strvec sent_argv = STRVEC_INIT; const char *arg_cmd = "argument "; if (argc != 2 || !strcmp(argv[1], "-h")) @@ -31,7 +31,7 @@ int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix) init_archivers(); /* put received options in sent_argv[] */ - argv_array_push(&sent_argv, "git-upload-archive"); + strvec_push(&sent_argv, "git-upload-archive"); for (;;) { char *buf = packet_read_line(0, NULL); if (!buf) @@ -41,7 +41,7 @@ int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix) if (!starts_with(buf, arg_cmd)) die("'argument' token or flush expected"); - argv_array_push(&sent_argv, buf + strlen(arg_cmd)); + strvec_push(&sent_argv, buf + strlen(arg_cmd)); } /* parse all options sent by the client */ diff --git a/builtin/worktree.c b/builtin/worktree.c index 3594509..3c483c2 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -316,7 +316,7 @@ static int add_worktree(const char *path, const char *refname, struct strbuf sb = STRBUF_INIT, realpath = STRBUF_INIT; const char *name; struct child_process cp = CHILD_PROCESS_INIT; - struct argv_array child_env = ARGV_ARRAY_INIT; + struct strvec child_env = STRVEC_INIT; unsigned int counter = 0; int len, ret; struct strbuf symref = STRBUF_INIT; @@ -408,18 +408,18 @@ static int add_worktree(const char *path, const char *refname, strbuf_addf(&sb, "%s/commondir", sb_repo.buf); write_file(sb.buf, "../.."); - argv_array_pushf(&child_env, "%s=%s", GIT_DIR_ENVIRONMENT, sb_git.buf); - argv_array_pushf(&child_env, "%s=%s", GIT_WORK_TREE_ENVIRONMENT, path); + strvec_pushf(&child_env, "%s=%s", GIT_DIR_ENVIRONMENT, sb_git.buf); + strvec_pushf(&child_env, "%s=%s", GIT_WORK_TREE_ENVIRONMENT, path); cp.git_cmd = 1; if (!is_branch) - argv_array_pushl(&cp.args, "update-ref", "HEAD", + strvec_pushl(&cp.args, "update-ref", "HEAD", oid_to_hex(&commit->object.oid), NULL); else { - argv_array_pushl(&cp.args, "symbolic-ref", "HEAD", + strvec_pushl(&cp.args, "symbolic-ref", "HEAD", symref.buf, NULL); if (opts->quiet) - argv_array_push(&cp.args, "--quiet"); + strvec_push(&cp.args, "--quiet"); } cp.env = child_env.argv; @@ -429,10 +429,10 @@ static int add_worktree(const char *path, const char *refname, if (opts->checkout) { cp.argv = NULL; - argv_array_clear(&cp.args); - argv_array_pushl(&cp.args, "reset", "--hard", "--no-recurse-submodules", NULL); + strvec_clear(&cp.args); + strvec_pushl(&cp.args, "reset", "--hard", "--no-recurse-submodules", NULL); if (opts->quiet) - argv_array_push(&cp.args, "--quiet"); + strvec_push(&cp.args, "--quiet"); cp.env = child_env.argv; ret = run_command(&cp); if (ret) @@ -465,7 +465,7 @@ done: cp.env = env; cp.argv = NULL; cp.trace2_hook_name = "post-checkout"; - argv_array_pushl(&cp.args, absolute_path(hook), + strvec_pushl(&cp.args, absolute_path(hook), oid_to_hex(&null_oid), oid_to_hex(&commit->object.oid), "1", NULL); @@ -473,7 +473,7 @@ done: } } - argv_array_clear(&child_env); + strvec_clear(&child_env); strbuf_release(&sb); strbuf_release(&symref); strbuf_release(&sb_repo); @@ -619,15 +619,15 @@ static int add(int ac, const char **av, const char *prefix) if (new_branch) { struct child_process cp = CHILD_PROCESS_INIT; cp.git_cmd = 1; - argv_array_push(&cp.args, "branch"); + strvec_push(&cp.args, "branch"); if (new_branch_force) - argv_array_push(&cp.args, "--force"); + strvec_push(&cp.args, "--force"); if (opts.quiet) - argv_array_push(&cp.args, "--quiet"); - argv_array_push(&cp.args, new_branch); - argv_array_push(&cp.args, branch); + strvec_push(&cp.args, "--quiet"); + strvec_push(&cp.args, new_branch); + strvec_push(&cp.args, branch); if (opt_track) - argv_array_push(&cp.args, opt_track); + strvec_push(&cp.args, opt_track); if (run_command(&cp)) return -1; branch = new_branch; @@ -924,7 +924,7 @@ static int move_worktree(int ac, const char **av, const char *prefix) static void check_clean_worktree(struct worktree *wt, const char *original_path) { - struct argv_array child_env = ARGV_ARRAY_INIT; + struct strvec child_env = STRVEC_INIT; struct child_process cp; char buf[1]; int ret; @@ -935,12 +935,12 @@ static void check_clean_worktree(struct worktree *wt, */ validate_no_submodules(wt); - argv_array_pushf(&child_env, "%s=%s/.git", + strvec_pushf(&child_env, "%s=%s/.git", GIT_DIR_ENVIRONMENT, wt->path); - argv_array_pushf(&child_env, "%s=%s", + strvec_pushf(&child_env, "%s=%s", GIT_WORK_TREE_ENVIRONMENT, wt->path); memset(&cp, 0, sizeof(cp)); - argv_array_pushl(&cp.args, "status", + strvec_pushl(&cp.args, "status", "--porcelain", "--ignore-submodules=none", NULL); cp.env = child_env.argv; -- cgit v0.10.2-6-g49f6 From ef8d7ac42a6a62d678166fe25ea743315809d2bb Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 28 Jul 2020 16:24:53 -0400 Subject: strvec: convert more callers away from argv_array name We eventually want to drop the argv_array name and just use strvec consistently. There's no particular reason we have to do it all at once, or care about interactions between converted and unconverted bits. Because of our preprocessor compat layer, the names are interchangeable to the compiler (so even a definition and declaration using different names is OK). This patch converts remaining files from the first half of the alphabet, to keep the diff to a manageable size. The conversion was done purely mechanically with: git ls-files '*.c' '*.h' | xargs perl -i -pe ' s/ARGV_ARRAY/STRVEC/g; s/argv_array/strvec/g; ' and then selectively staging files with "git add '[abcdefghjkl]*'". We'll deal with any indentation/style fallouts separately. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano diff --git a/add-interactive.c b/add-interactive.c index 29cd2fe..b345777 100644 --- a/add-interactive.c +++ b/add-interactive.c @@ -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, + strvec_push(&args, files->items.items[i].string); parse_pathspec(&ps_selected, PATHSPEC_ALL_MAGIC & ~PATHSPEC_LITERAL, PATHSPEC_LITERAL_PATH, "", args.argv); 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", + 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, + strvec_push(&args, files->items.items[i].string); res = run_command_v_opt(args.argv, 0); - argv_array_clear(&args); + strvec_clear(&args); } putchar('\n'); diff --git a/add-patch.c b/add-patch.c index 09d00c5..3c91ae5 100644 --- a/add-patch.c +++ b/add-patch.c @@ -286,11 +286,11 @@ 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, + strvec_pushf(&cp->env_array, INDEX_ENVIRONMENT "=%s", s->s.r->index_file); } @@ -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,12 +380,12 @@ 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, + strvec_push(&args, /* could be on an unborn branch */ !strcmp("HEAD", s->revision) && get_oid("HEAD", &oid) ? @@ -393,19 +393,19 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps) } color_arg_index = args.argc; /* 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; 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); @@ -419,7 +419,7 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps) colored_cp.argv = args.argv; 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 @@ soft_increment: 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")); diff --git a/bisect.c b/bisect.c index 77e35dd..3e50b51 100644 --- a/bisect.c +++ b/bisect.c @@ -456,7 +456,7 @@ 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(); @@ -632,7 +632,7 @@ 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); @@ -640,12 +640,12 @@ static void bisect_rev_setup(struct repository *r, struct rev_info *revs, 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, + strvec_pushf(&rev_argv, good_format, oid_to_hex(good_revs.oid + i)); - argv_array_push(&rev_argv, "--"); + strvec_push(&rev_argv, "--"); if (read_paths) read_bisect_paths(&rev_argv); diff --git a/bundle.c b/bundle.c index d46a387..709b2ab 100644 --- a/bundle.c +++ b/bundle.c @@ -269,16 +269,16 @@ out: /* Write the pack data to bundle_fd */ -static int write_pack_data(int bundle_fd, struct rev_info *revs, struct argv_array *pack_options) +static int write_pack_data(int bundle_fd, struct rev_info *revs, struct strvec *pack_options) { struct child_process pack_objects = CHILD_PROCESS_INIT; int i; - argv_array_pushl(&pack_objects.args, + strvec_pushl(&pack_objects.args, "pack-objects", "--stdout", "--thin", "--delta-base-offset", NULL); - argv_array_pushv(&pack_objects.args, pack_options->argv); + strvec_pushv(&pack_objects.args, pack_options->argv); pack_objects.in = -1; pack_objects.out = bundle_fd; pack_objects.git_cmd = 1; @@ -321,11 +321,11 @@ static int compute_and_write_prerequisites(int bundle_fd, FILE *rls_fout; int i; - argv_array_pushl(&rls.args, + strvec_pushl(&rls.args, "rev-list", "--boundary", "--pretty=oneline", NULL); for (i = 1; i < argc; i++) - argv_array_push(&rls.args, argv[i]); + strvec_push(&rls.args, argv[i]); rls.out = -1; rls.git_cmd = 1; if (start_command(&rls)) @@ -449,7 +449,7 @@ static int write_bundle_refs(int bundle_fd, struct rev_info *revs) } int create_bundle(struct repository *r, const char *path, - int argc, const char **argv, struct argv_array *pack_options) + int argc, const char **argv, struct strvec *pack_options) { struct lock_file lock = LOCK_INIT; int bundle_fd = -1; diff --git a/bundle.h b/bundle.h index 2cf1270..3f5c9ad 100644 --- a/bundle.h +++ b/bundle.h @@ -21,7 +21,7 @@ struct bundle_header { int is_bundle(const char *path, int quiet); int read_bundle_header(const char *path, struct bundle_header *header); int create_bundle(struct repository *r, const char *path, - int argc, const char **argv, struct argv_array *pack_options); + int argc, const char **argv, struct strvec *pack_options); int verify_bundle(struct repository *r, struct bundle_header *header, int verbose); #define BUNDLE_VERBOSE 1 int unbundle(struct repository *r, struct bundle_header *header, diff --git a/column.c b/column.c index 4a38eed..a79c262 100644 --- a/column.c +++ b/column.c @@ -358,7 +358,7 @@ static struct child_process column_process = CHILD_PROCESS_INIT; int run_column_filter(int colopts, const struct column_options *opts) { - struct argv_array *argv; + struct strvec *argv; if (fd_out != -1) return -1; @@ -366,14 +366,14 @@ int run_column_filter(int colopts, const struct column_options *opts) child_process_init(&column_process); argv = &column_process.args; - argv_array_push(argv, "column"); - argv_array_pushf(argv, "--raw-mode=%d", colopts); + strvec_push(argv, "column"); + strvec_pushf(argv, "--raw-mode=%d", colopts); if (opts && opts->width) - argv_array_pushf(argv, "--width=%d", opts->width); + strvec_pushf(argv, "--width=%d", opts->width); if (opts && opts->indent) - argv_array_pushf(argv, "--indent=%s", opts->indent); + strvec_pushf(argv, "--indent=%s", opts->indent); if (opts && opts->padding) - argv_array_pushf(argv, "--padding=%d", opts->padding); + strvec_pushf(argv, "--padding=%d", opts->padding); fflush(stdout); column_process.in = -1; diff --git a/commit.c b/commit.c index 7128895..a5176a2 100644 --- a/commit.c +++ b/commit.c @@ -1630,22 +1630,22 @@ size_t ignore_non_trailer(const char *buf, size_t len) int run_commit_hook(int editor_is_used, const char *index_file, const char *name, ...) { - struct argv_array hook_env = ARGV_ARRAY_INIT; + struct strvec hook_env = STRVEC_INIT; va_list args; int ret; - argv_array_pushf(&hook_env, "GIT_INDEX_FILE=%s", index_file); + strvec_pushf(&hook_env, "GIT_INDEX_FILE=%s", index_file); /* * Let the hook know that no editor will be launched. */ if (!editor_is_used) - argv_array_push(&hook_env, "GIT_EDITOR=:"); + strvec_push(&hook_env, "GIT_EDITOR=:"); va_start(args, name); ret = run_hook_ve(hook_env.argv,name, args); va_end(args); - argv_array_clear(&hook_env); + strvec_clear(&hook_env); return ret; } diff --git a/compat/mingw.c b/compat/mingw.c index 8ee0b64..4454b3e 100644 --- a/compat/mingw.c +++ b/compat/mingw.c @@ -18,8 +18,8 @@ void open_in_gdb(void) static struct child_process cp = CHILD_PROCESS_INIT; extern char *_pgmptr; - argv_array_pushl(&cp.args, "mintty", "gdb", NULL); - argv_array_pushf(&cp.args, "--pid=%d", getpid()); + strvec_pushl(&cp.args, "mintty", "gdb", NULL); + strvec_pushf(&cp.args, "--pid=%d", getpid()); cp.clean_on_exit = 1; if (start_command(&cp) < 0) die_errno("Could not start gdb"); diff --git a/compat/terminal.c b/compat/terminal.c index 35bca03..43b73dd 100644 --- a/compat/terminal.c +++ b/compat/terminal.c @@ -86,9 +86,9 @@ static void restore_term(void) if (stty_restore.nr == 0) return; - argv_array_push(&cp.args, "stty"); + strvec_push(&cp.args, "stty"); for (i = 0; i < stty_restore.nr; i++) - argv_array_push(&cp.args, stty_restore.items[i].string); + strvec_push(&cp.args, stty_restore.items[i].string); run_command(&cp); string_list_clear(&stty_restore, 0); return; @@ -107,25 +107,25 @@ static int disable_bits(DWORD bits) if (use_stty) { struct child_process cp = CHILD_PROCESS_INIT; - argv_array_push(&cp.args, "stty"); + strvec_push(&cp.args, "stty"); if (bits & ENABLE_LINE_INPUT) { string_list_append(&stty_restore, "icanon"); - argv_array_push(&cp.args, "-icanon"); + strvec_push(&cp.args, "-icanon"); } if (bits & ENABLE_ECHO_INPUT) { string_list_append(&stty_restore, "echo"); - argv_array_push(&cp.args, "-echo"); + strvec_push(&cp.args, "-echo"); } if (bits & ENABLE_PROCESSED_INPUT) { string_list_append(&stty_restore, "-ignbrk"); string_list_append(&stty_restore, "intr"); string_list_append(&stty_restore, "^c"); - argv_array_push(&cp.args, "ignbrk"); - argv_array_push(&cp.args, "intr"); - argv_array_push(&cp.args, ""); + strvec_push(&cp.args, "ignbrk"); + strvec_push(&cp.args, "intr"); + strvec_push(&cp.args, ""); } if (run_command(&cp) == 0) @@ -273,7 +273,7 @@ static int is_known_escape_sequence(const char *sequence) hashmap_init(&sequences, (hashmap_cmp_fn)sequence_entry_cmp, NULL, 0); - argv_array_pushl(&cp.args, "infocmp", "-L", "-1", NULL); + strvec_pushl(&cp.args, "infocmp", "-L", "-1", NULL); if (pipe_command(&cp, NULL, 0, &buf, 0, NULL, 0)) strbuf_setlen(&buf, 0); diff --git a/connect.c b/connect.c index e0d5b9f..9b453fe 100644 --- a/connect.c +++ b/connect.c @@ -17,7 +17,7 @@ #include "alias.h" static char *server_capabilities_v1; -static struct argv_array server_capabilities_v2 = ARGV_ARRAY_INIT; +static struct strvec server_capabilities_v2 = STRVEC_INIT; static const char *next_server_feature_value(const char *feature, int *len, int *offset); static int check_ref(const char *name, unsigned int flags) @@ -123,7 +123,7 @@ int server_supports_feature(const char *c, const char *feature, static void process_capabilities_v2(struct packet_reader *reader) { while (packet_reader_read(reader) == PACKET_READ_NORMAL) - argv_array_push(&server_capabilities_v2, reader->line); + strvec_push(&server_capabilities_v2, reader->line); if (reader->status != PACKET_READ_FLUSH) die(_("expected flush after capabilities")); @@ -453,7 +453,7 @@ void check_stateless_delimiter(int stateless_rpc, struct ref **get_remote_refs(int fd_out, struct packet_reader *reader, struct ref **list, int for_push, - const struct argv_array *ref_prefixes, + const struct strvec *ref_prefixes, const struct string_list *server_options, int stateless_rpc) { @@ -944,9 +944,9 @@ static struct child_process *git_proxy_connect(int fd[2], char *host) proxy = xmalloc(sizeof(*proxy)); child_process_init(proxy); - argv_array_push(&proxy->args, git_proxy_command); - argv_array_push(&proxy->args, host); - argv_array_push(&proxy->args, port); + strvec_push(&proxy->args, git_proxy_command); + strvec_push(&proxy->args, host); + strvec_push(&proxy->args, port); proxy->in = -1; proxy->out = -1; if (start_command(proxy)) @@ -1199,15 +1199,15 @@ static struct child_process *git_connect_git(int fd[2], char *hostandport, * Append the appropriate environment variables to `env` and options to * `args` for running ssh in Git's SSH-tunneled transport. */ -static void push_ssh_options(struct argv_array *args, struct argv_array *env, +static void push_ssh_options(struct strvec *args, struct strvec *env, enum ssh_variant variant, const char *port, enum protocol_version version, int flags) { if (variant == VARIANT_SSH && version > 0) { - argv_array_push(args, "-o"); - argv_array_push(args, "SendEnv=" GIT_PROTOCOL_ENVIRONMENT); - argv_array_pushf(env, GIT_PROTOCOL_ENVIRONMENT "=version=%d", + strvec_push(args, "-o"); + strvec_push(args, "SendEnv=" GIT_PROTOCOL_ENVIRONMENT); + strvec_pushf(env, GIT_PROTOCOL_ENVIRONMENT "=version=%d", version); } @@ -1221,7 +1221,7 @@ static void push_ssh_options(struct argv_array *args, struct argv_array *env, case VARIANT_PLINK: case VARIANT_PUTTY: case VARIANT_TORTOISEPLINK: - argv_array_push(args, "-4"); + strvec_push(args, "-4"); } } else if (flags & CONNECT_IPV6) { switch (variant) { @@ -1233,12 +1233,12 @@ static void push_ssh_options(struct argv_array *args, struct argv_array *env, case VARIANT_PLINK: case VARIANT_PUTTY: case VARIANT_TORTOISEPLINK: - argv_array_push(args, "-6"); + strvec_push(args, "-6"); } } if (variant == VARIANT_TORTOISEPLINK) - argv_array_push(args, "-batch"); + strvec_push(args, "-batch"); if (port) { switch (variant) { @@ -1247,15 +1247,15 @@ static void push_ssh_options(struct argv_array *args, struct argv_array *env, case VARIANT_SIMPLE: die(_("ssh variant 'simple' does not support setting port")); case VARIANT_SSH: - argv_array_push(args, "-p"); + strvec_push(args, "-p"); break; case VARIANT_PLINK: case VARIANT_PUTTY: case VARIANT_TORTOISEPLINK: - argv_array_push(args, "-P"); + strvec_push(args, "-P"); } - argv_array_push(args, port); + strvec_push(args, port); } } @@ -1293,18 +1293,18 @@ static void fill_ssh_args(struct child_process *conn, const char *ssh_host, detect.use_shell = conn->use_shell; detect.no_stdin = detect.no_stdout = detect.no_stderr = 1; - argv_array_push(&detect.args, ssh); - argv_array_push(&detect.args, "-G"); + strvec_push(&detect.args, ssh); + strvec_push(&detect.args, "-G"); push_ssh_options(&detect.args, &detect.env_array, VARIANT_SSH, port, version, flags); - argv_array_push(&detect.args, ssh_host); + strvec_push(&detect.args, ssh_host); variant = run_command(&detect) ? VARIANT_SIMPLE : VARIANT_SSH; } - argv_array_push(&conn->args, ssh); + strvec_push(&conn->args, ssh); push_ssh_options(&conn->args, &conn->env_array, variant, port, version, flags); - argv_array_push(&conn->args, ssh_host); + strvec_push(&conn->args, ssh_host); } /* @@ -1365,7 +1365,7 @@ struct child_process *git_connect(int fd[2], const char *url, /* remove repo-local variables from the environment */ for (var = local_repo_env; *var; var++) - argv_array_push(&conn->env_array, *var); + strvec_push(&conn->env_array, *var); conn->use_shell = 1; conn->in = conn->out = -1; @@ -1397,11 +1397,11 @@ struct child_process *git_connect(int fd[2], const char *url, transport_check_allowed("file"); conn->trace2_child_class = "transport/file"; if (version > 0) { - argv_array_pushf(&conn->env_array, GIT_PROTOCOL_ENVIRONMENT "=version=%d", + strvec_pushf(&conn->env_array, GIT_PROTOCOL_ENVIRONMENT "=version=%d", version); } } - argv_array_push(&conn->args, cmd.buf); + strvec_push(&conn->args, cmd.buf); if (start_command(conn)) die(_("unable to fork")); diff --git a/connected.c b/connected.c index 937b4ba..96b4787 100644 --- a/connected.c +++ b/connected.c @@ -90,22 +90,22 @@ promisor_pack_found: no_promisor_pack_found: if (opt->shallow_file) { - argv_array_push(&rev_list.args, "--shallow-file"); - argv_array_push(&rev_list.args, opt->shallow_file); + strvec_push(&rev_list.args, "--shallow-file"); + strvec_push(&rev_list.args, opt->shallow_file); } - argv_array_push(&rev_list.args,"rev-list"); - argv_array_push(&rev_list.args, "--objects"); - argv_array_push(&rev_list.args, "--stdin"); + strvec_push(&rev_list.args,"rev-list"); + strvec_push(&rev_list.args, "--objects"); + strvec_push(&rev_list.args, "--stdin"); if (has_promisor_remote()) - argv_array_push(&rev_list.args, "--exclude-promisor-objects"); + strvec_push(&rev_list.args, "--exclude-promisor-objects"); if (!opt->is_deepening_fetch) { - argv_array_push(&rev_list.args, "--not"); - argv_array_push(&rev_list.args, "--all"); + strvec_push(&rev_list.args, "--not"); + strvec_push(&rev_list.args, "--all"); } - argv_array_push(&rev_list.args, "--quiet"); - argv_array_push(&rev_list.args, "--alternate-refs"); + strvec_push(&rev_list.args, "--quiet"); + strvec_push(&rev_list.args, "--alternate-refs"); if (opt->progress) - argv_array_pushf(&rev_list.args, "--progress=%s", + strvec_pushf(&rev_list.args, "--progress=%s", _("Checking connectivity")); rev_list.git_cmd = 1; diff --git a/daemon.c b/daemon.c index fd669ed..cea5f53 100644 --- a/daemon.c +++ b/daemon.c @@ -296,7 +296,7 @@ static const char *path_ok(const char *directory, struct hostinfo *hi) return NULL; /* Fallthrough. Deny by default */ } -typedef int (*daemon_service_fn)(const struct argv_array *env); +typedef int (*daemon_service_fn)(const struct strvec *env); struct daemon_service { const char *name; const char *config_name; @@ -377,7 +377,7 @@ error_return: } static int run_service(const char *dir, struct daemon_service *service, - struct hostinfo *hi, const struct argv_array *env) + struct hostinfo *hi, const struct strvec *env) { const char *path; int enabled = service->enabled; @@ -462,7 +462,7 @@ static void copy_to_log(int fd) static int run_service_command(struct child_process *cld) { - argv_array_push(&cld->args, "."); + strvec_push(&cld->args, "."); cld->git_cmd = 1; cld->err = -1; if (start_command(cld)) @@ -476,33 +476,33 @@ static int run_service_command(struct child_process *cld) return finish_command(cld); } -static int upload_pack(const struct argv_array *env) +static int upload_pack(const struct strvec *env) { struct child_process cld = CHILD_PROCESS_INIT; - argv_array_pushl(&cld.args, "upload-pack", "--strict", NULL); - argv_array_pushf(&cld.args, "--timeout=%u", timeout); + strvec_pushl(&cld.args, "upload-pack", "--strict", NULL); + strvec_pushf(&cld.args, "--timeout=%u", timeout); - argv_array_pushv(&cld.env_array, env->argv); + strvec_pushv(&cld.env_array, env->argv); return run_service_command(&cld); } -static int upload_archive(const struct argv_array *env) +static int upload_archive(const struct strvec *env) { struct child_process cld = CHILD_PROCESS_INIT; - argv_array_push(&cld.args, "upload-archive"); + strvec_push(&cld.args, "upload-archive"); - argv_array_pushv(&cld.env_array, env->argv); + strvec_pushv(&cld.env_array, env->argv); return run_service_command(&cld); } -static int receive_pack(const struct argv_array *env) +static int receive_pack(const struct strvec *env) { struct child_process cld = CHILD_PROCESS_INIT; - argv_array_push(&cld.args, "receive-pack"); + strvec_push(&cld.args, "receive-pack"); - argv_array_pushv(&cld.env_array, env->argv); + strvec_pushv(&cld.env_array, env->argv); return run_service_command(&cld); } @@ -633,7 +633,7 @@ static char *parse_host_arg(struct hostinfo *hi, char *extra_args, int buflen) return extra_args; } -static void parse_extra_args(struct hostinfo *hi, struct argv_array *env, +static void parse_extra_args(struct hostinfo *hi, struct strvec *env, char *extra_args, int buflen) { const char *end = extra_args + buflen; @@ -664,7 +664,7 @@ static void parse_extra_args(struct hostinfo *hi, struct argv_array *env, if (git_protocol.len > 0) { loginfo("Extended attribute \"protocol\": %s", git_protocol.buf); - argv_array_pushf(env, GIT_PROTOCOL_ENVIRONMENT "=%s", + strvec_pushf(env, GIT_PROTOCOL_ENVIRONMENT "=%s", git_protocol.buf); } strbuf_release(&git_protocol); @@ -761,7 +761,7 @@ static int execute(void) int pktlen, len, i; char *addr = getenv("REMOTE_ADDR"), *port = getenv("REMOTE_PORT"); struct hostinfo hi; - struct argv_array env = ARGV_ARRAY_INIT; + struct strvec env = STRVEC_INIT; hostinfo_init(&hi); @@ -794,13 +794,13 @@ static int execute(void) */ int rc = run_service(arg, s, &hi, &env); hostinfo_clear(&hi); - argv_array_clear(&env); + strvec_clear(&env); return rc; } } hostinfo_clear(&hi); - argv_array_clear(&env); + strvec_clear(&env); logerror("Protocol error: '%s'", line); return -1; } @@ -893,7 +893,7 @@ static void check_dead_children(void) cradle = &blanket->next; } -static struct argv_array cld_argv = ARGV_ARRAY_INIT; +static struct strvec cld_argv = STRVEC_INIT; static void handle(int incoming, struct sockaddr *addr, socklen_t addrlen) { struct child_process cld = CHILD_PROCESS_INIT; @@ -913,16 +913,16 @@ static void handle(int incoming, struct sockaddr *addr, socklen_t addrlen) char buf[128] = ""; struct sockaddr_in *sin_addr = (void *) addr; inet_ntop(addr->sa_family, &sin_addr->sin_addr, buf, sizeof(buf)); - argv_array_pushf(&cld.env_array, "REMOTE_ADDR=%s", buf); - argv_array_pushf(&cld.env_array, "REMOTE_PORT=%d", + strvec_pushf(&cld.env_array, "REMOTE_ADDR=%s", buf); + strvec_pushf(&cld.env_array, "REMOTE_PORT=%d", ntohs(sin_addr->sin_port)); #ifndef NO_IPV6 } else if (addr->sa_family == AF_INET6) { char buf[128] = ""; struct sockaddr_in6 *sin6_addr = (void *) addr; inet_ntop(AF_INET6, &sin6_addr->sin6_addr, buf, sizeof(buf)); - argv_array_pushf(&cld.env_array, "REMOTE_ADDR=[%s]", buf); - argv_array_pushf(&cld.env_array, "REMOTE_PORT=%d", + strvec_pushf(&cld.env_array, "REMOTE_ADDR=[%s]", buf); + strvec_pushf(&cld.env_array, "REMOTE_PORT=%d", ntohs(sin6_addr->sin6_port)); #endif } @@ -1476,10 +1476,10 @@ int cmd_main(int argc, const char **argv) write_file(pid_file, "%"PRIuMAX, (uintmax_t) getpid()); /* prepare argv for serving-processes */ - argv_array_push(&cld_argv, argv[0]); /* git-daemon */ - argv_array_push(&cld_argv, "--serve"); + strvec_push(&cld_argv, argv[0]); /* git-daemon */ + strvec_push(&cld_argv, "--serve"); for (i = 1; i < argc; ++i) - argv_array_push(&cld_argv, argv[i]); + strvec_push(&cld_argv, argv[i]); return serve(&listen_addr, listen_port, cred); } diff --git a/diff.c b/diff.c index ee00815..f1a3758 100644 --- a/diff.c +++ b/diff.c @@ -4192,14 +4192,14 @@ static struct diff_tempfile *prepare_temp_file(struct repository *r, } static void add_external_diff_name(struct repository *r, - struct argv_array *argv, + struct strvec *argv, const char *name, struct diff_filespec *df) { struct diff_tempfile *temp = prepare_temp_file(r, name, df); - argv_array_push(argv, temp->name); - argv_array_push(argv, temp->hex); - argv_array_push(argv, temp->mode); + strvec_push(argv, temp->name); + strvec_push(argv, temp->hex); + strvec_push(argv, temp->mode); } /* An external diff command takes: @@ -4216,12 +4216,12 @@ static void run_external_diff(const char *pgm, const char *xfrm_msg, struct diff_options *o) { - struct argv_array argv = ARGV_ARRAY_INIT; - struct argv_array env = ARGV_ARRAY_INIT; + struct strvec argv = STRVEC_INIT; + struct strvec env = STRVEC_INIT; struct diff_queue_struct *q = &diff_queued_diff; - argv_array_push(&argv, pgm); - argv_array_push(&argv, name); + strvec_push(&argv, pgm); + strvec_push(&argv, name); if (one && two) { add_external_diff_name(o->repo, &argv, name, one); @@ -4229,13 +4229,13 @@ static void run_external_diff(const char *pgm, add_external_diff_name(o->repo, &argv, name, two); else { add_external_diff_name(o->repo, &argv, other, two); - argv_array_push(&argv, other); - argv_array_push(&argv, xfrm_msg); + strvec_push(&argv, other); + strvec_push(&argv, xfrm_msg); } } - argv_array_pushf(&env, "GIT_DIFF_PATH_COUNTER=%d", ++o->diff_path_counter); - argv_array_pushf(&env, "GIT_DIFF_PATH_TOTAL=%d", q->nr); + strvec_pushf(&env, "GIT_DIFF_PATH_COUNTER=%d", ++o->diff_path_counter); + strvec_pushf(&env, "GIT_DIFF_PATH_TOTAL=%d", q->nr); diff_free_filespec_data(one); diff_free_filespec_data(two); @@ -4243,8 +4243,8 @@ static void run_external_diff(const char *pgm, die(_("external diff died, stopping at %s"), name); remove_tempfile(); - argv_array_clear(&argv); - argv_array_clear(&env); + strvec_clear(&argv); + strvec_clear(&env); } static int similarity_index(struct diff_filepair *p) diff --git a/environment.c b/environment.c index 75fe5f4..00fe20e 100644 --- a/environment.c +++ b/environment.c @@ -156,14 +156,14 @@ static char *expand_namespace(const char *raw_namespace) * Wrapper of getenv() that returns a strdup value. This value is kept * in argv to be freed later. */ -static const char *getenv_safe(struct argv_array *argv, const char *name) +static const char *getenv_safe(struct strvec *argv, const char *name) { const char *value = getenv(name); if (!value) return NULL; - argv_array_push(argv, value); + strvec_push(argv, value); return argv->argv[argv->argc - 1]; } @@ -172,7 +172,7 @@ void setup_git_env(const char *git_dir) const char *shallow_file; const char *replace_ref_base; struct set_gitdir_args args = { NULL }; - struct argv_array to_free = ARGV_ARRAY_INIT; + struct strvec to_free = STRVEC_INIT; args.commondir = getenv_safe(&to_free, GIT_COMMON_DIR_ENVIRONMENT); args.object_dir = getenv_safe(&to_free, DB_ENVIRONMENT); @@ -180,7 +180,7 @@ void setup_git_env(const char *git_dir) args.index_file = getenv_safe(&to_free, INDEX_ENVIRONMENT); args.alternate_db = getenv_safe(&to_free, ALTERNATE_DB_ENVIRONMENT); repo_set_gitdir(the_repository, git_dir, &args); - argv_array_clear(&to_free); + strvec_clear(&to_free); if (getenv(NO_REPLACE_OBJECTS_ENVIRONMENT)) read_replace_refs = 0; diff --git a/exec-cmd.c b/exec-cmd.c index bb24c2f..0f8e888 100644 --- a/exec-cmd.c +++ b/exec-cmd.c @@ -320,16 +320,16 @@ void setup_path(void) strbuf_release(&new_path); } -const char **prepare_git_cmd(struct argv_array *out, const char **argv) +const char **prepare_git_cmd(struct strvec *out, const char **argv) { - argv_array_push(out, "git"); - argv_array_pushv(out, argv); + strvec_push(out, "git"); + strvec_pushv(out, argv); return out->argv; } int execv_git_cmd(const char **argv) { - struct argv_array nargv = ARGV_ARRAY_INIT; + struct strvec nargv = STRVEC_INIT; prepare_git_cmd(&nargv, argv); trace_argv_printf(nargv.argv, "trace: exec:"); @@ -339,7 +339,7 @@ int execv_git_cmd(const char **argv) trace_printf("trace: exec failed: %s\n", strerror(errno)); - argv_array_clear(&nargv); + strvec_clear(&nargv); return -1; } diff --git a/fast-import.c b/fast-import.c index 0dfa14d..ce47794 100644 --- a/fast-import.c +++ b/fast-import.c @@ -843,9 +843,9 @@ static int loosen_small_pack(const struct packed_git *p) unpack.in = p->pack_fd; unpack.git_cmd = 1; unpack.stdout_to_stderr = 1; - argv_array_push(&unpack.args, "unpack-objects"); + strvec_push(&unpack.args, "unpack-objects"); if (!show_stats) - argv_array_push(&unpack.args, "-q"); + strvec_push(&unpack.args, "-q"); return run_command(&unpack); } diff --git a/fetch-pack.c b/fetch-pack.c index 80fb3bd..7aa5dfb 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -835,30 +835,30 @@ static int get_pack(struct fetch_pack_args *args, } if (alternate_shallow_file) { - argv_array_push(&cmd.args, "--shallow-file"); - argv_array_push(&cmd.args, alternate_shallow_file); + strvec_push(&cmd.args, "--shallow-file"); + strvec_push(&cmd.args, alternate_shallow_file); } if (do_keep || args->from_promisor) { if (pack_lockfiles) cmd.out = -1; cmd_name = "index-pack"; - argv_array_push(&cmd.args, cmd_name); - argv_array_push(&cmd.args, "--stdin"); + strvec_push(&cmd.args, cmd_name); + strvec_push(&cmd.args, "--stdin"); if (!args->quiet && !args->no_progress) - argv_array_push(&cmd.args, "-v"); + strvec_push(&cmd.args, "-v"); if (args->use_thin_pack) - argv_array_push(&cmd.args, "--fix-thin"); + strvec_push(&cmd.args, "--fix-thin"); if (do_keep && (args->lock_pack || unpack_limit)) { char hostname[HOST_NAME_MAX + 1]; if (xgethostname(hostname, sizeof(hostname))) xsnprintf(hostname, sizeof(hostname), "localhost"); - argv_array_pushf(&cmd.args, + strvec_pushf(&cmd.args, "--keep=fetch-pack %"PRIuMAX " on %s", (uintmax_t)getpid(), hostname); } if (only_packfile && args->check_self_contained_and_connected) - argv_array_push(&cmd.args, "--check-self-contained-and-connected"); + strvec_push(&cmd.args, "--check-self-contained-and-connected"); else /* * We cannot perform any connectivity checks because @@ -873,18 +873,18 @@ static int get_pack(struct fetch_pack_args *args, * us. */ if (!(do_keep && pack_lockfiles) && args->from_promisor) - argv_array_push(&cmd.args, "--promisor"); + strvec_push(&cmd.args, "--promisor"); } else { cmd_name = "unpack-objects"; - argv_array_push(&cmd.args, cmd_name); + strvec_push(&cmd.args, cmd_name); if (args->quiet || args->no_progress) - argv_array_push(&cmd.args, "-q"); + strvec_push(&cmd.args, "-q"); args->check_self_contained_and_connected = 0; } if (pass_header) - argv_array_pushf(&cmd.args, "--pack_header=%"PRIu32",%"PRIu32, + strvec_pushf(&cmd.args, "--pack_header=%"PRIu32",%"PRIu32, ntohl(header.hdr_version), ntohl(header.hdr_entries)); if (fetch_fsck_objects >= 0 @@ -898,9 +898,9 @@ static int get_pack(struct fetch_pack_args *args, * checks both broken objects and links, but we only * want to check for broken objects. */ - argv_array_push(&cmd.args, "--fsck-objects"); + strvec_push(&cmd.args, "--fsck-objects"); else - argv_array_pushf(&cmd.args, "--strict%s", + strvec_pushf(&cmd.args, "--strict%s", fsck_msg_types.buf); } @@ -1652,11 +1652,11 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args, const char *uri = packfile_uris.items[i].string + the_hash_algo->hexsz + 1; - argv_array_push(&cmd.args, "http-fetch"); - argv_array_pushf(&cmd.args, "--packfile=%.*s", + strvec_push(&cmd.args, "http-fetch"); + strvec_pushf(&cmd.args, "--packfile=%.*s", (int) the_hash_algo->hexsz, packfile_uris.items[i].string); - argv_array_push(&cmd.args, uri); + strvec_push(&cmd.args, uri); cmd.git_cmd = 1; cmd.no_stdin = 1; cmd.out = -1; diff --git a/fsmonitor.c b/fsmonitor.c index 932bd90..e3c982e 100644 --- a/fsmonitor.c +++ b/fsmonitor.c @@ -146,9 +146,9 @@ static int query_fsmonitor(int version, const char *last_update, struct strbuf * if (!core_fsmonitor) return -1; - argv_array_push(&cp.args, core_fsmonitor); - argv_array_pushf(&cp.args, "%d", version); - argv_array_pushf(&cp.args, "%s", last_update); + strvec_push(&cp.args, core_fsmonitor); + strvec_pushf(&cp.args, "%d", version); + strvec_pushf(&cp.args, "%s", last_update); cp.use_shell = 1; cp.dir = get_git_work_tree(); diff --git a/git.c b/git.c index 6cd887b..258035c 100644 --- a/git.c +++ b/git.c @@ -349,8 +349,8 @@ static int handle_alias(int *argcp, const char ***argv) child.clean_on_exit = 1; child.wait_after_clean = 1; child.trace2_child_class = "shell_alias"; - argv_array_push(&child.args, alias_string + 1); - argv_array_pushv(&child.args, (*argv) + 1); + strvec_push(&child.args, alias_string + 1); + strvec_pushv(&child.args, (*argv) + 1); trace2_cmd_alias(alias_command, child.args.argv); trace2_cmd_list_config(); @@ -646,7 +646,7 @@ static void strip_extension(const char **argv) static void handle_builtin(int argc, const char **argv) { - struct argv_array args = ARGV_ARRAY_INIT; + struct strvec args = STRVEC_INIT; const char *cmd; struct cmd_struct *builtin; @@ -661,9 +661,9 @@ static void handle_builtin(int argc, const char **argv) argv[0] = cmd = "help"; for (i = 0; i < argc; i++) { - argv_array_push(&args, argv[i]); + strvec_push(&args, argv[i]); if (!i) - argv_array_push(&args, "--exclude-guides"); + strvec_push(&args, "--exclude-guides"); } argc++; @@ -673,7 +673,7 @@ static void handle_builtin(int argc, const char **argv) builtin = get_builtin(cmd); if (builtin) exit(run_builtin(builtin, argc, argv)); - argv_array_clear(&args); + strvec_clear(&args); } static void execv_dashed_external(const char **argv) @@ -688,8 +688,8 @@ static void execv_dashed_external(const char **argv) use_pager = check_pager_config(argv[0]); commit_pager_choice(); - argv_array_pushf(&cmd.args, "git-%s", argv[0]); - argv_array_pushv(&cmd.args, argv + 1); + strvec_pushf(&cmd.args, "git-%s", argv[0]); + strvec_pushv(&cmd.args, argv + 1); cmd.clean_on_exit = 1; cmd.wait_after_clean = 1; cmd.silent_exec_failure = 1; @@ -741,7 +741,7 @@ static int run_argv(int *argcp, const char ***argv) if (!done_alias) handle_builtin(*argcp, *argv); else if (get_builtin(**argv)) { - struct argv_array args = ARGV_ARRAY_INIT; + struct strvec args = STRVEC_INIT; int i; /* @@ -758,9 +758,9 @@ static int run_argv(int *argcp, const char ***argv) commit_pager_choice(); - argv_array_push(&args, "git"); + strvec_push(&args, "git"); for (i = 0; i < *argcp; i++) - argv_array_push(&args, (*argv)[i]); + strvec_push(&args, (*argv)[i]); trace_argv_printf(args.argv, "trace: exec:"); diff --git a/gpg-interface.c b/gpg-interface.c index 2d538bc..cf56fe8 100644 --- a/gpg-interface.c +++ b/gpg-interface.c @@ -282,9 +282,9 @@ static int verify_signed_buffer(const char *payload, size_t payload_size, if (!fmt) BUG("bad signature '%s'", signature); - argv_array_push(&gpg.args, fmt->program); - argv_array_pushv(&gpg.args, fmt->verify_args); - argv_array_pushl(&gpg.args, + strvec_push(&gpg.args, fmt->program); + strvec_pushv(&gpg.args, fmt->verify_args); + strvec_pushl(&gpg.args, "--status-fd=1", "--verify", temp->filename.buf, "-", NULL); @@ -434,7 +434,7 @@ int sign_buffer(struct strbuf *buffer, struct strbuf *signature, const char *sig size_t i, j, bottom; struct strbuf gpg_status = STRBUF_INIT; - argv_array_pushl(&gpg.args, + strvec_pushl(&gpg.args, use_format->program, "--status-fd=2", "-bsau", signing_key, diff --git a/graph.c b/graph.c index 96af8f6..09c9cc9 100644 --- a/graph.c +++ b/graph.c @@ -82,7 +82,7 @@ static void graph_show_line_prefix(const struct diff_options *diffopt) static const char **column_colors; static unsigned short column_colors_max; -static void parse_graph_colors_config(struct argv_array *colors, const char *string) +static void parse_graph_colors_config(struct strvec *colors, const char *string) { const char *end, *start; @@ -93,13 +93,13 @@ static void parse_graph_colors_config(struct argv_array *colors, const char *str char color[COLOR_MAXLEN]; if (!color_parse_mem(start, comma - start, color)) - argv_array_push(colors, color); + strvec_push(colors, color); else warning(_("ignore invalid color '%.*s' in log.graphColors"), (int)(comma - start), start); start = comma + 1; } - argv_array_push(colors, GIT_COLOR_RESET); + strvec_push(colors, GIT_COLOR_RESET); } void graph_set_column_colors(const char **colors, unsigned short colors_max) @@ -350,8 +350,8 @@ struct git_graph *graph_init(struct rev_info *opt) graph_set_column_colors(column_colors_ansi, column_colors_ansi_max); } else { - static struct argv_array custom_colors = ARGV_ARRAY_INIT; - argv_array_clear(&custom_colors); + static struct strvec custom_colors = STRVEC_INIT; + strvec_clear(&custom_colors); parse_graph_colors_config(&custom_colors, string); free(string); /* graph_set_column_colors takes a max-index, not a count */ diff --git a/http-backend.c b/http-backend.c index 6a42bad..92fd62f 100644 --- a/http-backend.c +++ b/http-backend.c @@ -477,9 +477,9 @@ static void run_service(const char **argv, int buffer_input) host = "(none)"; if (!getenv("GIT_COMMITTER_NAME")) - argv_array_pushf(&cld.env_array, "GIT_COMMITTER_NAME=%s", user); + strvec_pushf(&cld.env_array, "GIT_COMMITTER_NAME=%s", user); if (!getenv("GIT_COMMITTER_EMAIL")) - argv_array_pushf(&cld.env_array, + strvec_pushf(&cld.env_array, "GIT_COMMITTER_EMAIL=%s@http.%s", user, host); cld.argv = argv; diff --git a/http-push.c b/http-push.c index 3a47921..e1deea6 100644 --- a/http-push.c +++ b/http-push.c @@ -1846,7 +1846,7 @@ int cmd_main(int argc, const char **argv) new_refs = 0; for (ref = remote_refs; ref; ref = ref->next) { - struct argv_array commit_argv = ARGV_ARRAY_INIT; + struct strvec commit_argv = STRVEC_INIT; if (!ref->peer_ref) continue; @@ -1924,11 +1924,11 @@ int cmd_main(int argc, const char **argv) } /* Set up revision info for this refspec */ - argv_array_push(&commit_argv, ""); /* ignored */ - argv_array_push(&commit_argv, "--objects"); - argv_array_push(&commit_argv, oid_to_hex(&ref->new_oid)); + strvec_push(&commit_argv, ""); /* ignored */ + strvec_push(&commit_argv, "--objects"); + strvec_push(&commit_argv, oid_to_hex(&ref->new_oid)); if (!push_all && !is_null_oid(&ref->old_oid)) - argv_array_pushf(&commit_argv, "^%s", + strvec_pushf(&commit_argv, "^%s", oid_to_hex(&ref->old_oid)); repo_init_revisions(the_repository, &revs, setup_git_directory()); setup_revisions(commit_argv.argc, commit_argv.argv, &revs, NULL); @@ -1961,7 +1961,7 @@ int cmd_main(int argc, const char **argv) printf("%s %s\n", !rc ? "ok" : "error", ref->name); unlock_remote(ref_lock); check_locks(); - argv_array_clear(&commit_argv); + strvec_clear(&commit_argv); } /* Update remote server info if appropriate */ diff --git a/http.c b/http.c index 3b12843..268a1e9 100644 --- a/http.c +++ b/http.c @@ -2270,12 +2270,12 @@ int finish_http_pack_request(struct http_pack_request *preq) tmpfile_fd = xopen(preq->tmpfile.buf, O_RDONLY); - argv_array_push(&ip.args, "index-pack"); - argv_array_push(&ip.args, "--stdin"); + strvec_push(&ip.args, "index-pack"); + strvec_push(&ip.args, "--stdin"); ip.git_cmd = 1; ip.in = tmpfile_fd; if (preq->generate_keep) { - argv_array_pushf(&ip.args, "--keep=git %"PRIuMAX, + strvec_pushf(&ip.args, "--keep=git %"PRIuMAX, (uintmax_t)getpid()); ip.out = 0; } else { diff --git a/imap-send.c b/imap-send.c index 5273754..5764dd8 100644 --- a/imap-send.c +++ b/imap-send.c @@ -976,7 +976,7 @@ static struct imap_store *imap_open_store(struct imap_server_conf *srvc, char *f imap_info("Starting tunnel '%s'... ", srvc->tunnel); - argv_array_push(&tunnel.args, srvc->tunnel); + strvec_push(&tunnel.args, srvc->tunnel); tunnel.use_shell = 1; tunnel.in = -1; tunnel.out = -1; diff --git a/line-log.c b/line-log.c index 05d077b..bf73ea9 100644 --- a/line-log.c +++ b/line-log.c @@ -758,12 +758,12 @@ static void parse_pathspec_from_ranges(struct pathspec *pathspec, struct line_log_data *range) { struct line_log_data *r; - struct argv_array array = ARGV_ARRAY_INIT; + struct strvec array = STRVEC_INIT; const char **paths; for (r = range; r; r = r->next) - argv_array_push(&array, r->path); - paths = argv_array_detach(&array); + strvec_push(&array, r->path); + paths = strvec_detach(&array); parse_pathspec(pathspec, 0, PATHSPEC_PREFER_FULL, "", paths); /* strings are now owned by pathspec */ diff --git a/ls-refs.c b/ls-refs.c index 98fb190..8192c94 100644 --- a/ls-refs.c +++ b/ls-refs.c @@ -11,7 +11,7 @@ * Check if one of the prefixes is a prefix of the ref. * If no prefixes were provided, all refs match. */ -static int ref_match(const struct argv_array *prefixes, const char *refname) +static int ref_match(const struct strvec *prefixes, const char *refname) { int i; @@ -31,7 +31,7 @@ static int ref_match(const struct argv_array *prefixes, const char *refname) struct ls_refs_data { unsigned peel; unsigned symrefs; - struct argv_array prefixes; + struct strvec prefixes; }; static int send_ref(const char *refname, const struct object_id *oid, @@ -84,7 +84,7 @@ static int ls_refs_config(const char *var, const char *value, void *data) return parse_hide_refs_config(var, value, "uploadpack"); } -int ls_refs(struct repository *r, struct argv_array *keys, +int ls_refs(struct repository *r, struct strvec *keys, struct packet_reader *request) { struct ls_refs_data data; @@ -102,7 +102,7 @@ int ls_refs(struct repository *r, struct argv_array *keys, else if (!strcmp("symrefs", arg)) data.symrefs = 1; else if (skip_prefix(arg, "ref-prefix ", &out)) - argv_array_push(&data.prefixes, out); + strvec_push(&data.prefixes, out); } if (request->status != PACKET_READ_FLUSH) @@ -111,6 +111,6 @@ int ls_refs(struct repository *r, struct argv_array *keys, head_ref_namespaced(send_ref, &data); for_each_namespaced_ref(send_ref, &data); packet_flush(1); - argv_array_clear(&data.prefixes); + strvec_clear(&data.prefixes); return 0; } -- cgit v0.10.2-6-g49f6 From c972bf4cf546a56fe1c54ddde1d33ebb9f454a0f Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 28 Jul 2020 16:25:12 -0400 Subject: strvec: convert remaining callers away from argv_array name We eventually want to drop the argv_array name and just use strvec consistently. There's no particular reason we have to do it all at once, or care about interactions between converted and unconverted bits. Because of our preprocessor compat layer, the names are interchangeable to the compiler (so even a definition and declaration using different names is OK). This patch converts all of the remaining files, as the resulting diff is reasonably sized. The conversion was done purely mechanically with: git ls-files '*.c' '*.h' | xargs perl -i -pe ' s/ARGV_ARRAY/STRVEC/g; s/argv_array/strvec/g; ' We'll deal with any indentation/style fallouts separately. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano diff --git a/merge.c b/merge.c index aa36de2..a05b054 100644 --- a/merge.c +++ b/merge.c @@ -19,22 +19,22 @@ int try_merge_command(struct repository *r, const char **xopts, struct commit_list *common, const char *head_arg, struct commit_list *remotes) { - struct argv_array args = ARGV_ARRAY_INIT; + struct strvec args = STRVEC_INIT; int i, ret; struct commit_list *j; - argv_array_pushf(&args, "merge-%s", strategy); + strvec_pushf(&args, "merge-%s", strategy); for (i = 0; i < xopts_nr; i++) - argv_array_pushf(&args, "--%s", xopts[i]); + strvec_pushf(&args, "--%s", xopts[i]); for (j = common; j; j = j->next) - argv_array_push(&args, merge_argument(j->item)); - argv_array_push(&args, "--"); - argv_array_push(&args, head_arg); + strvec_push(&args, merge_argument(j->item)); + strvec_push(&args, "--"); + strvec_push(&args, head_arg); for (j = remotes; j; j = j->next) - argv_array_push(&args, merge_argument(j->item)); + strvec_push(&args, merge_argument(j->item)); ret = run_command_v_opt(args.argv, RUN_GIT_CMD); - argv_array_clear(&args); + strvec_clear(&args); discard_index(r->index); if (repo_read_index(r) < 0) diff --git a/midx.c b/midx.c index 6d1584c..a5fb797 100644 --- a/midx.c +++ b/midx.c @@ -1408,21 +1408,21 @@ int midx_repack(struct repository *r, const char *object_dir, size_t batch_size, repo_config_get_bool(r, "repack.usedeltabaseoffset", &delta_base_offset); repo_config_get_bool(r, "repack.usedeltaislands", &use_delta_islands); - argv_array_push(&cmd.args, "pack-objects"); + strvec_push(&cmd.args, "pack-objects"); strbuf_addstr(&base_name, object_dir); strbuf_addstr(&base_name, "/pack/pack"); - argv_array_push(&cmd.args, base_name.buf); + strvec_push(&cmd.args, base_name.buf); if (delta_base_offset) - argv_array_push(&cmd.args, "--delta-base-offset"); + strvec_push(&cmd.args, "--delta-base-offset"); if (use_delta_islands) - argv_array_push(&cmd.args, "--delta-islands"); + strvec_push(&cmd.args, "--delta-islands"); if (flags & MIDX_PROGRESS) - argv_array_push(&cmd.args, "--progress"); + strvec_push(&cmd.args, "--progress"); else - argv_array_push(&cmd.args, "-q"); + strvec_push(&cmd.args, "-q"); strbuf_release(&base_name); diff --git a/pager.c b/pager.c index 41446d4..ee435de 100644 --- a/pager.c +++ b/pager.c @@ -68,7 +68,7 @@ const char *git_pager(int stdout_is_tty) return pager; } -static void setup_pager_env(struct argv_array *env) +static void setup_pager_env(struct strvec *env) { const char **argv; int i; @@ -88,7 +88,7 @@ static void setup_pager_env(struct argv_array *env) *cp = '\0'; if (!getenv(argv[i])) { *cp = '='; - argv_array_push(env, argv[i]); + strvec_push(env, argv[i]); } } free(pager_env); @@ -97,7 +97,7 @@ static void setup_pager_env(struct argv_array *env) void prepare_pager_args(struct child_process *pager_process, const char *pager) { - argv_array_push(&pager_process->args, pager); + strvec_push(&pager_process->args, pager); pager_process->use_shell = 1; setup_pager_env(&pager_process->env_array); pager_process->trace2_child_class = "pager"; @@ -126,7 +126,7 @@ void setup_pager(void) /* spawn the pager */ prepare_pager_args(&pager_process, pager); pager_process.in = -1; - argv_array_push(&pager_process.env_array, "GIT_PAGER_IN_USE"); + strvec_push(&pager_process.env_array, "GIT_PAGER_IN_USE"); if (start_command(&pager_process)) return; diff --git a/parse-options-cb.c b/parse-options-cb.c index 7cba964..d9d3b08 100644 --- a/parse-options-cb.c +++ b/parse-options-cb.c @@ -275,19 +275,19 @@ int parse_opt_passthru(const struct option *opt, const char *arg, int unset) /** * For an option opt, recreate the command-line option, appending it to - * opt->value which must be a argv_array. This is useful when we need to pass + * opt->value which must be a strvec. This is useful when we need to pass * the command-line option, which can be specified multiple times, to another * command. */ int parse_opt_passthru_argv(const struct option *opt, const char *arg, int unset) { static struct strbuf sb = STRBUF_INIT; - struct argv_array *opt_value = opt->value; + struct strvec *opt_value = opt->value; if (recreate_opt(&sb, opt, arg, unset) < 0) return -1; - argv_array_push(opt_value, sb.buf); + strvec_push(opt_value, sb.buf); return 0; } diff --git a/pathspec.c b/pathspec.c index 57c9b58..c303126 100644 --- a/pathspec.c +++ b/pathspec.c @@ -624,7 +624,7 @@ void parse_pathspec_file(struct pathspec *pathspec, unsigned magic_mask, unsigned flags, const char *prefix, const char *file, int nul_term_line) { - struct argv_array parsed_file = ARGV_ARRAY_INIT; + struct strvec parsed_file = STRVEC_INIT; strbuf_getline_fn getline_fn = nul_term_line ? strbuf_getline_nul : strbuf_getline; struct strbuf buf = STRBUF_INIT; @@ -643,7 +643,7 @@ void parse_pathspec_file(struct pathspec *pathspec, unsigned magic_mask, die(_("line is badly quoted: %s"), buf.buf); strbuf_swap(&buf, &unquoted); } - argv_array_push(&parsed_file, buf.buf); + strvec_push(&parsed_file, buf.buf); strbuf_reset(&buf); } @@ -653,7 +653,7 @@ void parse_pathspec_file(struct pathspec *pathspec, unsigned magic_mask, fclose(in); parse_pathspec(pathspec, magic_mask, flags, prefix, parsed_file.argv); - argv_array_clear(&parsed_file); + strvec_clear(&parsed_file); } void copy_pathspec(struct pathspec *dst, const struct pathspec *src) diff --git a/quote.c b/quote.c index 10b383c..ced0245 100644 --- a/quote.c +++ b/quote.c @@ -172,7 +172,7 @@ char *sq_dequote(char *arg) static int sq_dequote_to_argv_internal(char *arg, const char ***argv, int *nr, int *alloc, - struct argv_array *array) + struct strvec *array) { char *next = arg; @@ -187,7 +187,7 @@ static int sq_dequote_to_argv_internal(char *arg, (*argv)[(*nr)++] = dequoted; } if (array) - argv_array_push(array, dequoted); + strvec_push(array, dequoted); } while (next); return 0; diff --git a/range-diff.c b/range-diff.c index b4d1d56..3a0eb70 100644 --- a/range-diff.c +++ b/range-diff.c @@ -41,7 +41,7 @@ static size_t find_end_of_line(char *buffer, unsigned long size) * as struct object_id (will need to be free()d). */ static int read_patches(const char *range, struct string_list *list, - const struct argv_array *other_arg) + const struct strvec *other_arg) { struct child_process cp = CHILD_PROCESS_INIT; struct strbuf buf = STRBUF_INIT, contents = STRBUF_INIT; @@ -51,7 +51,7 @@ static int read_patches(const char *range, struct string_list *list, int offset, len; size_t size; - argv_array_pushl(&cp.args, "log", "--no-color", "-p", "--no-merges", + strvec_pushl(&cp.args, "log", "--no-color", "-p", "--no-merges", "--reverse", "--date-order", "--decorate=no", "--no-prefix", /* @@ -67,8 +67,8 @@ static int read_patches(const char *range, struct string_list *list, "--notes", NULL); if (other_arg) - argv_array_pushv(&cp.args, other_arg->argv); - argv_array_push(&cp.args, range); + strvec_pushv(&cp.args, other_arg->argv); + strvec_push(&cp.args, range); cp.out = -1; cp.no_stdin = 1; cp.git_cmd = 1; @@ -523,7 +523,7 @@ static struct strbuf *output_prefix_cb(struct diff_options *opt, void *data) int show_range_diff(const char *range1, const char *range2, int creation_factor, int dual_color, const struct diff_options *diffopt, - const struct argv_array *other_arg) + const struct strvec *other_arg) { int res = 0; diff --git a/range-diff.h b/range-diff.h index 916f18b..583ced2 100644 --- a/range-diff.h +++ b/range-diff.h @@ -14,6 +14,6 @@ int show_range_diff(const char *range1, const char *range2, int creation_factor, int dual_color, const struct diff_options *diffopt, - const struct argv_array *other_arg); + const struct strvec *other_arg); #endif diff --git a/ref-filter.c b/ref-filter.c index 81c4399..7f01385 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -1914,15 +1914,15 @@ static void find_longest_prefixes_1(struct string_list *out, static void find_longest_prefixes(struct string_list *out, const char **patterns) { - struct argv_array sorted = ARGV_ARRAY_INIT; + struct strvec sorted = STRVEC_INIT; struct strbuf prefix = STRBUF_INIT; - argv_array_pushv(&sorted, patterns); + strvec_pushv(&sorted, patterns); QSORT(sorted.argv, sorted.argc, qsort_strcmp); find_longest_prefixes_1(out, &prefix, sorted.argv, sorted.argc); - argv_array_clear(&sorted); + strvec_clear(&sorted); strbuf_release(&prefix); } diff --git a/refs.c b/refs.c index 0067926..d8d3b10 100644 --- a/refs.c +++ b/refs.c @@ -553,13 +553,13 @@ int refname_match(const char *abbrev_name, const char *full_name) * Given a 'prefix' expand it by the rules in 'ref_rev_parse_rules' and add * the results to 'prefixes' */ -void expand_ref_prefix(struct argv_array *prefixes, const char *prefix) +void expand_ref_prefix(struct strvec *prefixes, const char *prefix) { const char **p; int len = strlen(prefix); for (p = ref_rev_parse_rules; *p; p++) - argv_array_pushf(prefixes, *p, len, prefix); + strvec_pushf(prefixes, *p, len, prefix); } char *repo_default_branch_name(struct repository *r) @@ -2037,7 +2037,7 @@ static int run_transaction_hook(struct ref_transaction *transaction, return ret; } - argv_array_pushl(&proc.args, hook, state, NULL); + strvec_pushl(&proc.args, hook, state, NULL); proc.in = -1; proc.stdout_to_stderr = 1; proc.trace2_hook_name = "reference-transaction"; diff --git a/refspec.c b/refspec.c index f9fb67d..6f317d6 100644 --- a/refspec.c +++ b/refspec.c @@ -202,7 +202,7 @@ int valid_fetch_refspec(const char *fetch_refspec_str) } void refspec_ref_prefixes(const struct refspec *rs, - struct argv_array *ref_prefixes) + struct strvec *ref_prefixes) { int i; for (i = 0; i < rs->nr; i++) { @@ -221,7 +221,7 @@ void refspec_ref_prefixes(const struct refspec *rs, if (prefix) { if (item->pattern) { const char *glob = strchr(prefix, '*'); - argv_array_pushf(ref_prefixes, "%.*s", + strvec_pushf(ref_prefixes, "%.*s", (int)(glob - prefix), prefix); } else { diff --git a/remote-curl.c b/remote-curl.c index 05fb794..85ce4f7 100644 --- a/remote-curl.c +++ b/remote-curl.c @@ -1141,41 +1141,41 @@ static int fetch_git(struct discovery *heads, struct rpc_state rpc; struct strbuf preamble = STRBUF_INIT; int i, err; - struct argv_array args = ARGV_ARRAY_INIT; + struct strvec args = STRVEC_INIT; struct strbuf rpc_result = STRBUF_INIT; - argv_array_pushl(&args, "fetch-pack", "--stateless-rpc", + strvec_pushl(&args, "fetch-pack", "--stateless-rpc", "--stdin", "--lock-pack", NULL); if (options.followtags) - argv_array_push(&args, "--include-tag"); + strvec_push(&args, "--include-tag"); if (options.thin) - argv_array_push(&args, "--thin"); + strvec_push(&args, "--thin"); if (options.verbosity >= 3) - argv_array_pushl(&args, "-v", "-v", NULL); + strvec_pushl(&args, "-v", "-v", NULL); if (options.check_self_contained_and_connected) - argv_array_push(&args, "--check-self-contained-and-connected"); + strvec_push(&args, "--check-self-contained-and-connected"); if (options.cloning) - argv_array_push(&args, "--cloning"); + strvec_push(&args, "--cloning"); if (options.update_shallow) - argv_array_push(&args, "--update-shallow"); + strvec_push(&args, "--update-shallow"); if (!options.progress) - argv_array_push(&args, "--no-progress"); + strvec_push(&args, "--no-progress"); if (options.depth) - argv_array_pushf(&args, "--depth=%lu", options.depth); + strvec_pushf(&args, "--depth=%lu", options.depth); if (options.deepen_since) - argv_array_pushf(&args, "--shallow-since=%s", options.deepen_since); + strvec_pushf(&args, "--shallow-since=%s", options.deepen_since); for (i = 0; i < options.deepen_not.nr; i++) - argv_array_pushf(&args, "--shallow-exclude=%s", + strvec_pushf(&args, "--shallow-exclude=%s", options.deepen_not.items[i].string); if (options.deepen_relative && options.depth) - argv_array_push(&args, "--deepen-relative"); + strvec_push(&args, "--deepen-relative"); if (options.from_promisor) - argv_array_push(&args, "--from-promisor"); + strvec_push(&args, "--from-promisor"); if (options.no_dependents) - argv_array_push(&args, "--no-dependents"); + strvec_push(&args, "--no-dependents"); if (options.filter) - argv_array_pushf(&args, "--filter=%s", options.filter); - argv_array_push(&args, url.buf); + strvec_pushf(&args, "--filter=%s", options.filter); + strvec_push(&args, url.buf); for (i = 0; i < nr_heads; i++) { struct ref *ref = to_fetch[i]; @@ -1195,7 +1195,7 @@ static int fetch_git(struct discovery *heads, write_or_die(1, rpc_result.buf, rpc_result.len); strbuf_release(&rpc_result); strbuf_release(&preamble); - argv_array_clear(&args); + strvec_clear(&args); return err; } @@ -1267,15 +1267,15 @@ static int push_dav(int nr_spec, const char **specs) size_t i; child.git_cmd = 1; - argv_array_push(&child.args, "http-push"); - argv_array_push(&child.args, "--helper-status"); + strvec_push(&child.args, "http-push"); + strvec_push(&child.args, "--helper-status"); if (options.dry_run) - argv_array_push(&child.args, "--dry-run"); + strvec_push(&child.args, "--dry-run"); if (options.verbosity > 1) - argv_array_push(&child.args, "--verbose"); - argv_array_push(&child.args, url.buf); + strvec_push(&child.args, "--verbose"); + strvec_push(&child.args, url.buf); for (i = 0; i < nr_spec; i++) - argv_array_push(&child.args, specs[i]); + strvec_push(&child.args, specs[i]); if (run_command(&child)) die(_("git-http-push failed")); @@ -1286,38 +1286,38 @@ static int push_git(struct discovery *heads, int nr_spec, const char **specs) { struct rpc_state rpc; int i, err; - struct argv_array args; + struct strvec args; struct string_list_item *cas_option; struct strbuf preamble = STRBUF_INIT; struct strbuf rpc_result = STRBUF_INIT; - argv_array_init(&args); - argv_array_pushl(&args, "send-pack", "--stateless-rpc", "--helper-status", + strvec_init(&args); + strvec_pushl(&args, "send-pack", "--stateless-rpc", "--helper-status", NULL); if (options.thin) - argv_array_push(&args, "--thin"); + strvec_push(&args, "--thin"); if (options.dry_run) - argv_array_push(&args, "--dry-run"); + strvec_push(&args, "--dry-run"); if (options.push_cert == SEND_PACK_PUSH_CERT_ALWAYS) - argv_array_push(&args, "--signed=yes"); + strvec_push(&args, "--signed=yes"); else if (options.push_cert == SEND_PACK_PUSH_CERT_IF_ASKED) - argv_array_push(&args, "--signed=if-asked"); + strvec_push(&args, "--signed=if-asked"); if (options.atomic) - argv_array_push(&args, "--atomic"); + strvec_push(&args, "--atomic"); if (options.verbosity == 0) - argv_array_push(&args, "--quiet"); + strvec_push(&args, "--quiet"); else if (options.verbosity > 1) - argv_array_push(&args, "--verbose"); + strvec_push(&args, "--verbose"); for (i = 0; i < options.push_options.nr; i++) - argv_array_pushf(&args, "--push-option=%s", + strvec_pushf(&args, "--push-option=%s", options.push_options.items[i].string); - argv_array_push(&args, options.progress ? "--progress" : "--no-progress"); + strvec_push(&args, options.progress ? "--progress" : "--no-progress"); for_each_string_list_item(cas_option, &cas_options) - argv_array_push(&args, cas_option->string); - argv_array_push(&args, url.buf); + strvec_push(&args, cas_option->string); + strvec_push(&args, url.buf); - argv_array_push(&args, "--stdin"); + strvec_push(&args, "--stdin"); for (i = 0; i < nr_spec; i++) packet_buf_write(&preamble, "%s\n", specs[i]); packet_buf_flush(&preamble); @@ -1330,7 +1330,7 @@ static int push_git(struct discovery *heads, int nr_spec, const char **specs) write_or_die(1, rpc_result.buf, rpc_result.len); strbuf_release(&rpc_result); strbuf_release(&preamble); - argv_array_clear(&args); + strvec_clear(&args); return err; } @@ -1349,13 +1349,13 @@ static int push(int nr_spec, const char **specs) static void parse_push(struct strbuf *buf) { - struct argv_array specs = ARGV_ARRAY_INIT; + struct strvec specs = STRVEC_INIT; int ret; do { const char *arg; if (skip_prefix(buf->buf, "push ", &arg)) - argv_array_push(&specs, arg); + strvec_push(&specs, arg); else die(_("http transport does not support %s"), buf->buf); @@ -1374,7 +1374,7 @@ static void parse_push(struct strbuf *buf) exit(128); /* error already reported */ free_specs: - argv_array_clear(&specs); + strvec_clear(&specs); } static int stateless_connect(const char *service_name) diff --git a/remote-testsvn.c b/remote-testsvn.c index 809b290..636b2b6 100644 --- a/remote-testsvn.c +++ b/remote-testsvn.c @@ -198,10 +198,10 @@ static int cmd_import(const char *line) die_errno("Couldn't open svn dump file %s.", url); } else { svndump_proc.out = -1; - argv_array_push(&svndump_proc.args, command); - argv_array_push(&svndump_proc.args, "dump"); - argv_array_push(&svndump_proc.args, url); - argv_array_pushf(&svndump_proc.args, "-r%u:HEAD", startrev); + strvec_push(&svndump_proc.args, command); + strvec_push(&svndump_proc.args, "dump"); + strvec_push(&svndump_proc.args, url); + strvec_pushf(&svndump_proc.args, "-r%u:HEAD", startrev); code = start_command(&svndump_proc); if (code) diff --git a/remote.c b/remote.c index ba1a386..13b0978 100644 --- a/remote.c +++ b/remote.c @@ -1885,7 +1885,7 @@ static int stat_branch_pair(const char *branch_name, const char *base, struct object_id oid; struct commit *ours, *theirs; struct rev_info revs; - struct argv_array argv = ARGV_ARRAY_INIT; + struct strvec argv = STRVEC_INIT; /* Cannot stat if what we used to build on no longer exists */ if (read_ref(base, &oid)) @@ -1911,12 +1911,12 @@ static int stat_branch_pair(const char *branch_name, const char *base, BUG("stat_branch_pair: invalid abf '%d'", abf); /* Run "rev-list --left-right ours...theirs" internally... */ - argv_array_push(&argv, ""); /* ignored */ - argv_array_push(&argv, "--left-right"); - argv_array_pushf(&argv, "%s...%s", + strvec_push(&argv, ""); /* ignored */ + strvec_push(&argv, "--left-right"); + strvec_pushf(&argv, "%s...%s", oid_to_hex(&ours->object.oid), oid_to_hex(&theirs->object.oid)); - argv_array_push(&argv, "--"); + strvec_push(&argv, "--"); repo_init_revisions(the_repository, &revs, NULL); setup_revisions(argv.argc, argv.argv, &revs, NULL); @@ -1938,7 +1938,7 @@ static int stat_branch_pair(const char *branch_name, const char *base, clear_commit_marks(ours, ALL_REV_FLAGS); clear_commit_marks(theirs, ALL_REV_FLAGS); - argv_array_clear(&argv); + strvec_clear(&argv); return 1; } diff --git a/revision.c b/revision.c index 07e16ed..e144132 100644 --- a/revision.c +++ b/revision.c @@ -2073,14 +2073,14 @@ int handle_revision_arg(const char *arg_, struct rev_info *revs, int flags, unsi } static void read_pathspec_from_stdin(struct strbuf *sb, - struct argv_array *prune) + struct strvec *prune) { while (strbuf_getline(sb, stdin) != EOF) - argv_array_push(prune, sb->buf); + strvec_push(prune, sb->buf); } static void read_revisions_from_stdin(struct rev_info *revs, - struct argv_array *prune) + struct strvec *prune) { struct strbuf sb; int seen_dashdash = 0; @@ -2675,7 +2675,7 @@ static void NORETURN diagnose_missing_default(const char *def) int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct setup_revision_opt *opt) { int i, flags, left, seen_dashdash, got_rev_arg = 0, revarg_opt; - struct argv_array prune_data = ARGV_ARRAY_INIT; + struct strvec prune_data = STRVEC_INIT; const char *submodule = NULL; int seen_end_of_options = 0; @@ -2694,7 +2694,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s argv[i] = NULL; argc = i; if (argv[i + 1]) - argv_array_pushv(&prune_data, argv + i + 1); + strvec_pushv(&prune_data, argv + i + 1); seen_dashdash = 1; break; } @@ -2760,7 +2760,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s for (j = i; j < argc; j++) verify_filename(revs->prefix, argv[j], j == i); - argv_array_pushv(&prune_data, argv + i); + strvec_pushv(&prune_data, argv + i); break; } else @@ -2785,7 +2785,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s parse_pathspec(&revs->prune_data, 0, 0, revs->prefix, prune_data.argv); } - argv_array_clear(&prune_data); + strvec_clear(&prune_data); if (revs->def == NULL) revs->def = opt ? opt->def : NULL; diff --git a/run-command.c b/run-command.c index 8f57661..b9630a1 100644 --- a/run-command.c +++ b/run-command.c @@ -11,14 +11,14 @@ void child_process_init(struct child_process *child) { memset(child, 0, sizeof(*child)); - argv_array_init(&child->args); - argv_array_init(&child->env_array); + strvec_init(&child->args); + strvec_init(&child->env_array); } void child_process_clear(struct child_process *child) { - argv_array_clear(&child->args); - argv_array_clear(&child->env_array); + strvec_clear(&child->args); + strvec_clear(&child->env_array); } struct child_to_clean { @@ -263,30 +263,30 @@ int sane_execvp(const char *file, char * const argv[]) return -1; } -static const char **prepare_shell_cmd(struct argv_array *out, const char **argv) +static const char **prepare_shell_cmd(struct strvec *out, const char **argv) { if (!argv[0]) BUG("shell command is empty"); if (strcspn(argv[0], "|&;<>()$`\\\"' \t\n*?[#~=%") != strlen(argv[0])) { #ifndef GIT_WINDOWS_NATIVE - argv_array_push(out, SHELL_PATH); + strvec_push(out, SHELL_PATH); #else - argv_array_push(out, "sh"); + strvec_push(out, "sh"); #endif - argv_array_push(out, "-c"); + strvec_push(out, "-c"); /* * If we have no extra arguments, we do not even need to * bother with the "$@" magic. */ if (!argv[1]) - argv_array_push(out, argv[0]); + strvec_push(out, argv[0]); else - argv_array_pushf(out, "%s \"$@\"", argv[0]); + strvec_pushf(out, "%s \"$@\"", argv[0]); } - argv_array_pushv(out, argv); + strvec_pushv(out, argv); return out->argv; } @@ -401,7 +401,7 @@ static void child_err_spew(struct child_process *cmd, struct child_err *cerr) set_error_routine(old_errfn); } -static int prepare_cmd(struct argv_array *out, const struct child_process *cmd) +static int prepare_cmd(struct strvec *out, const struct child_process *cmd) { if (!cmd->argv[0]) BUG("command is empty"); @@ -410,14 +410,14 @@ static int prepare_cmd(struct argv_array *out, const struct child_process *cmd) * Add SHELL_PATH so in the event exec fails with ENOEXEC we can * attempt to interpret the command with 'sh'. */ - argv_array_push(out, SHELL_PATH); + strvec_push(out, SHELL_PATH); if (cmd->git_cmd) { prepare_git_cmd(out, cmd->argv); } else if (cmd->use_shell) { prepare_shell_cmd(out, cmd->argv); } else { - argv_array_pushv(out, cmd->argv); + strvec_pushv(out, cmd->argv); } /* @@ -432,7 +432,7 @@ static int prepare_cmd(struct argv_array *out, const struct child_process *cmd) free((char *)out->argv[1]); out->argv[1] = program; } else { - argv_array_clear(out); + strvec_clear(out); errno = ENOENT; return -1; } @@ -742,7 +742,7 @@ fail_pipe: int notify_pipe[2]; int null_fd = -1; char **childenv; - struct argv_array argv = ARGV_ARRAY_INIT; + struct strvec argv = STRVEC_INIT; struct child_err cerr; struct atfork_state as; @@ -888,7 +888,7 @@ fail_pipe: if (null_fd >= 0) close(null_fd); - argv_array_clear(&argv); + strvec_clear(&argv); free(childenv); } end_of_spawn: @@ -897,7 +897,7 @@ end_of_spawn: { int fhin = 0, fhout = 1, fherr = 2; const char **sargv = cmd->argv; - struct argv_array nargv = ARGV_ARRAY_INIT; + struct strvec nargv = STRVEC_INIT; if (cmd->no_stdin) fhin = open("/dev/null", O_RDWR); @@ -935,7 +935,7 @@ end_of_spawn: if (cmd->clean_on_exit && cmd->pid >= 0) mark_child_for_cleanup(cmd->pid, cmd); - argv_array_clear(&nargv); + strvec_clear(&nargv); cmd->argv = sargv; if (fhin != 0) close(fhin); @@ -1352,9 +1352,9 @@ int run_hook_ve(const char *const *env, const char *name, va_list args) if (!p) return 0; - argv_array_push(&hook.args, p); + strvec_push(&hook.args, p); while ((p = va_arg(args, const char *))) - argv_array_push(&hook.args, p); + strvec_push(&hook.args, p); hook.env = env; hook.no_stdin = 1; hook.stdout_to_stderr = 1; @@ -1868,13 +1868,13 @@ int run_processes_parallel_tr2(int n, get_next_task_fn get_next_task, int run_auto_gc(int quiet) { - struct argv_array argv_gc_auto = ARGV_ARRAY_INIT; + struct strvec argv_gc_auto = STRVEC_INIT; int status; - argv_array_pushl(&argv_gc_auto, "gc", "--auto", NULL); + strvec_pushl(&argv_gc_auto, "gc", "--auto", NULL); if (quiet) - argv_array_push(&argv_gc_auto, "--quiet"); + strvec_push(&argv_gc_auto, "--quiet"); status = run_command_v_opt(argv_gc_auto.argv, RUN_GIT_CMD); - argv_array_clear(&argv_gc_auto); + strvec_clear(&argv_gc_auto); return status; } diff --git a/run-command.h b/run-command.h index f5e05d3..8b9bfae 100644 --- a/run-command.h +++ b/run-command.h @@ -52,15 +52,15 @@ struct child_process { * Note that the ownership of the memory pointed to by .argv stays with the * caller, but it should survive until `finish_command` completes. If the * .argv member is NULL, `start_command` will point it at the .args - * `argv_array` (so you may use one or the other, but you must use exactly + * `strvec` (so you may use one or the other, but you must use exactly * one). The memory in .args will be cleaned up automatically during * `finish_command` (or during `start_command` when it is unsuccessful). * */ const char **argv; - struct argv_array args; - struct argv_array env_array; + struct strvec args; + struct strvec env_array; pid_t pid; int trace2_child_id; @@ -107,7 +107,7 @@ struct child_process { * variable that will be removed from the child process's environment. * * If the .env member is NULL, `start_command` will point it at the - * .env_array `argv_array` (so you may use one or the other, but not both). + * .env_array `strvec` (so you may use one or the other, but not both). * The memory in .env_array will be cleaned up automatically during * `finish_command` (or during `start_command` when it is unsuccessful). */ @@ -134,7 +134,7 @@ struct child_process { void *clean_on_exit_handler_cbdata; }; -#define CHILD_PROCESS_INIT { NULL, ARGV_ARRAY_INIT, ARGV_ARRAY_INIT } +#define CHILD_PROCESS_INIT { NULL, STRVEC_INIT, STRVEC_INIT } /** * The functions: child_process_init, start_command, finish_command, diff --git a/send-pack.c b/send-pack.c index d671ab5..632f158 100644 --- a/send-pack.c +++ b/send-pack.c @@ -68,20 +68,20 @@ static int pack_objects(int fd, struct ref *refs, struct oid_array *extra, struc int i; int rc; - argv_array_push(&po.args, "pack-objects"); - argv_array_push(&po.args, "--all-progress-implied"); - argv_array_push(&po.args, "--revs"); - argv_array_push(&po.args, "--stdout"); + strvec_push(&po.args, "pack-objects"); + strvec_push(&po.args, "--all-progress-implied"); + strvec_push(&po.args, "--revs"); + strvec_push(&po.args, "--stdout"); if (args->use_thin_pack) - argv_array_push(&po.args, "--thin"); + strvec_push(&po.args, "--thin"); if (args->use_ofs_delta) - argv_array_push(&po.args, "--delta-base-offset"); + strvec_push(&po.args, "--delta-base-offset"); if (args->quiet || !args->progress) - argv_array_push(&po.args, "-q"); + strvec_push(&po.args, "-q"); if (args->progress) - argv_array_push(&po.args, "--progress"); + strvec_push(&po.args, "--progress"); if (is_repository_shallow(the_repository)) - argv_array_push(&po.args, "--shallow"); + strvec_push(&po.args, "--shallow"); po.in = -1; po.out = args->stateless_rpc ? -1 : fd; po.git_cmd = 1; diff --git a/sequencer.c b/sequencer.c index 9e7f868..80c7709 100644 --- a/sequencer.c +++ b/sequencer.c @@ -830,10 +830,10 @@ finish: /* * Read a GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL AND GIT_AUTHOR_DATE from a - * file with shell quoting into struct argv_array. Returns -1 on + * file with shell quoting into struct strvec. Returns -1 on * error, 0 otherwise. */ -static int read_env_script(struct argv_array *env) +static int read_env_script(struct strvec *env) { char *name, *email, *date; @@ -841,9 +841,9 @@ static int read_env_script(struct argv_array *env) &name, &email, &date, 0)) return -1; - argv_array_pushf(env, "GIT_AUTHOR_NAME=%s", name); - argv_array_pushf(env, "GIT_AUTHOR_EMAIL=%s", email); - argv_array_pushf(env, "GIT_AUTHOR_DATE=%s", date); + strvec_pushf(env, "GIT_AUTHOR_NAME=%s", name); + strvec_pushf(env, "GIT_AUTHOR_EMAIL=%s", email); + strvec_pushf(env, "GIT_AUTHOR_DATE=%s", date); free(name); free(email); free(date); @@ -929,34 +929,34 @@ static int run_git_commit(struct repository *r, gpg_opt, gpg_opt); } - argv_array_push(&cmd.args, "commit"); + strvec_push(&cmd.args, "commit"); if (!(flags & VERIFY_MSG)) - argv_array_push(&cmd.args, "-n"); + strvec_push(&cmd.args, "-n"); if ((flags & AMEND_MSG)) - argv_array_push(&cmd.args, "--amend"); + strvec_push(&cmd.args, "--amend"); if (opts->gpg_sign) - argv_array_pushf(&cmd.args, "-S%s", opts->gpg_sign); + strvec_pushf(&cmd.args, "-S%s", opts->gpg_sign); else - argv_array_push(&cmd.args, "--no-gpg-sign"); + strvec_push(&cmd.args, "--no-gpg-sign"); if (defmsg) - argv_array_pushl(&cmd.args, "-F", defmsg, NULL); + strvec_pushl(&cmd.args, "-F", defmsg, NULL); else if (!(flags & EDIT_MSG)) - argv_array_pushl(&cmd.args, "-C", "HEAD", NULL); + strvec_pushl(&cmd.args, "-C", "HEAD", NULL); if ((flags & CLEANUP_MSG)) - argv_array_push(&cmd.args, "--cleanup=strip"); + strvec_push(&cmd.args, "--cleanup=strip"); if ((flags & EDIT_MSG)) - argv_array_push(&cmd.args, "-e"); + strvec_push(&cmd.args, "-e"); else if (!(flags & CLEANUP_MSG) && !opts->signoff && !opts->record_origin && !opts->explicit_cleanup) - argv_array_push(&cmd.args, "--cleanup=verbatim"); + strvec_push(&cmd.args, "--cleanup=verbatim"); if ((flags & ALLOW_EMPTY)) - argv_array_push(&cmd.args, "--allow-empty"); + strvec_push(&cmd.args, "--allow-empty"); if (!(flags & EDIT_MSG)) - argv_array_push(&cmd.args, "--allow-empty-message"); + strvec_push(&cmd.args, "--allow-empty-message"); if (is_rebase_i(opts) && !(flags & EDIT_MSG)) return run_command_silent_on_success(&cmd); @@ -2754,15 +2754,15 @@ static int rollback_is_safe(void) static int reset_merge(const struct object_id *oid) { int ret; - struct argv_array argv = ARGV_ARRAY_INIT; + struct strvec argv = STRVEC_INIT; - argv_array_pushl(&argv, "reset", "--merge", NULL); + strvec_pushl(&argv, "reset", "--merge", NULL); if (!is_null_oid(oid)) - argv_array_push(&argv, oid_to_hex(oid)); + strvec_push(&argv, oid_to_hex(oid)); ret = run_command_v_opt(argv.argv, RUN_GIT_CMD); - argv_array_clear(&argv); + strvec_clear(&argv); return ret; } @@ -3125,14 +3125,14 @@ static int error_failed_squash(struct repository *r, static int do_exec(struct repository *r, const char *command_line) { - struct argv_array child_env = ARGV_ARRAY_INIT; + struct strvec child_env = STRVEC_INIT; const char *child_argv[] = { NULL, NULL }; int dirty, status; fprintf(stderr, _("Executing: %s\n"), command_line); child_argv[0] = command_line; - argv_array_pushf(&child_env, "GIT_DIR=%s", absolute_path(get_git_dir())); - argv_array_pushf(&child_env, "GIT_WORK_TREE=%s", + strvec_pushf(&child_env, "GIT_DIR=%s", absolute_path(get_git_dir())); + strvec_pushf(&child_env, "GIT_WORK_TREE=%s", absolute_path(get_git_work_tree())); status = run_command_v_opt_cd_env(child_argv, RUN_USING_SHELL, NULL, child_env.argv); @@ -3165,7 +3165,7 @@ static int do_exec(struct repository *r, const char *command_line) status = 1; } - argv_array_clear(&child_env); + strvec_clear(&child_env); return status; } @@ -3544,28 +3544,28 @@ static int do_merge(struct repository *r, } cmd.git_cmd = 1; - argv_array_push(&cmd.args, "merge"); - argv_array_push(&cmd.args, "-s"); + strvec_push(&cmd.args, "merge"); + strvec_push(&cmd.args, "-s"); if (!strategy) - argv_array_push(&cmd.args, "octopus"); + strvec_push(&cmd.args, "octopus"); else { - argv_array_push(&cmd.args, strategy); + strvec_push(&cmd.args, strategy); for (k = 0; k < opts->xopts_nr; k++) - argv_array_pushf(&cmd.args, + strvec_pushf(&cmd.args, "-X%s", opts->xopts[k]); } - argv_array_push(&cmd.args, "--no-edit"); - argv_array_push(&cmd.args, "--no-ff"); - argv_array_push(&cmd.args, "--no-log"); - argv_array_push(&cmd.args, "--no-stat"); - argv_array_push(&cmd.args, "-F"); - argv_array_push(&cmd.args, git_path_merge_msg(r)); + strvec_push(&cmd.args, "--no-edit"); + strvec_push(&cmd.args, "--no-ff"); + strvec_push(&cmd.args, "--no-log"); + strvec_push(&cmd.args, "--no-stat"); + strvec_push(&cmd.args, "-F"); + strvec_push(&cmd.args, git_path_merge_msg(r)); if (opts->gpg_sign) - argv_array_push(&cmd.args, opts->gpg_sign); + strvec_push(&cmd.args, opts->gpg_sign); /* Add the tips to be merged */ for (j = to_merge; j; j = j->next) - argv_array_push(&cmd.args, + strvec_push(&cmd.args, oid_to_hex(&j->item->object.oid)); strbuf_release(&ref_name); @@ -3694,7 +3694,7 @@ void create_autostash(struct repository *r, const char *path, struct child_process stash = CHILD_PROCESS_INIT; struct object_id oid; - argv_array_pushl(&stash.args, + strvec_pushl(&stash.args, "stash", "create", "autostash", NULL); stash.git_cmd = 1; stash.no_stdin = 1; @@ -3734,9 +3734,9 @@ static int apply_save_autostash_oid(const char *stash_oid, int attempt_apply) child.git_cmd = 1; child.no_stdout = 1; child.no_stderr = 1; - argv_array_push(&child.args, "stash"); - argv_array_push(&child.args, "apply"); - argv_array_push(&child.args, stash_oid); + strvec_push(&child.args, "stash"); + strvec_push(&child.args, "apply"); + strvec_push(&child.args, stash_oid); ret = run_command(&child); } @@ -3746,12 +3746,12 @@ static int apply_save_autostash_oid(const char *stash_oid, int attempt_apply) struct child_process store = CHILD_PROCESS_INIT; store.git_cmd = 1; - argv_array_push(&store.args, "stash"); - argv_array_push(&store.args, "store"); - argv_array_push(&store.args, "-m"); - argv_array_push(&store.args, "autostash"); - argv_array_push(&store.args, "-q"); - argv_array_push(&store.args, stash_oid); + strvec_push(&store.args, "stash"); + strvec_push(&store.args, "store"); + strvec_push(&store.args, "-m"); + strvec_push(&store.args, "autostash"); + strvec_push(&store.args, "-q"); + strvec_push(&store.args, stash_oid); if (run_command(&store)) ret = error(_("cannot store %s"), stash_oid); else @@ -3831,9 +3831,9 @@ static int run_git_checkout(struct repository *r, struct replay_opts *opts, cmd.git_cmd = 1; - argv_array_push(&cmd.args, "checkout"); - argv_array_push(&cmd.args, commit); - argv_array_pushf(&cmd.env_array, GIT_REFLOG_ACTION "=%s", action); + strvec_push(&cmd.args, "checkout"); + strvec_push(&cmd.args, commit); + strvec_pushf(&cmd.env_array, GIT_REFLOG_ACTION "=%s", action); if (opts->verbose) ret = run_command(&cmd); @@ -4157,9 +4157,9 @@ cleanup_head_ref: child.in = open(rebase_path_rewritten_list(), O_RDONLY); child.git_cmd = 1; - argv_array_push(&child.args, "notes"); - argv_array_push(&child.args, "copy"); - argv_array_push(&child.args, "--for-rewrite=rebase"); + strvec_push(&child.args, "notes"); + strvec_push(&child.args, "copy"); + strvec_push(&child.args, "--for-rewrite=rebase"); /* we don't care if this copying failed */ run_command(&child); @@ -4170,8 +4170,8 @@ cleanup_head_ref: O_RDONLY); hook.stdout_to_stderr = 1; hook.trace2_hook_name = "post-rewrite"; - argv_array_push(&hook.args, post_rewrite_hook); - argv_array_push(&hook.args, "rebase"); + strvec_push(&hook.args, post_rewrite_hook); + strvec_push(&hook.args, "rebase"); /* we don't care if this hook failed */ run_command(&hook); } diff --git a/serve.c b/serve.c index 8d9a345..523a9be 100644 --- a/serve.c +++ b/serve.c @@ -56,7 +56,7 @@ struct protocol_capability { * This field should be NULL for capabilities which are not commands. */ int (*command)(struct repository *r, - struct argv_array *keys, + struct strvec *keys, struct packet_reader *request); }; @@ -142,7 +142,7 @@ static int is_command(const char *key, struct protocol_capability **command) return 0; } -int has_capability(const struct argv_array *keys, const char *capability, +int has_capability(const struct strvec *keys, const char *capability, const char **value) { int i; @@ -162,7 +162,7 @@ int has_capability(const struct argv_array *keys, const char *capability, return 0; } -static void check_algorithm(struct repository *r, struct argv_array *keys) +static void check_algorithm(struct repository *r, struct strvec *keys) { int client = GIT_HASH_SHA1, server = hash_algo_by_ptr(r->hash_algo); const char *algo_name; @@ -187,7 +187,7 @@ static int process_request(void) { enum request_state state = PROCESS_REQUEST_KEYS; struct packet_reader reader; - struct argv_array keys = ARGV_ARRAY_INIT; + struct strvec keys = STRVEC_INIT; struct protocol_capability *command = NULL; packet_reader_init(&reader, 0, NULL, 0, @@ -211,7 +211,7 @@ static int process_request(void) /* collect request; a sequence of keys and values */ if (is_command(reader.line, &command) || is_valid_capability(reader.line)) - argv_array_push(&keys, reader.line); + strvec_push(&keys, reader.line); else die("unknown capability '%s'", reader.line); @@ -254,7 +254,7 @@ static int process_request(void) command->command(the_repository, &keys, &reader); - argv_array_clear(&keys); + strvec_clear(&keys); return 0; } diff --git a/sha1-file.c b/sha1-file.c index ccd34dd..a7f7a14 100644 --- a/sha1-file.c +++ b/sha1-file.c @@ -763,18 +763,18 @@ static void fill_alternate_refs_command(struct child_process *cmd, if (!git_config_get_value("core.alternateRefsCommand", &value)) { cmd->use_shell = 1; - argv_array_push(&cmd->args, value); - argv_array_push(&cmd->args, repo_path); + strvec_push(&cmd->args, value); + strvec_push(&cmd->args, repo_path); } else { cmd->git_cmd = 1; - argv_array_pushf(&cmd->args, "--git-dir=%s", repo_path); - argv_array_push(&cmd->args, "for-each-ref"); - argv_array_push(&cmd->args, "--format=%(objectname)"); + strvec_pushf(&cmd->args, "--git-dir=%s", repo_path); + strvec_push(&cmd->args, "for-each-ref"); + strvec_push(&cmd->args, "--format=%(objectname)"); if (!git_config_get_value("core.alternateRefsPrefixes", &value)) { - argv_array_push(&cmd->args, "--"); - argv_array_split(&cmd->args, value); + strvec_push(&cmd->args, "--"); + strvec_split(&cmd->args, value); } } diff --git a/sub-process.c b/sub-process.c index 1b1af9d..dfa790d 100644 --- a/sub-process.c +++ b/sub-process.c @@ -84,7 +84,7 @@ int subprocess_start(struct hashmap *hashmap, struct subprocess_entry *entry, co process = &entry->process; child_process_init(process); - argv_array_push(&process->args, cmd); + strvec_push(&process->args, cmd); process->use_shell = 1; process->in = -1; process->out = -1; diff --git a/submodule.c b/submodule.c index 874db5c..5c94474 100644 --- a/submodule.c +++ b/submodule.c @@ -262,17 +262,17 @@ int is_submodule_active(struct repository *repo, const char *path) sl = repo_config_get_value_multi(repo, "submodule.active"); if (sl) { struct pathspec ps; - struct argv_array args = ARGV_ARRAY_INIT; + struct strvec args = STRVEC_INIT; const struct string_list_item *item; for_each_string_list_item(item, sl) { - argv_array_push(&args, item->string); + strvec_push(&args, item->string); } parse_pathspec(&ps, 0, 0, NULL, args.argv); ret = match_pathspec(repo->index, &ps, path, strlen(path), 0, NULL, 1); - argv_array_clear(&args); + strvec_clear(&args); clear_pathspec(&ps); return ret; } @@ -481,27 +481,27 @@ static void print_submodule_summary(struct repository *r, struct rev_info *rev, strbuf_release(&sb); } -static void prepare_submodule_repo_env_no_git_dir(struct argv_array *out) +static void prepare_submodule_repo_env_no_git_dir(struct strvec *out) { const char * const *var; for (var = local_repo_env; *var; var++) { if (strcmp(*var, CONFIG_DATA_ENVIRONMENT)) - argv_array_push(out, *var); + strvec_push(out, *var); } } -void prepare_submodule_repo_env(struct argv_array *out) +void prepare_submodule_repo_env(struct strvec *out) { prepare_submodule_repo_env_no_git_dir(out); - argv_array_pushf(out, "%s=%s", GIT_DIR_ENVIRONMENT, + strvec_pushf(out, "%s=%s", GIT_DIR_ENVIRONMENT, DEFAULT_GIT_DIR_ENVIRONMENT); } -static void prepare_submodule_repo_env_in_gitdir(struct argv_array *out) +static void prepare_submodule_repo_env_in_gitdir(struct strvec *out) { prepare_submodule_repo_env_no_git_dir(out); - argv_array_pushf(out, "%s=.", GIT_DIR_ENVIRONMENT); + strvec_pushf(out, "%s=.", GIT_DIR_ENVIRONMENT); } /* @@ -681,22 +681,22 @@ void show_submodule_inline_diff(struct diff_options *o, const char *path, cp.no_stdin = 1; /* TODO: other options may need to be passed here. */ - argv_array_pushl(&cp.args, "diff", "--submodule=diff", NULL); - argv_array_pushf(&cp.args, "--color=%s", want_color(o->use_color) ? + strvec_pushl(&cp.args, "diff", "--submodule=diff", NULL); + strvec_pushf(&cp.args, "--color=%s", want_color(o->use_color) ? "always" : "never"); if (o->flags.reverse_diff) { - argv_array_pushf(&cp.args, "--src-prefix=%s%s/", + strvec_pushf(&cp.args, "--src-prefix=%s%s/", o->b_prefix, path); - argv_array_pushf(&cp.args, "--dst-prefix=%s%s/", + strvec_pushf(&cp.args, "--dst-prefix=%s%s/", o->a_prefix, path); } else { - argv_array_pushf(&cp.args, "--src-prefix=%s%s/", + strvec_pushf(&cp.args, "--src-prefix=%s%s/", o->a_prefix, path); - argv_array_pushf(&cp.args, "--dst-prefix=%s%s/", + strvec_pushf(&cp.args, "--dst-prefix=%s%s/", o->b_prefix, path); } - argv_array_push(&cp.args, oid_to_hex(old_oid)); + strvec_push(&cp.args, oid_to_hex(old_oid)); /* * If the submodule has modified content, we will diff against the * work tree, under the assumption that the user has asked for the @@ -704,7 +704,7 @@ void show_submodule_inline_diff(struct diff_options *o, const char *path, * haven't yet been committed to the submodule yet. */ if (!(dirty_submodule & DIRTY_SUBMODULE_MODIFIED)) - argv_array_push(&cp.args, oid_to_hex(new_oid)); + strvec_push(&cp.args, oid_to_hex(new_oid)); prepare_submodule_repo_env(&cp.env_array); if (start_command(&cp)) @@ -836,7 +836,7 @@ static void collect_changed_submodules_cb(struct diff_queue_struct *q, */ static void collect_changed_submodules(struct repository *r, struct string_list *changed, - struct argv_array *argv) + struct strvec *argv) { struct rev_info rev; const struct commit *commit; @@ -879,8 +879,8 @@ static int has_remote(const char *refname, const struct object_id *oid, static int append_oid_to_argv(const struct object_id *oid, void *data) { - struct argv_array *argv = data; - argv_array_push(argv, oid_to_hex(oid)); + struct strvec *argv = data; + strvec_push(argv, oid_to_hex(oid)); return 0; } @@ -941,9 +941,9 @@ static int submodule_has_commits(struct repository *r, struct child_process cp = CHILD_PROCESS_INIT; struct strbuf out = STRBUF_INIT; - argv_array_pushl(&cp.args, "rev-list", "-n", "1", NULL); + strvec_pushl(&cp.args, "rev-list", "-n", "1", NULL); oid_array_for_each_unique(commits, append_oid_to_argv, &cp.args); - argv_array_pushl(&cp.args, "--not", "--all", NULL); + strvec_pushl(&cp.args, "--not", "--all", NULL); prepare_submodule_repo_env(&cp.env_array); cp.git_cmd = 1; @@ -982,9 +982,9 @@ static int submodule_needs_pushing(struct repository *r, struct strbuf buf = STRBUF_INIT; int needs_pushing = 0; - argv_array_push(&cp.args, "rev-list"); + strvec_push(&cp.args, "rev-list"); oid_array_for_each_unique(commits, append_oid_to_argv, &cp.args); - argv_array_pushl(&cp.args, "--not", "--remotes", "-n", "1" , NULL); + strvec_pushl(&cp.args, "--not", "--remotes", "-n", "1" , NULL); prepare_submodule_repo_env(&cp.env_array); cp.git_cmd = 1; @@ -1012,13 +1012,13 @@ int find_unpushed_submodules(struct repository *r, { struct string_list submodules = STRING_LIST_INIT_DUP; struct string_list_item *name; - struct argv_array argv = ARGV_ARRAY_INIT; + struct strvec argv = STRVEC_INIT; /* argv.argv[0] will be ignored by setup_revisions */ - argv_array_push(&argv, "find_unpushed_submodules"); + strvec_push(&argv, "find_unpushed_submodules"); oid_array_for_each_unique(commits, append_oid_to_argv, &argv); - argv_array_push(&argv, "--not"); - argv_array_pushf(&argv, "--remotes=%s", remotes_name); + strvec_push(&argv, "--not"); + strvec_pushf(&argv, "--remotes=%s", remotes_name); collect_changed_submodules(r, &submodules, &argv); @@ -1041,7 +1041,7 @@ int find_unpushed_submodules(struct repository *r, } free_submodules_oids(&submodules); - argv_array_clear(&argv); + strvec_clear(&argv); return needs_pushing->nr; } @@ -1054,22 +1054,22 @@ static int push_submodule(const char *path, { if (for_each_remote_ref_submodule(path, has_remote, NULL) > 0) { struct child_process cp = CHILD_PROCESS_INIT; - argv_array_push(&cp.args, "push"); + strvec_push(&cp.args, "push"); if (dry_run) - argv_array_push(&cp.args, "--dry-run"); + strvec_push(&cp.args, "--dry-run"); if (push_options && push_options->nr) { const struct string_list_item *item; for_each_string_list_item(item, push_options) - argv_array_pushf(&cp.args, "--push-option=%s", + strvec_pushf(&cp.args, "--push-option=%s", item->string); } if (remote->origin != REMOTE_UNCONFIGURED) { int i; - argv_array_push(&cp.args, remote->name); + strvec_push(&cp.args, remote->name); for (i = 0; i < rs->raw_nr; i++) - argv_array_push(&cp.args, rs->raw[i]); + strvec_push(&cp.args, rs->raw[i]); } prepare_submodule_repo_env(&cp.env_array); @@ -1095,13 +1095,13 @@ static void submodule_push_check(const char *path, const char *head, struct child_process cp = CHILD_PROCESS_INIT; int i; - argv_array_push(&cp.args, "submodule--helper"); - argv_array_push(&cp.args, "push-check"); - argv_array_push(&cp.args, head); - argv_array_push(&cp.args, remote->name); + strvec_push(&cp.args, "submodule--helper"); + strvec_push(&cp.args, "push-check"); + strvec_push(&cp.args, head); + strvec_push(&cp.args, remote->name); for (i = 0; i < rs->raw_nr; i++) - argv_array_push(&cp.args, rs->raw[i]); + strvec_push(&cp.args, rs->raw[i]); prepare_submodule_repo_env(&cp.env_array); cp.git_cmd = 1; @@ -1189,17 +1189,17 @@ void check_for_new_submodule_commits(struct object_id *oid) static void calculate_changed_submodule_paths(struct repository *r, struct string_list *changed_submodule_names) { - struct argv_array argv = ARGV_ARRAY_INIT; + struct strvec argv = STRVEC_INIT; struct string_list_item *name; /* No need to check if there are no submodules configured */ if (!submodule_from_path(r, NULL, NULL)) return; - argv_array_push(&argv, "--"); /* argv[0] program name */ + strvec_push(&argv, "--"); /* argv[0] program name */ oid_array_for_each_unique(&ref_tips_after_fetch, append_oid_to_argv, &argv); - argv_array_push(&argv, "--not"); + strvec_push(&argv, "--not"); oid_array_for_each_unique(&ref_tips_before_fetch, append_oid_to_argv, &argv); @@ -1231,7 +1231,7 @@ static void calculate_changed_submodule_paths(struct repository *r, string_list_remove_empty_items(changed_submodule_names, 1); - argv_array_clear(&argv); + strvec_clear(&argv); oid_array_clear(&ref_tips_before_fetch); oid_array_clear(&ref_tips_after_fetch); initialized_fetch_ref_tips = 0; @@ -1242,24 +1242,24 @@ int submodule_touches_in_range(struct repository *r, struct object_id *incl_oid) { struct string_list subs = STRING_LIST_INIT_DUP; - struct argv_array args = ARGV_ARRAY_INIT; + struct strvec args = STRVEC_INIT; int ret; /* No need to check if there are no submodules configured */ if (!submodule_from_path(r, NULL, NULL)) return 0; - argv_array_push(&args, "--"); /* args[0] program name */ - argv_array_push(&args, oid_to_hex(incl_oid)); + strvec_push(&args, "--"); /* args[0] program name */ + strvec_push(&args, oid_to_hex(incl_oid)); if (!is_null_oid(excl_oid)) { - argv_array_push(&args, "--not"); - argv_array_push(&args, oid_to_hex(excl_oid)); + strvec_push(&args, "--not"); + strvec_push(&args, oid_to_hex(excl_oid)); } collect_changed_submodules(r, &subs, &args); ret = subs.nr; - argv_array_clear(&args); + strvec_clear(&args); free_submodules_oids(&subs); return ret; @@ -1267,7 +1267,7 @@ int submodule_touches_in_range(struct repository *r, struct submodule_parallel_fetch { int count; - struct argv_array args; + struct strvec args; struct repository *r; const char *prefix; int command_line_option; @@ -1283,7 +1283,7 @@ struct submodule_parallel_fetch { struct strbuf submodules_with_errors; }; -#define SPF_INIT {0, ARGV_ARRAY_INIT, NULL, NULL, 0, 0, 0, 0, \ +#define SPF_INIT {0, STRVEC_INIT, NULL, NULL, 0, 0, 0, 0, \ STRING_LIST_INIT_DUP, \ NULL, 0, 0, STRBUF_INIT} @@ -1452,15 +1452,15 @@ static int get_next_submodule(struct child_process *cp, if (!spf->quiet) strbuf_addf(err, _("Fetching submodule %s%s\n"), spf->prefix, ce->name); - argv_array_init(&cp->args); - argv_array_pushv(&cp->args, spf->args.argv); - argv_array_push(&cp->args, default_argv); - argv_array_push(&cp->args, "--submodule-prefix"); + strvec_init(&cp->args); + strvec_pushv(&cp->args, spf->args.argv); + strvec_push(&cp->args, default_argv); + strvec_push(&cp->args, "--submodule-prefix"); strbuf_addf(&submodule_prefix, "%s%s/", spf->prefix, task->sub->path); - argv_array_push(&cp->args, submodule_prefix.buf); + strvec_push(&cp->args, submodule_prefix.buf); spf->count++; *task_cb = task; @@ -1500,14 +1500,14 @@ static int get_next_submodule(struct child_process *cp, cp->git_cmd = 1; cp->dir = task->repo->gitdir; - argv_array_init(&cp->args); - argv_array_pushv(&cp->args, spf->args.argv); - argv_array_push(&cp->args, "on-demand"); - argv_array_push(&cp->args, "--submodule-prefix"); - argv_array_push(&cp->args, submodule_prefix.buf); + strvec_init(&cp->args); + strvec_pushv(&cp->args, spf->args.argv); + strvec_push(&cp->args, "on-demand"); + strvec_push(&cp->args, "--submodule-prefix"); + strvec_push(&cp->args, submodule_prefix.buf); /* NEEDSWORK: have get_default_remote from submodule--helper */ - argv_array_push(&cp->args, "origin"); + strvec_push(&cp->args, "origin"); oid_array_for_each_unique(task->commits, append_oid_to_argv, &cp->args); @@ -1598,7 +1598,7 @@ out: } int fetch_populated_submodules(struct repository *r, - const struct argv_array *options, + const struct strvec *options, const char *prefix, int command_line_option, int default_option, int quiet, int max_parallel_jobs) @@ -1618,10 +1618,10 @@ int fetch_populated_submodules(struct repository *r, if (repo_read_index(r) < 0) die(_("index file corrupt")); - argv_array_push(&spf.args, "fetch"); + strvec_push(&spf.args, "fetch"); for (i = 0; i < options->argc; i++) - argv_array_push(&spf.args, options->argv[i]); - argv_array_push(&spf.args, "--recurse-submodules-default"); + strvec_push(&spf.args, options->argv[i]); + strvec_push(&spf.args, "--recurse-submodules-default"); /* default value, "--submodule-prefix" and its value are added later */ calculate_changed_submodule_paths(r, &spf.changed_submodule_names); @@ -1638,7 +1638,7 @@ int fetch_populated_submodules(struct repository *r, spf.submodules_with_errors.buf); - argv_array_clear(&spf.args); + strvec_clear(&spf.args); out: free_submodules_oids(&spf.changed_submodule_names); return spf.result; @@ -1666,9 +1666,9 @@ unsigned is_submodule_modified(const char *path, int ignore_untracked) } strbuf_reset(&buf); - argv_array_pushl(&cp.args, "status", "--porcelain=2", NULL); + strvec_pushl(&cp.args, "status", "--porcelain=2", NULL); if (ignore_untracked) - argv_array_push(&cp.args, "-uno"); + strvec_push(&cp.args, "-uno"); prepare_submodule_repo_env(&cp.env_array); cp.git_cmd = 1; @@ -1779,16 +1779,16 @@ int bad_to_remove_submodule(const char *path, unsigned flags) if (!submodule_uses_gitfile(path)) return 1; - argv_array_pushl(&cp.args, "status", "--porcelain", + strvec_pushl(&cp.args, "status", "--porcelain", "--ignore-submodules=none", NULL); if (flags & SUBMODULE_REMOVAL_IGNORE_UNTRACKED) - argv_array_push(&cp.args, "-uno"); + strvec_push(&cp.args, "-uno"); else - argv_array_push(&cp.args, "-uall"); + strvec_push(&cp.args, "-uall"); if (!(flags & SUBMODULE_REMOVAL_IGNORE_IGNORED_UNTRACKED)) - argv_array_push(&cp.args, "--ignored"); + strvec_push(&cp.args, "--ignored"); prepare_submodule_repo_env(&cp.env_array); cp.git_cmd = 1; @@ -1846,7 +1846,7 @@ static int submodule_has_dirty_index(const struct submodule *sub) prepare_submodule_repo_env(&cp.env_array); cp.git_cmd = 1; - argv_array_pushl(&cp.args, "diff-index", "--quiet", + strvec_pushl(&cp.args, "diff-index", "--quiet", "--cached", "HEAD", NULL); cp.no_stdin = 1; cp.no_stdout = 1; @@ -1866,11 +1866,11 @@ static void submodule_reset_index(const char *path) cp.no_stdin = 1; cp.dir = path; - argv_array_pushf(&cp.args, "--super-prefix=%s%s/", + strvec_pushf(&cp.args, "--super-prefix=%s%s/", get_super_prefix_or_empty(), path); - argv_array_pushl(&cp.args, "read-tree", "-u", "--reset", NULL); + strvec_pushl(&cp.args, "read-tree", "-u", "--reset", NULL); - argv_array_push(&cp.args, empty_tree_oid_hex()); + strvec_push(&cp.args, empty_tree_oid_hex()); if (run_command(&cp)) die(_("could not reset submodule index")); @@ -1947,24 +1947,24 @@ int submodule_move_head(const char *path, cp.no_stdin = 1; cp.dir = path; - argv_array_pushf(&cp.args, "--super-prefix=%s%s/", + strvec_pushf(&cp.args, "--super-prefix=%s%s/", get_super_prefix_or_empty(), path); - argv_array_pushl(&cp.args, "read-tree", "--recurse-submodules", NULL); + strvec_pushl(&cp.args, "read-tree", "--recurse-submodules", NULL); if (flags & SUBMODULE_MOVE_HEAD_DRY_RUN) - argv_array_push(&cp.args, "-n"); + strvec_push(&cp.args, "-n"); else - argv_array_push(&cp.args, "-u"); + strvec_push(&cp.args, "-u"); if (flags & SUBMODULE_MOVE_HEAD_FORCE) - argv_array_push(&cp.args, "--reset"); + strvec_push(&cp.args, "--reset"); else - argv_array_push(&cp.args, "-m"); + strvec_push(&cp.args, "-m"); if (!(flags & SUBMODULE_MOVE_HEAD_FORCE)) - argv_array_push(&cp.args, old_head ? old_head : empty_tree_oid_hex()); + strvec_push(&cp.args, old_head ? old_head : empty_tree_oid_hex()); - argv_array_push(&cp.args, new_head ? new_head : empty_tree_oid_hex()); + strvec_push(&cp.args, new_head ? new_head : empty_tree_oid_hex()); if (run_command(&cp)) { ret = error(_("Submodule '%s' could not be updated."), path); @@ -1980,7 +1980,7 @@ int submodule_move_head(const char *path, cp.dir = path; prepare_submodule_repo_env(&cp.env_array); - argv_array_pushl(&cp.args, "update-ref", "HEAD", + strvec_pushl(&cp.args, "update-ref", "HEAD", "--no-deref", new_head, NULL); if (run_command(&cp)) { @@ -2157,7 +2157,7 @@ void absorb_git_dir_into_superproject(const char *path, cp.dir = path; cp.git_cmd = 1; cp.no_stdin = 1; - argv_array_pushl(&cp.args, "--super-prefix", sb.buf, + strvec_pushl(&cp.args, "--super-prefix", sb.buf, "submodule--helper", "absorb-git-dirs", NULL); prepare_submodule_repo_env(&cp.env_array); @@ -2194,9 +2194,9 @@ int get_superproject_working_tree(struct strbuf *buf) strbuf_release(&one_up); prepare_submodule_repo_env(&cp.env_array); - argv_array_pop(&cp.env_array); + strvec_pop(&cp.env_array); - argv_array_pushl(&cp.args, "--literal-pathspecs", "-C", "..", + strvec_pushl(&cp.args, "--literal-pathspecs", "-C", "..", "ls-files", "-z", "--stage", "--full-name", "--", subpath, NULL); strbuf_reset(&sb); diff --git a/t/helper/test-run-command.c b/t/helper/test-run-command.c index 8d3f6d5..67dde56 100644 --- a/t/helper/test-run-command.c +++ b/t/helper/test-run-command.c @@ -31,7 +31,7 @@ static int parallel_next(struct child_process *cp, if (number_callbacks >= 4) return 0; - argv_array_pushv(&cp->args, d->argv); + strvec_pushv(&cp->args, d->argv); strbuf_addstr(err, "preloaded output of a child\n"); number_callbacks++; return 1; @@ -72,19 +72,19 @@ static int next_test(struct child_process *cp, struct strbuf *err, void *cb, return 0; test = suite->tests.items[suite->next++].string; - argv_array_pushl(&cp->args, "sh", test, NULL); + strvec_pushl(&cp->args, "sh", test, NULL); if (suite->quiet) - argv_array_push(&cp->args, "--quiet"); + strvec_push(&cp->args, "--quiet"); if (suite->immediate) - argv_array_push(&cp->args, "-i"); + strvec_push(&cp->args, "-i"); if (suite->verbose) - argv_array_push(&cp->args, "-v"); + strvec_push(&cp->args, "-v"); if (suite->verbose_log) - argv_array_push(&cp->args, "-V"); + strvec_push(&cp->args, "-V"); if (suite->trace) - argv_array_push(&cp->args, "-x"); + strvec_push(&cp->args, "-x"); if (suite->write_junit_xml) - argv_array_push(&cp->args, "--write-junit-xml"); + strvec_push(&cp->args, "--write-junit-xml"); strbuf_addf(err, "Output of '%s':\n", test); *task_cb = (void *)test; @@ -220,7 +220,7 @@ static int quote_stress_test(int argc, const char **argv) char special[] = ".?*\\^_\"'`{}()[]<>@~&+:;$%"; // \t\r\n\a"; int i, j, k, trials = 100, skip = 0, msys2 = 0; struct strbuf out = STRBUF_INIT; - struct argv_array args = ARGV_ARRAY_INIT; + struct strvec args = STRVEC_INIT; struct option options[] = { OPT_INTEGER('n', "trials", &trials, "Number of trials"), OPT_INTEGER('s', "skip", &skip, "Skip trials"), @@ -241,12 +241,12 @@ static int quote_stress_test(int argc, const char **argv) size_t arg_count, arg_offset; int ret = 0; - argv_array_clear(&args); + strvec_clear(&args); if (msys2) - argv_array_pushl(&args, "sh", "-c", + strvec_pushl(&args, "sh", "-c", "printf %s\\\\0 \"$@\"", "skip", NULL); else - argv_array_pushl(&args, "test-tool", "run-command", + strvec_pushl(&args, "test-tool", "run-command", "quote-echo", NULL); arg_offset = args.argc; @@ -254,7 +254,7 @@ static int quote_stress_test(int argc, const char **argv) trials = 1; arg_count = argc; for (j = 0; j < arg_count; j++) - argv_array_push(&args, argv[j]); + strvec_push(&args, argv[j]); } else { arg_count = 1 + (my_random() % 5); for (j = 0; j < arg_count; j++) { @@ -268,7 +268,7 @@ static int quote_stress_test(int argc, const char **argv) ARRAY_SIZE(special)]; buf[arg_len] = '\0'; - argv_array_push(&args, buf); + strvec_push(&args, buf); } } @@ -301,7 +301,7 @@ static int quote_stress_test(int argc, const char **argv) (int)j, args.argv[j + arg_offset]); strbuf_release(&out); - argv_array_clear(&args); + strvec_clear(&args); return ret; } @@ -311,7 +311,7 @@ static int quote_stress_test(int argc, const char **argv) } strbuf_release(&out); - argv_array_clear(&args); + strvec_clear(&args); return 0; } @@ -338,7 +338,7 @@ static int inherit_handle(const char *argv0) xsnprintf(path, sizeof(path), "out-XXXXXX"); tmp = xmkstemp(path); - argv_array_pushl(&cp.args, + strvec_pushl(&cp.args, "test-tool", argv0, "inherited-handle-child", NULL); cp.in = -1; cp.no_stdout = cp.no_stderr = 1; @@ -391,7 +391,7 @@ int cmd__run_command(int argc, const char **argv) while (!strcmp(argv[1], "env")) { if (!argv[2]) die("env specifier without a value"); - argv_array_push(&proc.env_array, argv[2]); + strvec_push(&proc.env_array, argv[2]); argv += 2; argc -= 2; } diff --git a/tmp-objdir.c b/tmp-objdir.c index 06924a7..e78e481 100644 --- a/tmp-objdir.c +++ b/tmp-objdir.c @@ -10,7 +10,7 @@ struct tmp_objdir { struct strbuf path; - struct argv_array env; + struct strvec env; }; /* @@ -24,7 +24,7 @@ static struct tmp_objdir *the_tmp_objdir; static void tmp_objdir_free(struct tmp_objdir *t) { strbuf_release(&t->path); - argv_array_clear(&t->env); + strvec_clear(&t->env); free(t); } @@ -79,7 +79,7 @@ static void remove_tmp_objdir_on_signal(int signo) * separated by PATH_SEP (which is what separate values in * GIT_ALTERNATE_OBJECT_DIRECTORIES). */ -static void env_append(struct argv_array *env, const char *key, const char *val) +static void env_append(struct strvec *env, const char *key, const char *val) { struct strbuf quoted = STRBUF_INIT; const char *old; @@ -97,16 +97,16 @@ static void env_append(struct argv_array *env, const char *key, const char *val) old = getenv(key); if (!old) - argv_array_pushf(env, "%s=%s", key, val); + strvec_pushf(env, "%s=%s", key, val); else - argv_array_pushf(env, "%s=%s%c%s", key, old, PATH_SEP, val); + strvec_pushf(env, "%s=%s%c%s", key, old, PATH_SEP, val); strbuf_release("ed); } -static void env_replace(struct argv_array *env, const char *key, const char *val) +static void env_replace(struct strvec *env, const char *key, const char *val) { - argv_array_pushf(env, "%s=%s", key, val); + strvec_pushf(env, "%s=%s", key, val); } static int setup_tmp_objdir(const char *root) @@ -131,7 +131,7 @@ struct tmp_objdir *tmp_objdir_create(void) t = xmalloc(sizeof(*t)); strbuf_init(&t->path, 0); - argv_array_init(&t->env); + strvec_init(&t->env); strbuf_addf(&t->path, "%s/incoming-XXXXXX", get_object_directory()); diff --git a/transport-helper.c b/transport-helper.c index 441763f..dcd4adf 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -128,14 +128,14 @@ static struct child_process *get_helper(struct transport *transport) helper->in = -1; helper->out = -1; helper->err = 0; - argv_array_pushf(&helper->args, "git-remote-%s", data->name); - argv_array_push(&helper->args, transport->remote->name); - argv_array_push(&helper->args, remove_ext_force(transport->url)); + strvec_pushf(&helper->args, "git-remote-%s", data->name); + strvec_push(&helper->args, transport->remote->name); + strvec_push(&helper->args, remove_ext_force(transport->url)); helper->git_cmd = 0; helper->silent_exec_failure = 1; if (have_git_dir()) - argv_array_pushf(&helper->env_array, "%s=%s", + strvec_pushf(&helper->env_array, "%s=%s", GIT_DIR_ENVIRONMENT, get_git_dir()); helper->trace2_child_class = helper->args.argv[0]; /* "remote-" */ @@ -439,13 +439,13 @@ static int get_importer(struct transport *transport, struct child_process *fasti int cat_blob_fd, code; child_process_init(fastimport); fastimport->in = xdup(helper->out); - argv_array_push(&fastimport->args, "fast-import"); - argv_array_push(&fastimport->args, "--allow-unsafe-features"); - argv_array_push(&fastimport->args, debug ? "--stats" : "--quiet"); + strvec_push(&fastimport->args, "fast-import"); + strvec_push(&fastimport->args, "--allow-unsafe-features"); + strvec_push(&fastimport->args, debug ? "--stats" : "--quiet"); if (data->bidi_import) { cat_blob_fd = xdup(helper->in); - argv_array_pushf(&fastimport->args, "--cat-blob-fd=%d", cat_blob_fd); + strvec_pushf(&fastimport->args, "--cat-blob-fd=%d", cat_blob_fd); } fastimport->git_cmd = 1; @@ -466,17 +466,17 @@ static int get_exporter(struct transport *transport, /* we need to duplicate helper->in because we want to use it after * fastexport is done with it. */ fastexport->out = dup(helper->in); - argv_array_push(&fastexport->args, "fast-export"); - argv_array_push(&fastexport->args, "--use-done-feature"); - argv_array_push(&fastexport->args, data->signed_tags ? + strvec_push(&fastexport->args, "fast-export"); + strvec_push(&fastexport->args, "--use-done-feature"); + strvec_push(&fastexport->args, data->signed_tags ? "--signed-tags=verbatim" : "--signed-tags=warn-strip"); if (data->export_marks) - argv_array_pushf(&fastexport->args, "--export-marks=%s.tmp", data->export_marks); + strvec_pushf(&fastexport->args, "--export-marks=%s.tmp", data->export_marks); if (data->import_marks) - argv_array_pushf(&fastexport->args, "--import-marks=%s", data->import_marks); + strvec_pushf(&fastexport->args, "--import-marks=%s", data->import_marks); for (i = 0; i < revlist_args->nr; i++) - argv_array_push(&fastexport->args, revlist_args->items[i].string); + strvec_push(&fastexport->args, revlist_args->items[i].string); fastexport->git_cmd = 1; return start_command(fastexport); @@ -1082,7 +1082,7 @@ static int has_attribute(const char *attrs, const char *attr) } static struct ref *get_refs_list(struct transport *transport, int for_push, - const struct argv_array *ref_prefixes) + const struct strvec *ref_prefixes) { get_helper(transport); diff --git a/transport-internal.h b/transport-internal.h index 284784a..27c9daf 100644 --- a/transport-internal.h +++ b/transport-internal.h @@ -30,7 +30,7 @@ struct transport_vtable { * in the ref's old_sha1 field; otherwise it should be all 0. **/ struct ref *(*get_refs_list)(struct transport *transport, int for_push, - const struct argv_array *ref_prefixes); + const struct strvec *ref_prefixes); /** * Fetch the objects for the given refs. Note that this gets diff --git a/transport.c b/transport.c index b41386e..2d4fd85 100644 --- a/transport.c +++ b/transport.c @@ -127,7 +127,7 @@ struct bundle_transport_data { static struct ref *get_refs_from_bundle(struct transport *transport, int for_push, - const struct argv_array *ref_prefixes) + const struct strvec *ref_prefixes) { struct bundle_transport_data *data = transport->data; struct ref *result = NULL; @@ -283,7 +283,7 @@ static void die_if_server_options(struct transport *transport) * remote refs. */ static struct ref *handshake(struct transport *transport, int for_push, - const struct argv_array *ref_prefixes, + const struct strvec *ref_prefixes, int must_list_refs) { struct git_transport_data *data = transport->data; @@ -327,7 +327,7 @@ static struct ref *handshake(struct transport *transport, int for_push, } static struct ref *get_refs_via_connect(struct transport *transport, int for_push, - const struct argv_array *ref_prefixes) + const struct strvec *ref_prefixes) { return handshake(transport, for_push, ref_prefixes, 1); } @@ -1153,7 +1153,7 @@ int transport_push(struct repository *r, int porcelain = flags & TRANSPORT_PUSH_PORCELAIN; int pretend = flags & TRANSPORT_PUSH_DRY_RUN; int push_ret, ret, err; - struct argv_array ref_prefixes = ARGV_ARRAY_INIT; + struct strvec ref_prefixes = STRVEC_INIT; if (check_push_refs(local_refs, rs) < 0) return -1; @@ -1165,7 +1165,7 @@ int transport_push(struct repository *r, &ref_prefixes); trace2_region_leave("transport_push", "get_refs_list", r); - argv_array_clear(&ref_prefixes); + strvec_clear(&ref_prefixes); if (flags & TRANSPORT_PUSH_ALL) match_flags |= MATCH_REFS_ALL; @@ -1281,7 +1281,7 @@ int transport_push(struct repository *r, } const struct ref *transport_get_remote_refs(struct transport *transport, - const struct argv_array *ref_prefixes) + const struct strvec *ref_prefixes) { if (!transport->got_remote_refs) { transport->remote_refs = diff --git a/transport.h b/transport.h index b3c3013..1be4013 100644 --- a/transport.h +++ b/transport.h @@ -243,7 +243,7 @@ int transport_push(struct repository *repo, * ref_prefixes. */ const struct ref *transport_get_remote_refs(struct transport *transport, - const struct argv_array *ref_prefixes); + const struct strvec *ref_prefixes); /* * Fetch the hash algorithm used by a remote. diff --git a/unpack-trees.c b/unpack-trees.c index 65c3395..323280d 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -106,7 +106,7 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts, const char **msgs = opts->msgs; const char *msg; - argv_array_init(&opts->msgs_to_free); + strvec_init(&opts->msgs_to_free); if (!strcmp(cmd, "checkout")) msg = advice_commit_before_merge @@ -124,7 +124,7 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts, "Please commit your changes or stash them before you %s.") : _("Your local changes to the following files would be overwritten by %s:\n%%s"); msgs[ERROR_WOULD_OVERWRITE] = msgs[ERROR_NOT_UPTODATE_FILE] = - argv_array_pushf(&opts->msgs_to_free, msg, cmd, cmd); + strvec_pushf(&opts->msgs_to_free, msg, cmd, cmd); msgs[ERROR_NOT_UPTODATE_DIR] = _("Updating the following directories would lose untracked files in them:\n%s"); @@ -145,7 +145,7 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts, "Please move or remove them before you %s.") : _("The following untracked working tree files would be removed by %s:\n%%s"); msgs[ERROR_WOULD_LOSE_UNTRACKED_REMOVED] = - argv_array_pushf(&opts->msgs_to_free, msg, cmd, cmd); + strvec_pushf(&opts->msgs_to_free, msg, cmd, cmd); if (!strcmp(cmd, "checkout")) msg = advice_commit_before_merge @@ -163,7 +163,7 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts, "Please move or remove them before you %s.") : _("The following untracked working tree files would be overwritten by %s:\n%%s"); msgs[ERROR_WOULD_LOSE_UNTRACKED_OVERWRITTEN] = - argv_array_pushf(&opts->msgs_to_free, msg, cmd, cmd); + strvec_pushf(&opts->msgs_to_free, msg, cmd, cmd); /* * Special case: ERROR_BIND_OVERLAP refers to a pair of paths, we @@ -189,7 +189,7 @@ void setup_unpack_trees_porcelain(struct unpack_trees_options *opts, void clear_unpack_trees_porcelain(struct unpack_trees_options *opts) { - argv_array_clear(&opts->msgs_to_free); + strvec_clear(&opts->msgs_to_free); memset(opts->msgs, 0, sizeof(opts->msgs)); } diff --git a/unpack-trees.h b/unpack-trees.h index f8a904a..2e87875 100644 --- a/unpack-trees.h +++ b/unpack-trees.h @@ -70,7 +70,7 @@ struct unpack_trees_options { struct pathspec *pathspec; merge_fn_t fn; const char *msgs[NB_UNPACK_TREES_WARNING_TYPES]; - struct argv_array msgs_to_free; + struct strvec msgs_to_free; /* * Store error messages in an array, each case * corresponding to a error message type diff --git a/upload-pack.c b/upload-pack.c index b435dae..1b0e1fc 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -269,45 +269,45 @@ static void create_pack_file(struct upload_pack_data *pack_data, if (!pack_data->pack_objects_hook) pack_objects.git_cmd = 1; else { - argv_array_push(&pack_objects.args, pack_data->pack_objects_hook); - argv_array_push(&pack_objects.args, "git"); + strvec_push(&pack_objects.args, pack_data->pack_objects_hook); + strvec_push(&pack_objects.args, "git"); pack_objects.use_shell = 1; } if (pack_data->shallow_nr) { - argv_array_push(&pack_objects.args, "--shallow-file"); - argv_array_push(&pack_objects.args, ""); + strvec_push(&pack_objects.args, "--shallow-file"); + strvec_push(&pack_objects.args, ""); } - argv_array_push(&pack_objects.args, "pack-objects"); - argv_array_push(&pack_objects.args, "--revs"); + strvec_push(&pack_objects.args, "pack-objects"); + strvec_push(&pack_objects.args, "--revs"); if (pack_data->use_thin_pack) - argv_array_push(&pack_objects.args, "--thin"); + strvec_push(&pack_objects.args, "--thin"); - argv_array_push(&pack_objects.args, "--stdout"); + strvec_push(&pack_objects.args, "--stdout"); if (pack_data->shallow_nr) - argv_array_push(&pack_objects.args, "--shallow"); + strvec_push(&pack_objects.args, "--shallow"); if (!pack_data->no_progress) - argv_array_push(&pack_objects.args, "--progress"); + strvec_push(&pack_objects.args, "--progress"); if (pack_data->use_ofs_delta) - argv_array_push(&pack_objects.args, "--delta-base-offset"); + strvec_push(&pack_objects.args, "--delta-base-offset"); if (pack_data->use_include_tag) - argv_array_push(&pack_objects.args, "--include-tag"); + strvec_push(&pack_objects.args, "--include-tag"); if (pack_data->filter_options.choice) { const char *spec = expand_list_objects_filter_spec(&pack_data->filter_options); if (pack_objects.use_shell) { struct strbuf buf = STRBUF_INIT; sq_quote_buf(&buf, spec); - argv_array_pushf(&pack_objects.args, "--filter=%s", buf.buf); + strvec_pushf(&pack_objects.args, "--filter=%s", buf.buf); strbuf_release(&buf); } else { - argv_array_pushf(&pack_objects.args, "--filter=%s", + strvec_pushf(&pack_objects.args, "--filter=%s", spec); } } if (uri_protocols) { for (i = 0; i < uri_protocols->nr; i++) - argv_array_pushf(&pack_objects.args, "--uri-protocol=%s", + strvec_pushf(&pack_objects.args, "--uri-protocol=%s", uri_protocols->items[i].string); } @@ -880,26 +880,26 @@ static int send_shallow_list(struct upload_pack_data *data) deepen(data, data->depth); ret = 1; } else if (data->deepen_rev_list) { - struct argv_array av = ARGV_ARRAY_INIT; + struct strvec av = STRVEC_INIT; int i; - argv_array_push(&av, "rev-list"); + strvec_push(&av, "rev-list"); if (data->deepen_since) - argv_array_pushf(&av, "--max-age=%"PRItime, data->deepen_since); + strvec_pushf(&av, "--max-age=%"PRItime, data->deepen_since); if (data->deepen_not.nr) { - argv_array_push(&av, "--not"); + strvec_push(&av, "--not"); for (i = 0; i < data->deepen_not.nr; i++) { struct string_list_item *s = data->deepen_not.items + i; - argv_array_push(&av, s->string); + strvec_push(&av, s->string); } - argv_array_push(&av, "--not"); + strvec_push(&av, "--not"); } for (i = 0; i < data->want_obj.nr; i++) { struct object *o = data->want_obj.objects[i].item; - argv_array_push(&av, oid_to_hex(&o->oid)); + strvec_push(&av, oid_to_hex(&o->oid)); } deepen_by_rev_list(data, av.argc, av.argv); - argv_array_clear(&av); + strvec_clear(&av); ret = 1; } else { if (data->shallows.nr > 0) { @@ -1521,7 +1521,7 @@ enum fetch_state { FETCH_DONE, }; -int upload_pack_v2(struct repository *r, struct argv_array *keys, +int upload_pack_v2(struct repository *r, struct strvec *keys, struct packet_reader *request) { enum fetch_state state = FETCH_PROCESS_ARGS; diff --git a/wt-status.c b/wt-status.c index 9817161..60d4e84 100644 --- a/wt-status.c +++ b/wt-status.c @@ -913,17 +913,17 @@ static void wt_longstatus_print_submodule_summary(struct wt_status *s, int uncom struct strbuf summary = STRBUF_INIT; char *summary_content; - argv_array_pushf(&sm_summary.env_array, "GIT_INDEX_FILE=%s", + strvec_pushf(&sm_summary.env_array, "GIT_INDEX_FILE=%s", s->index_file); - argv_array_push(&sm_summary.args, "submodule"); - argv_array_push(&sm_summary.args, "summary"); - argv_array_push(&sm_summary.args, uncommitted ? "--files" : "--cached"); - argv_array_push(&sm_summary.args, "--for-status"); - argv_array_push(&sm_summary.args, "--summary-limit"); - argv_array_pushf(&sm_summary.args, "%d", s->submodule_summary); + strvec_push(&sm_summary.args, "submodule"); + strvec_push(&sm_summary.args, "summary"); + strvec_push(&sm_summary.args, uncommitted ? "--files" : "--cached"); + strvec_push(&sm_summary.args, "--for-status"); + strvec_push(&sm_summary.args, "--summary-limit"); + strvec_pushf(&sm_summary.args, "%d", s->submodule_summary); if (!uncommitted) - argv_array_push(&sm_summary.args, s->amend ? "HEAD^" : "HEAD"); + strvec_push(&sm_summary.args, s->amend ? "HEAD^" : "HEAD"); sm_summary.git_cmd = 1; sm_summary.no_stdin = 1; -- cgit v0.10.2-6-g49f6 From f6d8942b1fc6c968980c8ae03054d7b2114b4415 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 28 Jul 2020 16:26:31 -0400 Subject: strvec: fix indentation in renamed calls Code which split an argv_array call across multiple lines, like: argv_array_pushl(&args, "one argument", "another argument", "and more", NULL); was recently mechanically renamed to use strvec, which results in mis-matched indentation like: strvec_pushl(&args, "one argument", "another argument", "and more", NULL); Let's fix these up to align the arguments with the opening paren. I did this manually by sifting through the results of: git jump grep 'strvec_.*,$' and liberally applying my editor's auto-format. Most of the changes are of the form shown above, though I also normalized a few that had originally used a single-tab indentation (rather than our usual style of aligning with the open paren). I also rewrapped a couple of obvious cases (e.g., where previously too-long lines became short enough to fit on one), but I wasn't aggressive about it. In cases broken to three or more lines, the grouping of arguments is sometimes meaningful, and it wasn't worth my time or reviewer time to ponder each case individually. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano diff --git a/add-interactive.c b/add-interactive.c index b345777..458f3a3 100644 --- a/add-interactive.c +++ b/add-interactive.c @@ -941,7 +941,7 @@ static int run_patch(struct add_i_state *s, const struct pathspec *ps, for (i = 0; i < files->items.nr; i++) if (files->selected[i]) strvec_push(&args, - files->items.items[i].string); + files->items.items[i].string); parse_pathspec(&ps_selected, PATHSPEC_ALL_MAGIC & ~PATHSPEC_LITERAL, PATHSPEC_LITERAL_PATH, "", args.argv); @@ -979,13 +979,13 @@ static int run_diff(struct add_i_state *s, const struct pathspec *ps, struct strvec args = STRVEC_INIT; strvec_pushl(&args, "git", "diff", "-p", "--cached", - oid_to_hex(!is_initial ? &oid : - s->r->hash_algo->empty_tree), - "--", NULL); + 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]) strvec_push(&args, - files->items.items[i].string); + files->items.items[i].string); res = run_command_v_opt(args.argv, 0); strvec_clear(&args); } diff --git a/add-patch.c b/add-patch.c index 3c91ae5..8c07728 100644 --- a/add-patch.c +++ b/add-patch.c @@ -291,7 +291,7 @@ static void setup_child_process(struct add_p_state *s, cp->git_cmd = 1; strvec_pushf(&cp->env_array, - INDEX_ENVIRONMENT "=%s", s->s.r->index_file); + INDEX_ENVIRONMENT "=%s", s->s.r->index_file); } static int parse_range(const char **p, @@ -386,10 +386,10 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps) if (s->revision) { struct object_id oid; strvec_push(&args, - /* could be on an unborn branch */ - !strcmp("HEAD", s->revision) && - get_oid("HEAD", &oid) ? - empty_tree_oid_hex() : s->revision); + /* 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; /* Use `--no-color` explicitly, just in case `diff.color = always`. */ diff --git a/bisect.c b/bisect.c index 3e50b51..99ff694 100644 --- a/bisect.c +++ b/bisect.c @@ -644,7 +644,7 @@ static void bisect_rev_setup(struct repository *r, struct rev_info *revs, strvec_pushf(&rev_argv, bad_format, oid_to_hex(current_bad_oid)); for (i = 0; i < good_revs.nr; i++) strvec_pushf(&rev_argv, good_format, - oid_to_hex(good_revs.oid + i)); + oid_to_hex(good_revs.oid + i)); strvec_push(&rev_argv, "--"); if (read_paths) read_bisect_paths(&rev_argv); diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c index 9815e78..dd52878 100644 --- a/builtin/bisect--helper.c +++ b/builtin/bisect--helper.c @@ -529,7 +529,7 @@ static int bisect_start(struct bisect_terms *terms, int no_checkout, struct strvec argv = STRVEC_INIT; strvec_pushl(&argv, "checkout", start_head.buf, - "--", NULL); + "--", NULL); if (run_command_v_opt(argv.argv, RUN_GIT_CMD)) { res = error(_("checking out '%s' failed." " Try 'git bisect start " diff --git a/builtin/describe.c b/builtin/describe.c index ff3c169..e3cac80 100644 --- a/builtin/describe.c +++ b/builtin/describe.c @@ -505,8 +505,8 @@ static void describe_blob(struct object_id oid, struct strbuf *dst) struct process_commit_data pcd = { null_oid, oid, dst, &revs}; strvec_pushl(&args, "internal: The first arg is not parsed", - "--objects", "--in-commit-order", "--reverse", "HEAD", - NULL); + "--objects", "--in-commit-order", "--reverse", "HEAD", + NULL); repo_init_revisions(the_repository, &revs, NULL); if (setup_revisions(args.argc, args.argv, &revs, NULL) > 1) @@ -598,8 +598,8 @@ int cmd_describe(int argc, const char **argv, const char *prefix) strvec_init(&args); strvec_pushl(&args, "name-rev", - "--peel-tag", "--name-only", "--no-undefined", - NULL); + "--peel-tag", "--name-only", "--no-undefined", + NULL); if (always) strvec_push(&args, "--always"); if (!all) { diff --git a/builtin/difftool.c b/builtin/difftool.c index 40c4d7b..5ac021a 100644 --- a/builtin/difftool.c +++ b/builtin/difftool.c @@ -211,9 +211,9 @@ static void changed_files(struct hashmap *result, const char *index_path, env[0] = index_env.buf; strvec_pushl(&update_index.args, - "--git-dir", git_dir, "--work-tree", workdir, - "update-index", "--really-refresh", "-q", - "--unmerged", NULL); + "--git-dir", git_dir, "--work-tree", workdir, + "update-index", "--really-refresh", "-q", + "--unmerged", NULL); update_index.no_stdin = 1; update_index.no_stdout = 1; update_index.no_stderr = 1; @@ -226,8 +226,8 @@ static void changed_files(struct hashmap *result, const char *index_path, run_command(&update_index); strvec_pushl(&diff_files.args, - "--git-dir", git_dir, "--work-tree", workdir, - "diff-files", "--name-only", "-z", NULL); + "--git-dir", git_dir, "--work-tree", workdir, + "diff-files", "--name-only", "-z", NULL); diff_files.no_stdin = 1; diff_files.git_cmd = 1; diff_files.use_shell = 0; @@ -394,7 +394,7 @@ static int run_dir_diff(const char *extcmd, int symlinks, const char *prefix, child.dir = prefix; child.out = -1; strvec_pushl(&child.args, "diff", "--raw", "--no-abbrev", "-z", - NULL); + NULL); for (i = 0; i < argc; i++) strvec_push(&child.args, argv[i]); if (start_command(&child)) diff --git a/builtin/fetch.c b/builtin/fetch.c index cc63618..c2e7afe 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -1601,7 +1601,7 @@ static int fetch_multiple(struct string_list *list, int max_children) } strvec_pushl(&argv, "fetch", "--append", "--no-auto-gc", - "--no-write-commit-graph", NULL); + "--no-write-commit-graph", NULL); add_options_to_argv(&argv); if (max_children != 1 && list->nr != 1) { diff --git a/builtin/gc.c b/builtin/gc.c index 89742e1..9871980 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -662,7 +662,7 @@ int cmd_gc(int argc, const char **argv, const char *prefix) strvec_push(&prune, "--no-progress"); if (has_promisor_remote()) strvec_push(&prune, - "--exclude-promisor-objects"); + "--exclude-promisor-objects"); if (run_command_v_opt(prune.argv, RUN_GIT_CMD)) die(FAILED_RUN, prune.argv[0]); } diff --git a/builtin/pull.c b/builtin/pull.c index 8a8d30e..dae8766 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -638,7 +638,7 @@ static int rebase_submodules(void) cp.git_cmd = 1; cp.no_stdin = 1; strvec_pushl(&cp.args, "submodule", "update", - "--recursive", "--rebase", NULL); + "--recursive", "--rebase", NULL); argv_push_verbosity(&cp.args); return run_command(&cp); @@ -651,7 +651,7 @@ static int update_submodules(void) cp.git_cmd = 1; cp.no_stdin = 1; strvec_pushl(&cp.args, "submodule", "update", - "--recursive", "--checkout", NULL); + "--recursive", "--checkout", NULL); argv_push_verbosity(&cp.args); return run_command(&cp); @@ -802,7 +802,7 @@ static int get_rebase_fork_point(struct object_id *fork_point, const char *repo, return -1; strvec_pushl(&cp.args, "merge-base", "--fork-point", - remote_branch, curr_branch->name, NULL); + remote_branch, curr_branch->name, NULL); cp.no_stdin = 1; cp.no_stderr = 1; cp.git_cmd = 1; diff --git a/builtin/rebase.c b/builtin/rebase.c index fb56b9e..35aeb8e 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -348,7 +348,7 @@ static int do_interactive_rebase(struct rebase_options *opts, unsigned flags) strvec_pushl(&make_script_args, "", revisions, NULL); if (opts->restrict_revision) strvec_pushf(&make_script_args, "^%s", - oid_to_hex(&opts->restrict_revision->object.oid)); + oid_to_hex(&opts->restrict_revision->object.oid)); ret = sequencer_make_script(the_repository, &todo_list.buf, make_script_args.argc, make_script_args.argv, @@ -858,17 +858,17 @@ static int run_am(struct rebase_options *opts) format_patch.git_cmd = 1; strvec_pushl(&format_patch.args, "format-patch", "-k", "--stdout", - "--full-index", "--cherry-pick", "--right-only", - "--src-prefix=a/", "--dst-prefix=b/", "--no-renames", - "--no-cover-letter", "--pretty=mboxrd", "--topo-order", - "--no-base", NULL); + "--full-index", "--cherry-pick", "--right-only", + "--src-prefix=a/", "--dst-prefix=b/", "--no-renames", + "--no-cover-letter", "--pretty=mboxrd", "--topo-order", + "--no-base", NULL); if (opts->git_format_patch_opt.len) strvec_split(&format_patch.args, - opts->git_format_patch_opt.buf); + opts->git_format_patch_opt.buf); strvec_push(&format_patch.args, revisions.buf); if (opts->restrict_revision) strvec_pushf(&format_patch.args, "^%s", - oid_to_hex(&opts->restrict_revision->object.oid)); + oid_to_hex(&opts->restrict_revision->object.oid)); status = run_command(&format_patch); if (status) { diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 7127423..1fc69cf 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -668,24 +668,24 @@ static void prepare_push_cert_sha1(struct child_process *proc) } if (!is_null_oid(&push_cert_oid)) { strvec_pushf(&proc->env_array, "GIT_PUSH_CERT=%s", - oid_to_hex(&push_cert_oid)); + oid_to_hex(&push_cert_oid)); strvec_pushf(&proc->env_array, "GIT_PUSH_CERT_SIGNER=%s", - sigcheck.signer ? sigcheck.signer : ""); + sigcheck.signer ? sigcheck.signer : ""); strvec_pushf(&proc->env_array, "GIT_PUSH_CERT_KEY=%s", - sigcheck.key ? sigcheck.key : ""); + sigcheck.key ? sigcheck.key : ""); strvec_pushf(&proc->env_array, "GIT_PUSH_CERT_STATUS=%c", - sigcheck.result); + sigcheck.result); if (push_cert_nonce) { strvec_pushf(&proc->env_array, - "GIT_PUSH_CERT_NONCE=%s", - push_cert_nonce); + "GIT_PUSH_CERT_NONCE=%s", + push_cert_nonce); strvec_pushf(&proc->env_array, - "GIT_PUSH_CERT_NONCE_STATUS=%s", - nonce_status); + "GIT_PUSH_CERT_NONCE_STATUS=%s", + nonce_status); if (nonce_status == NONCE_SLOP) strvec_pushf(&proc->env_array, - "GIT_PUSH_CERT_NONCE_SLOP=%ld", - nonce_stamp_slop); + "GIT_PUSH_CERT_NONCE_SLOP=%ld", + nonce_stamp_slop); } } } @@ -721,10 +721,10 @@ static int run_and_feed_hook(const char *hook_name, feed_fn feed, int i; for (i = 0; i < feed_state->push_options->nr; i++) strvec_pushf(&proc.env_array, - "GIT_PUSH_OPTION_%d=%s", i, - feed_state->push_options->items[i].string); + "GIT_PUSH_OPTION_%d=%s", i, + feed_state->push_options->items[i].string); strvec_pushf(&proc.env_array, "GIT_PUSH_OPTION_COUNT=%d", - feed_state->push_options->nr); + feed_state->push_options->nr); } else strvec_pushf(&proc.env_array, "GIT_PUSH_OPTION_COUNT"); @@ -1718,7 +1718,7 @@ static const char *pack_lockfile; static void push_header_arg(struct strvec *args, struct pack_header *hdr) { strvec_pushf(args, "--pack_header=%"PRIu32",%"PRIu32, - ntohl(hdr->hdr_version), ntohl(hdr->hdr_entries)); + ntohl(hdr->hdr_version), ntohl(hdr->hdr_entries)); } static const char *unpack(int err_fd, struct shallow_info *si) @@ -1768,10 +1768,10 @@ static const char *unpack(int err_fd, struct shallow_info *si) strvec_push(&child.args, "-q"); if (fsck_objects) strvec_pushf(&child.args, "--strict%s", - fsck_msg_types.buf); + fsck_msg_types.buf); if (max_input_size) strvec_pushf(&child.args, "--max-input-size=%"PRIuMAX, - (uintmax_t)max_input_size); + (uintmax_t)max_input_size); child.no_stdout = 1; child.err = err_fd; child.git_cmd = 1; @@ -1787,9 +1787,9 @@ static const char *unpack(int err_fd, struct shallow_info *si) if (xgethostname(hostname, sizeof(hostname))) xsnprintf(hostname, sizeof(hostname), "localhost"); strvec_pushf(&child.args, - "--keep=receive-pack %"PRIuMAX" on %s", - (uintmax_t)getpid(), - hostname); + "--keep=receive-pack %"PRIuMAX" on %s", + (uintmax_t)getpid(), + hostname); if (!quiet && err_fd) strvec_push(&child.args, "--show-resolving-progress"); @@ -1797,12 +1797,12 @@ static const char *unpack(int err_fd, struct shallow_info *si) strvec_push(&child.args, "--report-end-of-input"); if (fsck_objects) strvec_pushf(&child.args, "--strict%s", - fsck_msg_types.buf); + fsck_msg_types.buf); if (!reject_thin) strvec_push(&child.args, "--fix-thin"); if (max_input_size) strvec_pushf(&child.args, "--max-input-size=%"PRIuMAX, - (uintmax_t)max_input_size); + (uintmax_t)max_input_size); child.out = -1; child.err = err_fd; child.git_cmd = 1; diff --git a/builtin/repack.c b/builtin/repack.c index 7435ee9..04c5cea 100644 --- a/builtin/repack.c +++ b/builtin/repack.c @@ -366,7 +366,7 @@ int cmd_repack(int argc, const char **argv, const char *prefix) strvec_push(&cmd.args, "--honor-pack-keep"); for (i = 0; i < keep_pack_list.nr; i++) strvec_pushf(&cmd.args, "--keep-pack=%s", - keep_pack_list.items[i].string); + keep_pack_list.items[i].string); strvec_push(&cmd.args, "--non-empty"); strvec_push(&cmd.args, "--all"); strvec_push(&cmd.args, "--reflog"); @@ -388,12 +388,12 @@ int cmd_repack(int argc, const char **argv, const char *prefix) if (existing_packs.nr && delete_redundant) { if (unpack_unreachable) { strvec_pushf(&cmd.args, - "--unpack-unreachable=%s", - unpack_unreachable); + "--unpack-unreachable=%s", + unpack_unreachable); strvec_push(&cmd.env_array, "GIT_REF_PARANOIA=1"); } else if (pack_everything & LOOSEN_UNREACHABLE) { strvec_push(&cmd.args, - "--unpack-unreachable"); + "--unpack-unreachable"); } else if (keep_unreachable) { strvec_push(&cmd.args, "--keep-unreachable"); strvec_push(&cmd.args, "--pack-loose-unreachable"); diff --git a/builtin/stash.c b/builtin/stash.c index 05c086e..bfdbafa 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -336,7 +336,7 @@ static int get_newly_staged(struct strbuf *out, struct object_id *c_tree) */ cp.git_cmd = 1; strvec_pushl(&cp.args, "diff-index", "--cached", "--name-only", - "--diff-filter=A", NULL); + "--diff-filter=A", NULL); strvec_push(&cp.args, c_tree_hex); return pipe_command(&cp, NULL, 0, out, 0, NULL, 0); } @@ -368,7 +368,7 @@ static int restore_untracked(struct object_id *u_tree) strvec_push(&cp.args, "read-tree"); strvec_push(&cp.args, oid_to_hex(u_tree)); strvec_pushf(&cp.env_array, "GIT_INDEX_FILE=%s", - stash_index_path.buf); + stash_index_path.buf); if (run_command(&cp)) { remove_path(stash_index_path.buf); return -1; @@ -378,7 +378,7 @@ static int restore_untracked(struct object_id *u_tree) cp.git_cmd = 1; strvec_pushl(&cp.args, "checkout-index", "--all", NULL); strvec_pushf(&cp.env_array, "GIT_INDEX_FILE=%s", - stash_index_path.buf); + stash_index_path.buf); res = run_command(&cp); remove_path(stash_index_path.buf); @@ -500,9 +500,9 @@ static int do_apply_stash(const char *prefix, struct stash_info *info, cp.git_cmd = 1; cp.dir = prefix; strvec_pushf(&cp.env_array, GIT_WORK_TREE_ENVIRONMENT"=%s", - absolute_path(get_git_work_tree())); + absolute_path(get_git_work_tree())); strvec_pushf(&cp.env_array, GIT_DIR_ENVIRONMENT"=%s", - absolute_path(get_git_dir())); + absolute_path(get_git_dir())); strvec_push(&cp.args, "status"); run_command(&cp); } @@ -547,7 +547,7 @@ static int do_drop_stash(struct stash_info *info, int quiet) cp_reflog.git_cmd = 1; strvec_pushl(&cp_reflog.args, "reflog", "delete", "--updateref", - "--rewrite", NULL); + "--rewrite", NULL); strvec_push(&cp_reflog.args, info->revision.buf); ret = run_command(&cp_reflog); if (!ret) { @@ -693,7 +693,7 @@ static int list_stash(int argc, const char **argv, const char *prefix) cp.git_cmd = 1; strvec_pushl(&cp.args, "log", "--format=%gd: %gs", "-g", - "--first-parent", "-m", NULL); + "--first-parent", "-m", NULL); strvec_pushv(&cp.args, argv); strvec_push(&cp.args, ref_stash); strvec_push(&cp.args, "--"); @@ -961,7 +961,7 @@ static int save_untracked_files(struct stash_info *info, struct strbuf *msg, cp_upd_index.git_cmd = 1; strvec_pushl(&cp_upd_index.args, "update-index", "-z", "--add", - "--remove", "--stdin", NULL); + "--remove", "--stdin", NULL); strvec_pushf(&cp_upd_index.env_array, "GIT_INDEX_FILE=%s", stash_index_path.buf); @@ -1005,7 +1005,7 @@ static int stash_patch(struct stash_info *info, const struct pathspec *ps, cp_read_tree.git_cmd = 1; strvec_pushl(&cp_read_tree.args, "read-tree", "HEAD", NULL); strvec_pushf(&cp_read_tree.env_array, "GIT_INDEX_FILE=%s", - stash_index_path.buf); + stash_index_path.buf); if (run_command(&cp_read_tree)) { ret = -1; goto done; @@ -1035,7 +1035,7 @@ static int stash_patch(struct stash_info *info, const struct pathspec *ps, cp_diff_tree.git_cmd = 1; strvec_pushl(&cp_diff_tree.args, "diff-tree", "-p", "-U1", "HEAD", - oid_to_hex(&info->w_tree), "--", NULL); + oid_to_hex(&info->w_tree), "--", NULL); if (pipe_command(&cp_diff_tree, NULL, 0, out_patch, 0, NULL, 0)) { ret = -1; goto done; @@ -1089,10 +1089,10 @@ static int stash_working_tree(struct stash_info *info, const struct pathspec *ps cp_upd_index.git_cmd = 1; strvec_pushl(&cp_upd_index.args, "update-index", - "--ignore-skip-worktree-entries", - "-z", "--add", "--remove", "--stdin", NULL); + "--ignore-skip-worktree-entries", + "-z", "--add", "--remove", "--stdin", NULL); strvec_pushf(&cp_upd_index.env_array, "GIT_INDEX_FILE=%s", - stash_index_path.buf); + stash_index_path.buf); if (pipe_command(&cp_upd_index, diff_output.buf, diff_output.len, NULL, 0, NULL, 0)) { @@ -1343,7 +1343,7 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q cp.git_cmd = 1; strvec_pushl(&cp.args, "clean", "--force", - "--quiet", "-d", NULL); + "--quiet", "-d", NULL); if (include_untracked == INCLUDE_ALL_FILES) strvec_push(&cp.args, "-x"); if (run_command(&cp)) { @@ -1373,8 +1373,8 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q cp_diff.git_cmd = 1; strvec_pushl(&cp_diff.args, "diff-index", "-p", - "--cached", "--binary", "HEAD", "--", - NULL); + "--cached", "--binary", "HEAD", "--", + NULL); add_pathspecs(&cp_diff.args, ps); if (pipe_command(&cp_diff, NULL, 0, &out, 0, NULL, 0)) { ret = -1; @@ -1383,7 +1383,7 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q cp_apply.git_cmd = 1; strvec_pushl(&cp_apply.args, "apply", "--index", - "-R", NULL); + "-R", NULL); if (pipe_command(&cp_apply, out.buf, out.len, NULL, 0, NULL, 0)) { ret = -1; @@ -1393,7 +1393,7 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q struct child_process cp = CHILD_PROCESS_INIT; cp.git_cmd = 1; strvec_pushl(&cp.args, "reset", "--hard", "-q", - "--no-recurse-submodules", NULL); + "--no-recurse-submodules", NULL); if (run_command(&cp)) { ret = -1; goto done; @@ -1405,7 +1405,7 @@ static int do_push_stash(const struct pathspec *ps, const char *stash_msg, int q cp.git_cmd = 1; strvec_pushl(&cp.args, "checkout", "--no-overlay", - oid_to_hex(&info.i_tree), "--", NULL); + oid_to_hex(&info.i_tree), "--", NULL); if (!ps->nr) strvec_push(&cp.args, ":/"); else diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 7705e8e..665db1f 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -499,7 +499,7 @@ static void runcommand_in_submodule_cb(const struct cache_entry *list_item, strvec_pushf(&cp.env_array, "sm_path=%s", path); strvec_pushf(&cp.env_array, "displaypath=%s", displaypath); strvec_pushf(&cp.env_array, "sha1=%s", - oid_to_hex(ce_oid)); + oid_to_hex(ce_oid)); strvec_pushf(&cp.env_array, "toplevel=%s", toplevel); /* @@ -513,7 +513,7 @@ static void runcommand_in_submodule_cb(const struct cache_entry *list_item, */ sq_quote_buf(&sb, path); strvec_pushf(&cp.args, "path=%s; %s", - sb.buf, info->argv[0]); + sb.buf, info->argv[0]); strbuf_release(&sb); free(toplevel); } else { @@ -537,7 +537,7 @@ static void runcommand_in_submodule_cb(const struct cache_entry *list_item, strvec_pushl(&cpr.args, "--super-prefix", NULL); strvec_pushf(&cpr.args, "%s/", displaypath); strvec_pushl(&cpr.args, "submodule--helper", "foreach", "--recursive", - NULL); + NULL); if (info->quiet) strvec_push(&cpr.args, "--quiet"); @@ -810,8 +810,8 @@ static void status_submodule(const char *path, const struct object_id *ce_oid, strbuf_release(&buf); strvec_pushl(&diff_files_args, "diff-files", - "--ignore-submodules=dirty", "--quiet", "--", - path, NULL); + "--ignore-submodules=dirty", "--quiet", "--", + path, NULL); git_config(git_diff_basic_config, NULL); @@ -852,7 +852,7 @@ static void status_submodule(const char *path, const struct object_id *ce_oid, strvec_push(&cpr.args, "--super-prefix"); strvec_pushf(&cpr.args, "%s/", displaypath); strvec_pushl(&cpr.args, "submodule--helper", "status", - "--recursive", NULL); + "--recursive", NULL); if (flags & OPT_CACHED) strvec_push(&cpr.args, "--cached"); @@ -996,7 +996,7 @@ static void sync_submodule(const char *path, const char *prefix, cp.git_cmd = 1; cp.dir = path; strvec_pushl(&cp.args, "submodule--helper", - "print-default-remote", NULL); + "print-default-remote", NULL); strbuf_reset(&sb); if (capture_command(&cp, &sb, 0)) @@ -1024,7 +1024,7 @@ static void sync_submodule(const char *path, const char *prefix, strvec_push(&cpr.args, "--super-prefix"); strvec_pushf(&cpr.args, "%s/", displaypath); strvec_pushl(&cpr.args, "submodule--helper", "sync", - "--recursive", NULL); + "--recursive", NULL); if (flags & OPT_QUIET) strvec_push(&cpr.args, "--quiet"); @@ -1128,7 +1128,7 @@ static void deinit_submodule(const char *path, const char *prefix, struct child_process cp_rm = CHILD_PROCESS_INIT; cp_rm.git_cmd = 1; strvec_pushl(&cp_rm.args, "rm", "-qn", - path, NULL); + path, NULL); if (run_command(&cp_rm)) die(_("Submodule work tree '%s' contains local " @@ -1251,7 +1251,7 @@ static int clone_submodule(const char *path, const char *gitdir, const char *url struct string_list_item *item; for_each_string_list_item(item, reference) strvec_pushl(&cp.args, "--reference", - item->string, NULL); + item->string, NULL); } if (dissociate) strvec_push(&cp.args, "--dissociate"); diff --git a/builtin/worktree.c b/builtin/worktree.c index 3c483c2..be5d84f 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -414,10 +414,10 @@ static int add_worktree(const char *path, const char *refname, if (!is_branch) strvec_pushl(&cp.args, "update-ref", "HEAD", - oid_to_hex(&commit->object.oid), NULL); + oid_to_hex(&commit->object.oid), NULL); else { strvec_pushl(&cp.args, "symbolic-ref", "HEAD", - symref.buf, NULL); + symref.buf, NULL); if (opts->quiet) strvec_push(&cp.args, "--quiet"); } @@ -466,9 +466,9 @@ done: cp.argv = NULL; cp.trace2_hook_name = "post-checkout"; strvec_pushl(&cp.args, absolute_path(hook), - oid_to_hex(&null_oid), - oid_to_hex(&commit->object.oid), - "1", NULL); + oid_to_hex(&null_oid), + oid_to_hex(&commit->object.oid), + "1", NULL); ret = run_command(&cp); } } @@ -936,13 +936,13 @@ static void check_clean_worktree(struct worktree *wt, validate_no_submodules(wt); strvec_pushf(&child_env, "%s=%s/.git", - GIT_DIR_ENVIRONMENT, wt->path); + GIT_DIR_ENVIRONMENT, wt->path); strvec_pushf(&child_env, "%s=%s", - GIT_WORK_TREE_ENVIRONMENT, wt->path); + GIT_WORK_TREE_ENVIRONMENT, wt->path); memset(&cp, 0, sizeof(cp)); strvec_pushl(&cp.args, "status", - "--porcelain", "--ignore-submodules=none", - NULL); + "--porcelain", "--ignore-submodules=none", + NULL); cp.env = child_env.argv; cp.git_cmd = 1; cp.dir = wt->path; diff --git a/bundle.c b/bundle.c index 709b2ab..565d053 100644 --- a/bundle.c +++ b/bundle.c @@ -275,9 +275,9 @@ static int write_pack_data(int bundle_fd, struct rev_info *revs, struct strvec * int i; strvec_pushl(&pack_objects.args, - "pack-objects", - "--stdout", "--thin", "--delta-base-offset", - NULL); + "pack-objects", + "--stdout", "--thin", "--delta-base-offset", + NULL); strvec_pushv(&pack_objects.args, pack_options->argv); pack_objects.in = -1; pack_objects.out = bundle_fd; @@ -322,8 +322,8 @@ static int compute_and_write_prerequisites(int bundle_fd, int i; strvec_pushl(&rls.args, - "rev-list", "--boundary", "--pretty=oneline", - NULL); + "rev-list", "--boundary", "--pretty=oneline", + NULL); for (i = 1; i < argc; i++) strvec_push(&rls.args, argv[i]); rls.out = -1; diff --git a/connect.c b/connect.c index 9b453fe..3299ea9 100644 --- a/connect.c +++ b/connect.c @@ -1208,7 +1208,7 @@ static void push_ssh_options(struct strvec *args, struct strvec *env, strvec_push(args, "-o"); strvec_push(args, "SendEnv=" GIT_PROTOCOL_ENVIRONMENT); strvec_pushf(env, GIT_PROTOCOL_ENVIRONMENT "=version=%d", - version); + version); } if (flags & CONNECT_IPV4) { @@ -1397,8 +1397,9 @@ struct child_process *git_connect(int fd[2], const char *url, transport_check_allowed("file"); conn->trace2_child_class = "transport/file"; if (version > 0) { - strvec_pushf(&conn->env_array, GIT_PROTOCOL_ENVIRONMENT "=version=%d", - version); + strvec_pushf(&conn->env_array, + GIT_PROTOCOL_ENVIRONMENT "=version=%d", + version); } } strvec_push(&conn->args, cmd.buf); diff --git a/connected.c b/connected.c index 96b4787..21c1ebe 100644 --- a/connected.c +++ b/connected.c @@ -106,7 +106,7 @@ no_promisor_pack_found: strvec_push(&rev_list.args, "--alternate-refs"); if (opt->progress) strvec_pushf(&rev_list.args, "--progress=%s", - _("Checking connectivity")); + _("Checking connectivity")); rev_list.git_cmd = 1; rev_list.env = opt->env; diff --git a/daemon.c b/daemon.c index cea5f53..0dec89f 100644 --- a/daemon.c +++ b/daemon.c @@ -665,7 +665,7 @@ static void parse_extra_args(struct hostinfo *hi, struct strvec *env, if (git_protocol.len > 0) { loginfo("Extended attribute \"protocol\": %s", git_protocol.buf); strvec_pushf(env, GIT_PROTOCOL_ENVIRONMENT "=%s", - git_protocol.buf); + git_protocol.buf); } strbuf_release(&git_protocol); } @@ -915,7 +915,7 @@ static void handle(int incoming, struct sockaddr *addr, socklen_t addrlen) inet_ntop(addr->sa_family, &sin_addr->sin_addr, buf, sizeof(buf)); strvec_pushf(&cld.env_array, "REMOTE_ADDR=%s", buf); strvec_pushf(&cld.env_array, "REMOTE_PORT=%d", - ntohs(sin_addr->sin_port)); + ntohs(sin_addr->sin_port)); #ifndef NO_IPV6 } else if (addr->sa_family == AF_INET6) { char buf[128] = ""; @@ -923,7 +923,7 @@ static void handle(int incoming, struct sockaddr *addr, socklen_t addrlen) inet_ntop(AF_INET6, &sin6_addr->sin6_addr, buf, sizeof(buf)); strvec_pushf(&cld.env_array, "REMOTE_ADDR=[%s]", buf); strvec_pushf(&cld.env_array, "REMOTE_PORT=%d", - ntohs(sin6_addr->sin6_port)); + ntohs(sin6_addr->sin6_port)); #endif } diff --git a/fetch-pack.c b/fetch-pack.c index 7aa5dfb..7f20eca 100644 --- a/fetch-pack.c +++ b/fetch-pack.c @@ -854,8 +854,8 @@ static int get_pack(struct fetch_pack_args *args, if (xgethostname(hostname, sizeof(hostname))) xsnprintf(hostname, sizeof(hostname), "localhost"); strvec_pushf(&cmd.args, - "--keep=fetch-pack %"PRIuMAX " on %s", - (uintmax_t)getpid(), hostname); + "--keep=fetch-pack %"PRIuMAX " on %s", + (uintmax_t)getpid(), hostname); } if (only_packfile && args->check_self_contained_and_connected) strvec_push(&cmd.args, "--check-self-contained-and-connected"); @@ -885,7 +885,7 @@ static int get_pack(struct fetch_pack_args *args, if (pass_header) strvec_pushf(&cmd.args, "--pack_header=%"PRIu32",%"PRIu32, - ntohl(header.hdr_version), + ntohl(header.hdr_version), ntohl(header.hdr_entries)); if (fetch_fsck_objects >= 0 ? fetch_fsck_objects @@ -901,7 +901,7 @@ static int get_pack(struct fetch_pack_args *args, strvec_push(&cmd.args, "--fsck-objects"); else strvec_pushf(&cmd.args, "--strict%s", - fsck_msg_types.buf); + fsck_msg_types.buf); } cmd.in = demux.out; @@ -1654,8 +1654,8 @@ static struct ref *do_fetch_pack_v2(struct fetch_pack_args *args, strvec_push(&cmd.args, "http-fetch"); strvec_pushf(&cmd.args, "--packfile=%.*s", - (int) the_hash_algo->hexsz, - packfile_uris.items[i].string); + (int) the_hash_algo->hexsz, + packfile_uris.items[i].string); strvec_push(&cmd.args, uri); cmd.git_cmd = 1; cmd.no_stdin = 1; diff --git a/gpg-interface.c b/gpg-interface.c index cf56fe8..b499270 100644 --- a/gpg-interface.c +++ b/gpg-interface.c @@ -285,9 +285,9 @@ static int verify_signed_buffer(const char *payload, size_t payload_size, strvec_push(&gpg.args, fmt->program); strvec_pushv(&gpg.args, fmt->verify_args); strvec_pushl(&gpg.args, - "--status-fd=1", - "--verify", temp->filename.buf, "-", - NULL); + "--status-fd=1", + "--verify", temp->filename.buf, "-", + NULL); if (!gpg_status) gpg_status = &buf; @@ -435,10 +435,10 @@ int sign_buffer(struct strbuf *buffer, struct strbuf *signature, const char *sig struct strbuf gpg_status = STRBUF_INIT; strvec_pushl(&gpg.args, - use_format->program, - "--status-fd=2", - "-bsau", signing_key, - NULL); + use_format->program, + "--status-fd=2", + "-bsau", signing_key, + NULL); bottom = signature->len; diff --git a/http-backend.c b/http-backend.c index 92fd62f..a03b4ba 100644 --- a/http-backend.c +++ b/http-backend.c @@ -480,7 +480,7 @@ static void run_service(const char **argv, int buffer_input) strvec_pushf(&cld.env_array, "GIT_COMMITTER_NAME=%s", user); if (!getenv("GIT_COMMITTER_EMAIL")) strvec_pushf(&cld.env_array, - "GIT_COMMITTER_EMAIL=%s@http.%s", user, host); + "GIT_COMMITTER_EMAIL=%s@http.%s", user, host); cld.argv = argv; if (buffer_input || gzipped_request || req_len >= 0) diff --git a/http-push.c b/http-push.c index e1deea6..31911aa 100644 --- a/http-push.c +++ b/http-push.c @@ -1929,7 +1929,7 @@ int cmd_main(int argc, const char **argv) strvec_push(&commit_argv, oid_to_hex(&ref->new_oid)); if (!push_all && !is_null_oid(&ref->old_oid)) strvec_pushf(&commit_argv, "^%s", - oid_to_hex(&ref->old_oid)); + oid_to_hex(&ref->old_oid)); repo_init_revisions(the_repository, &revs, setup_git_directory()); setup_revisions(commit_argv.argc, commit_argv.argv, &revs, NULL); revs.edge_hint = 0; /* just in case */ diff --git a/http.c b/http.c index 268a1e9..8b23a54 100644 --- a/http.c +++ b/http.c @@ -2276,7 +2276,7 @@ int finish_http_pack_request(struct http_pack_request *preq) ip.in = tmpfile_fd; if (preq->generate_keep) { strvec_pushf(&ip.args, "--keep=git %"PRIuMAX, - (uintmax_t)getpid()); + (uintmax_t)getpid()); ip.out = 0; } else { ip.no_stdout = 1; diff --git a/range-diff.c b/range-diff.c index 3a0eb70..831c490 100644 --- a/range-diff.c +++ b/range-diff.c @@ -52,20 +52,20 @@ static int read_patches(const char *range, struct string_list *list, size_t size; strvec_pushl(&cp.args, "log", "--no-color", "-p", "--no-merges", - "--reverse", "--date-order", "--decorate=no", - "--no-prefix", - /* - * Choose indicators that are not used anywhere - * else in diffs, but still look reasonable - * (e.g. will not be confusing when debugging) - */ - "--output-indicator-new=>", - "--output-indicator-old=<", - "--output-indicator-context=#", - "--no-abbrev-commit", - "--pretty=medium", - "--notes", - NULL); + "--reverse", "--date-order", "--decorate=no", + "--no-prefix", + /* + * Choose indicators that are not used anywhere + * else in diffs, but still look reasonable + * (e.g. will not be confusing when debugging) + */ + "--output-indicator-new=>", + "--output-indicator-old=<", + "--output-indicator-context=#", + "--no-abbrev-commit", + "--pretty=medium", + "--notes", + NULL); if (other_arg) strvec_pushv(&cp.args, other_arg->argv); strvec_push(&cp.args, range); diff --git a/refspec.c b/refspec.c index 6f317d6..f10ef28 100644 --- a/refspec.c +++ b/refspec.c @@ -222,8 +222,8 @@ void refspec_ref_prefixes(const struct refspec *rs, if (item->pattern) { const char *glob = strchr(prefix, '*'); strvec_pushf(ref_prefixes, "%.*s", - (int)(glob - prefix), - prefix); + (int)(glob - prefix), + prefix); } else { expand_ref_prefix(ref_prefixes, prefix); } diff --git a/remote-curl.c b/remote-curl.c index 85ce4f7..7feaddc 100644 --- a/remote-curl.c +++ b/remote-curl.c @@ -1145,7 +1145,7 @@ static int fetch_git(struct discovery *heads, struct strbuf rpc_result = STRBUF_INIT; strvec_pushl(&args, "fetch-pack", "--stateless-rpc", - "--stdin", "--lock-pack", NULL); + "--stdin", "--lock-pack", NULL); if (options.followtags) strvec_push(&args, "--include-tag"); if (options.thin) @@ -1166,7 +1166,7 @@ static int fetch_git(struct discovery *heads, strvec_pushf(&args, "--shallow-since=%s", options.deepen_since); for (i = 0; i < options.deepen_not.nr; i++) strvec_pushf(&args, "--shallow-exclude=%s", - options.deepen_not.items[i].string); + options.deepen_not.items[i].string); if (options.deepen_relative && options.depth) strvec_push(&args, "--deepen-relative"); if (options.from_promisor) @@ -1293,7 +1293,7 @@ static int push_git(struct discovery *heads, int nr_spec, const char **specs) strvec_init(&args); strvec_pushl(&args, "send-pack", "--stateless-rpc", "--helper-status", - NULL); + NULL); if (options.thin) strvec_push(&args, "--thin"); @@ -1311,7 +1311,7 @@ static int push_git(struct discovery *heads, int nr_spec, const char **specs) strvec_push(&args, "--verbose"); for (i = 0; i < options.push_options.nr; i++) strvec_pushf(&args, "--push-option=%s", - options.push_options.items[i].string); + options.push_options.items[i].string); strvec_push(&args, options.progress ? "--progress" : "--no-progress"); for_each_string_list_item(cas_option, &cas_options) strvec_push(&args, cas_option->string); diff --git a/remote.c b/remote.c index 13b0978..b4665fe 100644 --- a/remote.c +++ b/remote.c @@ -1914,8 +1914,8 @@ static int stat_branch_pair(const char *branch_name, const char *base, strvec_push(&argv, ""); /* ignored */ strvec_push(&argv, "--left-right"); strvec_pushf(&argv, "%s...%s", - oid_to_hex(&ours->object.oid), - oid_to_hex(&theirs->object.oid)); + oid_to_hex(&ours->object.oid), + oid_to_hex(&theirs->object.oid)); strvec_push(&argv, "--"); repo_init_revisions(the_repository, &revs, NULL); diff --git a/sequencer.c b/sequencer.c index 80c7709..31a2b1a 100644 --- a/sequencer.c +++ b/sequencer.c @@ -3133,7 +3133,7 @@ static int do_exec(struct repository *r, const char *command_line) child_argv[0] = command_line; strvec_pushf(&child_env, "GIT_DIR=%s", absolute_path(get_git_dir())); strvec_pushf(&child_env, "GIT_WORK_TREE=%s", - absolute_path(get_git_work_tree())); + absolute_path(get_git_work_tree())); status = run_command_v_opt_cd_env(child_argv, RUN_USING_SHELL, NULL, child_env.argv); @@ -3552,7 +3552,7 @@ static int do_merge(struct repository *r, strvec_push(&cmd.args, strategy); for (k = 0; k < opts->xopts_nr; k++) strvec_pushf(&cmd.args, - "-X%s", opts->xopts[k]); + "-X%s", opts->xopts[k]); } strvec_push(&cmd.args, "--no-edit"); strvec_push(&cmd.args, "--no-ff"); @@ -3566,7 +3566,7 @@ static int do_merge(struct repository *r, /* Add the tips to be merged */ for (j = to_merge; j; j = j->next) strvec_push(&cmd.args, - oid_to_hex(&j->item->object.oid)); + oid_to_hex(&j->item->object.oid)); strbuf_release(&ref_name); unlink(git_path_cherry_pick_head(r)); @@ -3695,7 +3695,7 @@ void create_autostash(struct repository *r, const char *path, struct object_id oid; strvec_pushl(&stash.args, - "stash", "create", "autostash", NULL); + "stash", "create", "autostash", NULL); stash.git_cmd = 1; stash.no_stdin = 1; strbuf_reset(&buf); diff --git a/submodule.c b/submodule.c index 5c94474..fb96d59 100644 --- a/submodule.c +++ b/submodule.c @@ -495,7 +495,7 @@ void prepare_submodule_repo_env(struct strvec *out) { prepare_submodule_repo_env_no_git_dir(out); strvec_pushf(out, "%s=%s", GIT_DIR_ENVIRONMENT, - DEFAULT_GIT_DIR_ENVIRONMENT); + DEFAULT_GIT_DIR_ENVIRONMENT); } static void prepare_submodule_repo_env_in_gitdir(struct strvec *out) @@ -687,14 +687,14 @@ void show_submodule_inline_diff(struct diff_options *o, const char *path, if (o->flags.reverse_diff) { strvec_pushf(&cp.args, "--src-prefix=%s%s/", - o->b_prefix, path); + o->b_prefix, path); strvec_pushf(&cp.args, "--dst-prefix=%s%s/", - o->a_prefix, path); + o->a_prefix, path); } else { strvec_pushf(&cp.args, "--src-prefix=%s%s/", - o->a_prefix, path); + o->a_prefix, path); strvec_pushf(&cp.args, "--dst-prefix=%s%s/", - o->b_prefix, path); + o->b_prefix, path); } strvec_push(&cp.args, oid_to_hex(old_oid)); /* @@ -1062,7 +1062,7 @@ static int push_submodule(const char *path, const struct string_list_item *item; for_each_string_list_item(item, push_options) strvec_pushf(&cp.args, "--push-option=%s", - item->string); + item->string); } if (remote->origin != REMOTE_UNCONFIGURED) { @@ -1780,7 +1780,7 @@ int bad_to_remove_submodule(const char *path, unsigned flags) return 1; strvec_pushl(&cp.args, "status", "--porcelain", - "--ignore-submodules=none", NULL); + "--ignore-submodules=none", NULL); if (flags & SUBMODULE_REMOVAL_IGNORE_UNTRACKED) strvec_push(&cp.args, "-uno"); @@ -1847,7 +1847,7 @@ static int submodule_has_dirty_index(const struct submodule *sub) cp.git_cmd = 1; strvec_pushl(&cp.args, "diff-index", "--quiet", - "--cached", "HEAD", NULL); + "--cached", "HEAD", NULL); cp.no_stdin = 1; cp.no_stdout = 1; cp.dir = sub->path; @@ -1867,7 +1867,7 @@ static void submodule_reset_index(const char *path) cp.dir = path; strvec_pushf(&cp.args, "--super-prefix=%s%s/", - get_super_prefix_or_empty(), path); + get_super_prefix_or_empty(), path); strvec_pushl(&cp.args, "read-tree", "-u", "--reset", NULL); strvec_push(&cp.args, empty_tree_oid_hex()); @@ -1948,7 +1948,7 @@ int submodule_move_head(const char *path, cp.dir = path; strvec_pushf(&cp.args, "--super-prefix=%s%s/", - get_super_prefix_or_empty(), path); + get_super_prefix_or_empty(), path); strvec_pushl(&cp.args, "read-tree", "--recurse-submodules", NULL); if (flags & SUBMODULE_MOVE_HEAD_DRY_RUN) @@ -1981,7 +1981,7 @@ int submodule_move_head(const char *path, prepare_submodule_repo_env(&cp.env_array); strvec_pushl(&cp.args, "update-ref", "HEAD", - "--no-deref", new_head, NULL); + "--no-deref", new_head, NULL); if (run_command(&cp)) { ret = -1; @@ -2158,8 +2158,8 @@ void absorb_git_dir_into_superproject(const char *path, cp.git_cmd = 1; cp.no_stdin = 1; strvec_pushl(&cp.args, "--super-prefix", sb.buf, - "submodule--helper", - "absorb-git-dirs", NULL); + "submodule--helper", + "absorb-git-dirs", NULL); prepare_submodule_repo_env(&cp.env_array); if (run_command(&cp)) die(_("could not recurse into submodule '%s'"), path); @@ -2197,8 +2197,8 @@ int get_superproject_working_tree(struct strbuf *buf) strvec_pop(&cp.env_array); strvec_pushl(&cp.args, "--literal-pathspecs", "-C", "..", - "ls-files", "-z", "--stage", "--full-name", "--", - subpath, NULL); + "ls-files", "-z", "--stage", "--full-name", "--", + subpath, NULL); strbuf_reset(&sb); cp.no_stdin = 1; diff --git a/t/helper/test-run-command.c b/t/helper/test-run-command.c index 67dde56..726835f 100644 --- a/t/helper/test-run-command.c +++ b/t/helper/test-run-command.c @@ -244,10 +244,10 @@ static int quote_stress_test(int argc, const char **argv) strvec_clear(&args); if (msys2) strvec_pushl(&args, "sh", "-c", - "printf %s\\\\0 \"$@\"", "skip", NULL); + "printf %s\\\\0 \"$@\"", "skip", NULL); else strvec_pushl(&args, "test-tool", "run-command", - "quote-echo", NULL); + "quote-echo", NULL); arg_offset = args.argc; if (argc > 0) { @@ -339,7 +339,7 @@ static int inherit_handle(const char *argv0) tmp = xmkstemp(path); strvec_pushl(&cp.args, - "test-tool", argv0, "inherited-handle-child", NULL); + "test-tool", argv0, "inherited-handle-child", NULL); cp.in = -1; cp.no_stdout = cp.no_stderr = 1; if (start_command(&cp) < 0) diff --git a/transport-helper.c b/transport-helper.c index dcd4adf..ae8011e 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -136,7 +136,7 @@ static struct child_process *get_helper(struct transport *transport) if (have_git_dir()) strvec_pushf(&helper->env_array, "%s=%s", - GIT_DIR_ENVIRONMENT, get_git_dir()); + GIT_DIR_ENVIRONMENT, get_git_dir()); helper->trace2_child_class = helper->args.argv[0]; /* "remote-" */ diff --git a/upload-pack.c b/upload-pack.c index 1b0e1fc..4a7918e 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -301,8 +301,7 @@ static void create_pack_file(struct upload_pack_data *pack_data, strvec_pushf(&pack_objects.args, "--filter=%s", buf.buf); strbuf_release(&buf); } else { - strvec_pushf(&pack_objects.args, "--filter=%s", - spec); + strvec_pushf(&pack_objects.args, "--filter=%s", spec); } } if (uri_protocols) { diff --git a/wt-status.c b/wt-status.c index 60d4e84..8454662 100644 --- a/wt-status.c +++ b/wt-status.c @@ -913,8 +913,7 @@ static void wt_longstatus_print_submodule_summary(struct wt_status *s, int uncom struct strbuf summary = STRBUF_INIT; char *summary_content; - strvec_pushf(&sm_summary.env_array, "GIT_INDEX_FILE=%s", - s->index_file); + strvec_pushf(&sm_summary.env_array, "GIT_INDEX_FILE=%s", s->index_file); strvec_push(&sm_summary.args, "submodule"); strvec_push(&sm_summary.args, "summary"); -- cgit v0.10.2-6-g49f6 From 837dc425cf1216a97aaeb5137b743dac766fd79d Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 28 Jul 2020 16:26:57 -0400 Subject: strvec: update documention to avoid argv_array There were a few mentions of argv_array in a non-code file which didn't get picked up in the previous commits (note that even comments in code files were already covered because of the mechanical conversion via perl). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano diff --git a/Documentation/technical/api-parse-options.txt b/Documentation/technical/api-parse-options.txt index 2e2e7c1..5a60bbf 100644 --- a/Documentation/technical/api-parse-options.txt +++ b/Documentation/technical/api-parse-options.txt @@ -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. -- cgit v0.10.2-6-g49f6 From b5eb741a00155f888a9a4ced87c840a2b7b04f5a Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 28 Jul 2020 16:27:09 -0400 Subject: strvec: drop argv_array compatibility layer There are no callers which need it anymore. Any topics in flight will need to be updated as they get merged in (but the compiler will make that quite clear). Signed-off-by: Jeff King Signed-off-by: Junio C Hamano diff --git a/strvec.h b/strvec.h index 4be39c8..bd35de1 100644 --- a/strvec.h +++ b/strvec.h @@ -86,17 +86,4 @@ void strvec_clear(struct strvec *); */ const char **strvec_detach(struct strvec *); -/* compatibility for historic argv_array interface */ -#define argv_array strvec -#define ARGV_ARRAY_INIT STRVEC_INIT -#define argv_array_init strvec_init -#define argv_array_push strvec_push -#define argv_array_pushf strvec_pushf -#define argv_array_pushl strvec_pushl -#define argv_array_pushv strvec_pushv -#define argv_array_pop strvec_pop -#define argv_array_split strvec_split -#define argv_array_clear strvec_clear -#define argv_array_detach strvec_detach - #endif /* STRVEC_H */ -- cgit v0.10.2-6-g49f6 From d70a9eb611a9d242c1d26847d223b8677609305b Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 28 Jul 2020 20:37:20 -0400 Subject: strvec: rename struct fields The "argc" and "argv" names made sense when the struct was argv_array, but now they're just confusing. Let's rename them to "nr" (which we use for counts elsewhere) and "v" (which is rather terse, but reads well when combined with typical variable names like "args.v"). Note that we have to update all of the callers immediately. Playing tricks with the preprocessor is hard here, because we wouldn't want to rewrite unrelated tokens. Signed-off-by: Jeff King Signed-off-by: Junio C Hamano diff --git a/add-interactive.c b/add-interactive.c index 458f3a3..555c4ab 100644 --- a/add-interactive.c +++ b/add-interactive.c @@ -944,7 +944,7 @@ static int run_patch(struct add_i_state *s, const struct pathspec *ps, 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); strvec_clear(&args); clear_pathspec(&ps_selected); @@ -986,7 +986,7 @@ static int run_diff(struct add_i_state *s, const struct pathspec *ps, if (files->selected[i]) strvec_push(&args, files->items.items[i].string); - res = run_command_v_opt(args.argv, 0); + res = run_command_v_opt(args.v, 0); strvec_clear(&args); } diff --git a/add-patch.c b/add-patch.c index 8c07728..0f68eb6 100644 --- a/add-patch.c +++ b/add-patch.c @@ -391,14 +391,14 @@ static int parse_diff(struct add_p_state *s, const struct pathspec *ps) 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`. */ strvec_pushl(&args, "--no-color", "-p", "--", NULL); for (i = 0; i < ps->nr; i++) 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) { strvec_clear(&args); @@ -415,8 +415,8 @@ 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); strvec_clear(&args); diff --git a/bisect.c b/bisect.c index 99ff694..6959fb8 100644 --- a/bisect.c +++ b/bisect.c @@ -649,7 +649,7 @@ static void bisect_rev_setup(struct repository *r, struct rev_info *revs, 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 */ } diff --git a/builtin/add.c b/builtin/add.c index 6185dd1..ab39a60 100644 --- a/builtin/add.c +++ b/builtin/add.c @@ -228,7 +228,7 @@ int run_add_interactive(const char *revision, const char *patch_mode, /* pass original pathspec, to be re-parsed */ strvec_push(&argv, pathspec->items[i].original); - status = run_command_v_opt(argv.argv, RUN_GIT_CMD); + status = run_command_v_opt(argv.v, RUN_GIT_CMD); strvec_clear(&argv); return status; } diff --git a/builtin/am.c b/builtin/am.c index 992ab3c..dd4e6c2 100644 --- a/builtin/am.c +++ b/builtin/am.c @@ -812,7 +812,7 @@ static int split_mail_stgit_series(struct am_state *state, const char **paths, strbuf_release(&sb); free(series_dir_buf); - ret = split_mail_conv(stgit_patch_to_mail, state, patches.argv, keep_cr); + ret = split_mail_conv(stgit_patch_to_mail, state, patches.v, keep_cr); strvec_clear(&patches); return ret; @@ -1002,7 +1002,7 @@ static void am_setup(struct am_state *state, enum patch_format patch_format, } write_state_text(state, "scissors", str); - sq_quote_argv(&sb, state->git_apply_opts.argv); + sq_quote_argv(&sb, state->git_apply_opts.v); write_state_text(state, "apply-opt", sb.buf); if (state->rebasing) @@ -1401,9 +1401,9 @@ static int run_apply(const struct am_state *state, const char *index_file) BUG("init_apply_state() failed"); strvec_push(&apply_opts, "apply"); - strvec_pushv(&apply_opts, state->git_apply_opts.argv); + strvec_pushv(&apply_opts, state->git_apply_opts.v); - opts_left = apply_parse_options(apply_opts.argc, apply_opts.argv, + opts_left = apply_parse_options(apply_opts.nr, apply_opts.v, &apply_state, &force_apply, &options, NULL); @@ -1428,7 +1428,7 @@ static int run_apply(const struct am_state *state, const char *index_file) strvec_push(&apply_paths, am_path(state, "patch")); - res = apply_all_patches(&apply_state, apply_paths.argc, apply_paths.argv, options); + res = apply_all_patches(&apply_state, apply_paths.nr, apply_paths.v, options); strvec_clear(&apply_paths); strvec_clear(&apply_opts); @@ -1455,7 +1455,7 @@ static int build_fake_ancestor(const struct am_state *state, const char *index_f cp.git_cmd = 1; strvec_push(&cp.args, "apply"); - strvec_pushv(&cp.args, state->git_apply_opts.argv); + strvec_pushv(&cp.args, state->git_apply_opts.v); strvec_pushf(&cp.args, "--build-fake-ancestor=%s", index_file); strvec_push(&cp.args, am_path(state, "patch")); @@ -2376,10 +2376,10 @@ int cmd_am(int argc, const char **argv, const char *prefix) strvec_push(&paths, mkpath("%s/%s", prefix, argv[i])); } - if (state.interactive && !paths.argc) + if (state.interactive && !paths.nr) die(_("interactive mode requires patches on the command line")); - am_setup(&state, patch_format, paths.argv, keep_cr); + am_setup(&state, patch_format, paths.v, keep_cr); strvec_clear(&paths); } diff --git a/builtin/annotate.c b/builtin/annotate.c index 7b7ecd3..58ff977 100644 --- a/builtin/annotate.c +++ b/builtin/annotate.c @@ -18,5 +18,5 @@ int cmd_annotate(int argc, const char **argv, const char *prefix) strvec_push(&args, argv[i]); } - return cmd_blame(args.argc, args.argv, prefix); + return cmd_blame(args.nr, args.v, prefix); } diff --git a/builtin/bisect--helper.c b/builtin/bisect--helper.c index dd52878..b46de04 100644 --- a/builtin/bisect--helper.c +++ b/builtin/bisect--helper.c @@ -168,7 +168,7 @@ static int bisect_reset(const char *commit) struct strvec argv = STRVEC_INIT; strvec_pushl(&argv, "checkout", branch.buf, "--", NULL); - if (run_command_v_opt(argv.argv, RUN_GIT_CMD)) { + if (run_command_v_opt(argv.v, RUN_GIT_CMD)) { error(_("could not check out original" " HEAD '%s'. Try 'git bisect" " reset '."), branch.buf); @@ -530,7 +530,7 @@ static int bisect_start(struct bisect_terms *terms, int no_checkout, strvec_pushl(&argv, "checkout", start_head.buf, "--", NULL); - if (run_command_v_opt(argv.argv, RUN_GIT_CMD)) { + if (run_command_v_opt(argv.v, RUN_GIT_CMD)) { res = error(_("checking out '%s' failed." " Try 'git bisect start " "'."), diff --git a/builtin/clone.c b/builtin/clone.c index e26bd82..fccc814 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -752,7 +752,7 @@ static int git_sparse_checkout_init(const char *repo) */ core_apply_sparse_checkout = 1; - if (run_command_v_opt(argv.argv, RUN_GIT_CMD)) { + if (run_command_v_opt(argv.v, RUN_GIT_CMD)) { error(_("failed to initialize sparse-checkout")); result = 1; } @@ -844,7 +844,7 @@ static int checkout(int submodule_progress) "--single-branch" : "--no-single-branch"); - err = run_command_v_opt(args.argv, RUN_GIT_CMD); + err = run_command_v_opt(args.v, RUN_GIT_CMD); strvec_clear(&args); } diff --git a/builtin/commit.c b/builtin/commit.c index c3f4067..69ac78d 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -1008,7 +1008,7 @@ static int prepare_to_commit(const char *index_file, const char *prefix, struct strvec env = STRVEC_INIT; strvec_pushf(&env, "GIT_INDEX_FILE=%s", index_file); - if (launch_editor(git_path_commit_editmsg(), NULL, env.argv)) { + if (launch_editor(git_path_commit_editmsg(), NULL, env.v)) { fprintf(stderr, _("Please supply the message using either -m or -F option.\n")); exit(1); diff --git a/builtin/describe.c b/builtin/describe.c index e3cac80..7668591 100644 --- a/builtin/describe.c +++ b/builtin/describe.c @@ -509,7 +509,7 @@ static void describe_blob(struct object_id oid, struct strbuf *dst) NULL); repo_init_revisions(the_repository, &revs, NULL); - if (setup_revisions(args.argc, args.argv, &revs, NULL) > 1) + if (setup_revisions(args.nr, args.v, &revs, NULL) > 1) BUG("setup_revisions could not handle all args?"); if (prepare_revision_walk(&revs)) @@ -613,7 +613,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix) strvec_pushv(&args, argv); else strvec_push(&args, "HEAD"); - return cmd_name_rev(args.argc, args.argv, prefix); + return cmd_name_rev(args.nr, args.v, prefix); } hashmap_init(&names, commit_name_neq, NULL, 0); @@ -659,7 +659,7 @@ int cmd_describe(int argc, const char **argv, const char *prefix) repo_init_revisions(the_repository, &revs, prefix); strvec_pushv(&args, diff_index_args); - if (setup_revisions(args.argc, args.argv, &revs, NULL) != 1) + if (setup_revisions(args.nr, args.v, &revs, NULL) != 1) BUG("malformed internal diff-index command line"); result = run_diff_index(&revs, 0); diff --git a/builtin/difftool.c b/builtin/difftool.c index 5ac021a..7ac432b 100644 --- a/builtin/difftool.c +++ b/builtin/difftool.c @@ -683,7 +683,7 @@ static int run_file_diff(int prompt, const char *prefix, strvec_push(&args, "diff"); for (i = 0; i < argc; i++) strvec_push(&args, argv[i]); - ret = run_command_v_opt_cd_env(args.argv, RUN_GIT_CMD, prefix, env); + ret = run_command_v_opt_cd_env(args.v, RUN_GIT_CMD, prefix, env); exit(ret); } diff --git a/builtin/fetch.c b/builtin/fetch.c index c2e7afe..c49f0e9 100644 --- a/builtin/fetch.c +++ b/builtin/fetch.c @@ -1354,7 +1354,7 @@ static int do_fetch(struct transport *transport, if (tags == TAGS_SET || tags == TAGS_DEFAULT) { must_list_refs = 1; - if (ref_prefixes.argc) + if (ref_prefixes.nr) strvec_push(&ref_prefixes, "refs/tags/"); } @@ -1605,7 +1605,7 @@ static int fetch_multiple(struct string_list *list, int max_children) add_options_to_argv(&argv); if (max_children != 1 && list->nr != 1) { - struct parallel_fetch_state state = { argv.argv, list, 0, 0 }; + struct parallel_fetch_state state = { argv.v, list, 0, 0 }; strvec_push(&argv, "--end-of-options"); result = run_processes_parallel_tr2(max_children, @@ -1623,7 +1623,7 @@ static int fetch_multiple(struct string_list *list, int max_children) strvec_push(&argv, name); if (verbosity >= 0) printf(_("Fetching %s\n"), name); - if (run_command_v_opt(argv.argv, RUN_GIT_CMD)) { + if (run_command_v_opt(argv.v, RUN_GIT_CMD)) { error(_("Could not fetch %s"), name); result = 1; } diff --git a/builtin/gc.c b/builtin/gc.c index 9871980..aafa094 100644 --- a/builtin/gc.c +++ b/builtin/gc.c @@ -514,11 +514,11 @@ static void gc_before_repack(void) if (done++) return; - if (pack_refs && run_command_v_opt(pack_refs_cmd.argv, RUN_GIT_CMD)) - die(FAILED_RUN, pack_refs_cmd.argv[0]); + if (pack_refs && run_command_v_opt(pack_refs_cmd.v, RUN_GIT_CMD)) + die(FAILED_RUN, pack_refs_cmd.v[0]); - if (prune_reflogs && run_command_v_opt(reflog.argv, RUN_GIT_CMD)) - die(FAILED_RUN, reflog.argv[0]); + if (prune_reflogs && run_command_v_opt(reflog.v, RUN_GIT_CMD)) + die(FAILED_RUN, reflog.v[0]); } int cmd_gc(int argc, const char **argv, const char *prefix) @@ -653,8 +653,8 @@ int cmd_gc(int argc, const char **argv, const char *prefix) if (!repository_format_precious_objects) { close_object_store(the_repository->objects); - if (run_command_v_opt(repack.argv, RUN_GIT_CMD)) - die(FAILED_RUN, repack.argv[0]); + if (run_command_v_opt(repack.v, RUN_GIT_CMD)) + die(FAILED_RUN, repack.v[0]); if (prune_expire) { strvec_push(&prune, prune_expire); @@ -663,19 +663,19 @@ int cmd_gc(int argc, const char **argv, const char *prefix) if (has_promisor_remote()) strvec_push(&prune, "--exclude-promisor-objects"); - if (run_command_v_opt(prune.argv, RUN_GIT_CMD)) - die(FAILED_RUN, prune.argv[0]); + if (run_command_v_opt(prune.v, RUN_GIT_CMD)) + die(FAILED_RUN, prune.v[0]); } } if (prune_worktrees_expire) { strvec_push(&prune_worktrees, prune_worktrees_expire); - if (run_command_v_opt(prune_worktrees.argv, RUN_GIT_CMD)) - die(FAILED_RUN, prune_worktrees.argv[0]); + if (run_command_v_opt(prune_worktrees.v, RUN_GIT_CMD)) + die(FAILED_RUN, prune_worktrees.v[0]); } - if (run_command_v_opt(rerere.argv, RUN_GIT_CMD)) - die(FAILED_RUN, rerere.argv[0]); + if (run_command_v_opt(rerere.v, RUN_GIT_CMD)) + die(FAILED_RUN, rerere.v[0]); report_garbage = report_pack_garbage; reprepare_packed_git(the_repository); diff --git a/builtin/pack-objects.c b/builtin/pack-objects.c index 323f8bc..f00ae80 100644 --- a/builtin/pack-objects.c +++ b/builtin/pack-objects.c @@ -3704,7 +3704,7 @@ int cmd_pack_objects(int argc, const char **argv, const char *prefix) if (!use_internal_rev_list) read_object_list_from_stdin(); else { - get_object_list(rp.argc, rp.argv); + get_object_list(rp.nr, rp.v); strvec_clear(&rp); } cleanup_preferred_base(); diff --git a/builtin/pull.c b/builtin/pull.c index dae8766..015f6de 100644 --- a/builtin/pull.c +++ b/builtin/pull.c @@ -584,14 +584,14 @@ static int run_fetch(const char *repo, const char **refspecs) strvec_push(&args, "--no-show-forced-updates"); if (set_upstream) strvec_push(&args, set_upstream); - strvec_pushv(&args, opt_fetch.argv); + strvec_pushv(&args, opt_fetch.v); if (repo) { strvec_push(&args, repo); strvec_pushv(&args, refspecs); } else if (*refspecs) BUG("refspecs without repo?"); - ret = run_command_v_opt(args.argv, RUN_GIT_CMD); + ret = run_command_v_opt(args.v, RUN_GIT_CMD); strvec_clear(&args); return ret; } @@ -691,8 +691,8 @@ static int run_merge(void) strvec_push(&args, opt_ff); if (opt_verify_signatures) strvec_push(&args, opt_verify_signatures); - strvec_pushv(&args, opt_strategies.argv); - strvec_pushv(&args, opt_strategy_opts.argv); + strvec_pushv(&args, opt_strategies.v); + strvec_pushv(&args, opt_strategy_opts.v); if (opt_gpg_sign) strvec_push(&args, opt_gpg_sign); if (opt_autostash == 0) @@ -703,7 +703,7 @@ static int run_merge(void) strvec_push(&args, "--allow-unrelated-histories"); strvec_push(&args, "FETCH_HEAD"); - ret = run_command_v_opt(args.argv, RUN_GIT_CMD); + ret = run_command_v_opt(args.v, RUN_GIT_CMD); strvec_clear(&args); return ret; } @@ -882,8 +882,8 @@ static int run_rebase(const struct object_id *curr_head, strvec_push(&args, "--interactive"); if (opt_diffstat) strvec_push(&args, opt_diffstat); - strvec_pushv(&args, opt_strategies.argv); - strvec_pushv(&args, opt_strategy_opts.argv); + strvec_pushv(&args, opt_strategies.v); + strvec_pushv(&args, opt_strategy_opts.v); if (opt_gpg_sign) strvec_push(&args, opt_gpg_sign); if (opt_autostash == 0) @@ -902,7 +902,7 @@ static int run_rebase(const struct object_id *curr_head, else strvec_push(&args, oid_to_hex(merge_head)); - ret = run_command_v_opt(args.argv, RUN_GIT_CMD); + ret = run_command_v_opt(args.v, RUN_GIT_CMD); strvec_clear(&args); return ret; } diff --git a/builtin/rebase.c b/builtin/rebase.c index 35aeb8e..dadb52f 100644 --- a/builtin/rebase.c +++ b/builtin/rebase.c @@ -351,7 +351,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.argc, make_script_args.argv, + make_script_args.nr, make_script_args.v, flags); if (ret) @@ -900,7 +900,7 @@ static int run_am(struct rebase_options *opts) return status; } - strvec_pushv(&am.args, opts->git_am_opts.argv); + strvec_pushv(&am.args, opts->git_am_opts.v); strvec_push(&am.args, "--rebasing"); strvec_pushf(&am.args, "--resolvemsg=%s", resolvemsg); strvec_push(&am.args, "--patch-format=mboxrd"); @@ -969,7 +969,7 @@ static int run_specific_rebase(struct rebase_options *opts, enum action action) add_var(&script_snippet, "revisions", opts->revisions); add_var(&script_snippet, "restrict_revision", opts->restrict_revision ? oid_to_hex(&opts->restrict_revision->object.oid) : NULL); - sq_quote_argv_pretty(&buf, opts->git_am_opts.argv); + sq_quote_argv_pretty(&buf, opts->git_am_opts.v); add_var(&script_snippet, "git_am_opt", buf.buf); strbuf_release(&buf); add_var(&script_snippet, "verbose", @@ -1625,8 +1625,8 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) allow_preemptive_ff = 0; } - for (i = 0; i < options.git_am_opts.argc; i++) { - const char *option = options.git_am_opts.argv[i], *p; + for (i = 0; i < options.git_am_opts.nr; i++) { + const char *option = options.git_am_opts.v[i], *p; if (!strcmp(option, "--committer-date-is-author-date") || !strcmp(option, "--ignore-date") || !strcmp(option, "--whitespace=fix") || @@ -1721,10 +1721,10 @@ int cmd_rebase(int argc, const char **argv, const char *prefix) if (isatty(2) && options.flags & REBASE_NO_QUIET) strbuf_addstr(&options.git_format_patch_opt, " --progress"); - if (options.git_am_opts.argc || options.type == REBASE_APPLY) { + if (options.git_am_opts.nr || options.type == REBASE_APPLY) { /* all am options except -q are compatible only with --apply */ - for (i = options.git_am_opts.argc - 1; i >= 0; i--) - if (strcmp(options.git_am_opts.argv[i], "-q")) + for (i = options.git_am_opts.nr - 1; i >= 0; i--) + if (strcmp(options.git_am_opts.v[i], "-q")) break; if (i >= 0) { diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c index 1fc69cf..439f29d 100644 --- a/builtin/receive-pack.c +++ b/builtin/receive-pack.c @@ -950,7 +950,7 @@ static const char *push_to_deploy(unsigned char *sha1, struct child_process child = CHILD_PROCESS_INIT; child.argv = update_refresh; - child.env = env->argv; + child.env = env->v; child.dir = work_tree; child.no_stdin = 1; child.stdout_to_stderr = 1; @@ -961,7 +961,7 @@ static const char *push_to_deploy(unsigned char *sha1, /* run_command() does not clean up completely; reinitialize */ child_process_init(&child); child.argv = diff_files; - child.env = env->argv; + child.env = env->v; child.dir = work_tree; child.no_stdin = 1; child.stdout_to_stderr = 1; @@ -974,7 +974,7 @@ static const char *push_to_deploy(unsigned char *sha1, child_process_init(&child); child.argv = diff_index; - child.env = env->argv; + child.env = env->v; child.no_stdin = 1; child.no_stdout = 1; child.stdout_to_stderr = 0; @@ -985,7 +985,7 @@ static const char *push_to_deploy(unsigned char *sha1, read_tree[3] = hash_to_hex(sha1); child_process_init(&child); child.argv = read_tree; - child.env = env->argv; + child.env = env->v; child.dir = work_tree; child.no_stdin = 1; child.no_stdout = 1; @@ -1004,7 +1004,7 @@ static const char *push_to_checkout(unsigned char *hash, const char *work_tree) { strvec_pushf(env, "GIT_WORK_TREE=%s", absolute_path(work_tree)); - if (run_hook_le(env->argv, push_to_checkout_hook, + if (run_hook_le(env->v, push_to_checkout_hook, hash_to_hex(hash), NULL)) return "push-to-checkout hook declined"; else @@ -1205,11 +1205,11 @@ static void run_update_post_hook(struct command *commands) for (cmd = commands; cmd; cmd = cmd->next) { if (cmd->error_string || cmd->did_not_exist) continue; - if (!proc.args.argc) + if (!proc.args.nr) strvec_push(&proc.args, hook); strvec_push(&proc.args, cmd->ref_name); } - if (!proc.args.argc) + if (!proc.args.nr) return; proc.no_stdin = 1; diff --git a/builtin/remote.c b/builtin/remote.c index a3b33c2..c8240e9 100644 --- a/builtin/remote.c +++ b/builtin/remote.c @@ -1470,7 +1470,7 @@ static int update(int argc, const char **argv) for (i = 1; i < argc; i++) strvec_push(&fetch_argv, argv[i]); - if (strcmp(fetch_argv.argv[fetch_argv.argc-1], "default") == 0) { + if (strcmp(fetch_argv.v[fetch_argv.nr-1], "default") == 0) { git_config(get_remote_default, &default_defined); if (!default_defined) { strvec_pop(&fetch_argv); @@ -1478,7 +1478,7 @@ static int update(int argc, const char **argv) } } - retval = run_command_v_opt(fetch_argv.argv, RUN_GIT_CMD); + retval = run_command_v_opt(fetch_argv.v, RUN_GIT_CMD); strvec_clear(&fetch_argv); return retval; } diff --git a/builtin/replace.c b/builtin/replace.c index 7bc5d66..cd48765 100644 --- a/builtin/replace.c +++ b/builtin/replace.c @@ -513,7 +513,7 @@ static int convert_graft_file(int force) continue; strvec_split(&args, buf.buf); - if (args.argc && create_graft(args.argc, args.argv, force, 1)) + if (args.nr && create_graft(args.nr, args.v, force, 1)) strbuf_addf(&err, "\n\t%s", buf.buf); strvec_clear(&args); } diff --git a/builtin/show-branch.c b/builtin/show-branch.c index 4c918ce..7eae5f3 100644 --- a/builtin/show-branch.c +++ b/builtin/show-branch.c @@ -561,7 +561,7 @@ static int git_show_branch_config(const char *var, const char *value, void *cb) * default_arg is now passed to parse_options(), so we need to * mimic the real argv a bit better. */ - if (!default_args.argc) + if (!default_args.nr) strvec_push(&default_args, "show-branch"); strvec_push(&default_args, value); return 0; @@ -684,9 +684,9 @@ int cmd_show_branch(int ac, const char **av, const char *prefix) git_config(git_show_branch_config, NULL); /* If nothing is specified, try the default first */ - if (ac == 1 && default_args.argc) { - ac = default_args.argc; - av = default_args.argv; + if (ac == 1 && default_args.nr) { + ac = default_args.nr; + av = default_args.v; } ac = parse_options(ac, av, prefix, builtin_show_branch_options, diff --git a/builtin/stash.c b/builtin/stash.c index bfdbafa..10d8763 100644 --- a/builtin/stash.c +++ b/builtin/stash.c @@ -745,7 +745,7 @@ static int show_stash(int argc, const char **argv, const char *prefix) strvec_push(&revision_args, argv[i]); } - ret = get_stash_info(&info, stash_args.argc, stash_args.argv); + ret = get_stash_info(&info, stash_args.nr, stash_args.v); strvec_clear(&stash_args); if (ret) return -1; @@ -754,7 +754,7 @@ static int show_stash(int argc, const char **argv, const char *prefix) * The config settings are applied only if there are not passed * any options. */ - if (revision_args.argc == 1) { + if (revision_args.nr == 1) { if (show_stat) rev.diffopt.output_format = DIFF_FORMAT_DIFFSTAT; @@ -767,7 +767,7 @@ static int show_stash(int argc, const char **argv, const char *prefix) } } - argc = setup_revisions(revision_args.argc, revision_args.argv, &rev, NULL); + argc = setup_revisions(revision_args.nr, revision_args.v, &rev, NULL); if (argc > 1) { free_stash_info(&info); usage_with_options(git_stash_show_usage, options); @@ -1611,5 +1611,5 @@ int cmd_stash(int argc, const char **argv, const char *prefix) /* Assume 'stash push' */ strvec_push(&args, "push"); strvec_pushv(&args, argv); - return !!push_stash(args.argc, args.argv, prefix, 1); + return !!push_stash(args.nr, args.v, prefix, 1); } diff --git a/builtin/submodule--helper.c b/builtin/submodule--helper.c index 665db1f..df135ab 100644 --- a/builtin/submodule--helper.c +++ b/builtin/submodule--helper.c @@ -817,9 +817,9 @@ static void status_submodule(const char *path, const struct object_id *ce_oid, repo_init_revisions(the_repository, &rev, NULL); rev.abbrev = 0; - diff_files_args.argc = setup_revisions(diff_files_args.argc, - diff_files_args.argv, - &rev, NULL); + diff_files_args.nr = setup_revisions(diff_files_args.nr, + diff_files_args.v, + &rev, NULL); diff_files_result = run_diff_files(&rev, 0); if (!diff_result_code(&rev.diffopt, diff_files_result)) { diff --git a/builtin/upload-archive.c b/builtin/upload-archive.c index f02bb0e..24654b4 100644 --- a/builtin/upload-archive.c +++ b/builtin/upload-archive.c @@ -36,7 +36,7 @@ int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix) char *buf = packet_read_line(0, NULL); if (!buf) break; /* got a flush */ - if (sent_argv.argc > MAX_ARGS) + if (sent_argv.nr > MAX_ARGS) die("Too many options (>%d)", MAX_ARGS - 1); if (!starts_with(buf, arg_cmd)) @@ -45,7 +45,7 @@ int cmd_upload_archive_writer(int argc, const char **argv, const char *prefix) } /* parse all options sent by the client */ - return write_archive(sent_argv.argc, sent_argv.argv, prefix, + return write_archive(sent_argv.nr, sent_argv.v, prefix, the_repository, NULL, 1); } diff --git a/builtin/worktree.c b/builtin/worktree.c index be5d84f..378f332 100644 --- a/builtin/worktree.c +++ b/builtin/worktree.c @@ -422,7 +422,7 @@ static int add_worktree(const char *path, const char *refname, strvec_push(&cp.args, "--quiet"); } - cp.env = child_env.argv; + cp.env = child_env.v; ret = run_command(&cp); if (ret) goto done; @@ -433,7 +433,7 @@ static int add_worktree(const char *path, const char *refname, strvec_pushl(&cp.args, "reset", "--hard", "--no-recurse-submodules", NULL); if (opts->quiet) strvec_push(&cp.args, "--quiet"); - cp.env = child_env.argv; + cp.env = child_env.v; ret = run_command(&cp); if (ret) goto done; @@ -943,7 +943,7 @@ static void check_clean_worktree(struct worktree *wt, strvec_pushl(&cp.args, "status", "--porcelain", "--ignore-submodules=none", NULL); - cp.env = child_env.argv; + cp.env = child_env.v; cp.git_cmd = 1; cp.dir = wt->path; cp.out = -1; diff --git a/bundle.c b/bundle.c index 565d053..7ef9c3a 100644 --- a/bundle.c +++ b/bundle.c @@ -278,7 +278,7 @@ static int write_pack_data(int bundle_fd, struct rev_info *revs, struct strvec * "pack-objects", "--stdout", "--thin", "--delta-base-offset", NULL); - strvec_pushv(&pack_objects.args, pack_options->argv); + strvec_pushv(&pack_objects.args, pack_options->v); pack_objects.in = -1; pack_objects.out = bundle_fd; pack_objects.git_cmd = 1; diff --git a/commit.c b/commit.c index a5176a2..4ce8cb3 100644 --- a/commit.c +++ b/commit.c @@ -1643,7 +1643,7 @@ int run_commit_hook(int editor_is_used, const char *index_file, strvec_push(&hook_env, "GIT_EDITOR=:"); va_start(args, name); - ret = run_hook_ve(hook_env.argv,name, args); + ret = run_hook_ve(hook_env.v, name, args); va_end(args); strvec_clear(&hook_env); diff --git a/connect.c b/connect.c index 3299ea9..0b6aba1 100644 --- a/connect.c +++ b/connect.c @@ -70,9 +70,9 @@ int server_supports_v2(const char *c, int die_on_error) { int i; - for (i = 0; i < server_capabilities_v2.argc; i++) { + for (i = 0; i < server_capabilities_v2.nr; i++) { const char *out; - if (skip_prefix(server_capabilities_v2.argv[i], c, &out) && + if (skip_prefix(server_capabilities_v2.v[i], c, &out) && (!*out || *out == '=')) return 1; } @@ -87,9 +87,9 @@ int server_feature_v2(const char *c, const char **v) { int i; - for (i = 0; i < server_capabilities_v2.argc; i++) { + for (i = 0; i < server_capabilities_v2.nr; i++) { const char *out; - if (skip_prefix(server_capabilities_v2.argv[i], c, &out) && + if (skip_prefix(server_capabilities_v2.v[i], c, &out) && (*out == '=')) { *v = out + 1; return 1; @@ -103,9 +103,9 @@ int server_supports_feature(const char *c, const char *feature, { int i; - for (i = 0; i < server_capabilities_v2.argc; i++) { + for (i = 0; i < server_capabilities_v2.nr; i++) { const char *out; - if (skip_prefix(server_capabilities_v2.argv[i], c, &out) && + if (skip_prefix(server_capabilities_v2.v[i], c, &out) && (!*out || *(out++) == '=')) { if (parse_feature_request(out, feature)) return 1; @@ -488,9 +488,9 @@ struct ref **get_remote_refs(int fd_out, struct packet_reader *reader, if (!for_push) packet_write_fmt(fd_out, "peel\n"); packet_write_fmt(fd_out, "symrefs\n"); - for (i = 0; ref_prefixes && i < ref_prefixes->argc; i++) { + for (i = 0; ref_prefixes && i < ref_prefixes->nr; i++) { packet_write_fmt(fd_out, "ref-prefix %s\n", - ref_prefixes->argv[i]); + ref_prefixes->v[i]); } packet_flush(fd_out); diff --git a/daemon.c b/daemon.c index 0dec89f..2ab7ea8 100644 --- a/daemon.c +++ b/daemon.c @@ -482,7 +482,7 @@ static int upload_pack(const struct strvec *env) strvec_pushl(&cld.args, "upload-pack", "--strict", NULL); strvec_pushf(&cld.args, "--timeout=%u", timeout); - strvec_pushv(&cld.env_array, env->argv); + strvec_pushv(&cld.env_array, env->v); return run_service_command(&cld); } @@ -492,7 +492,7 @@ static int upload_archive(const struct strvec *env) struct child_process cld = CHILD_PROCESS_INIT; strvec_push(&cld.args, "upload-archive"); - strvec_pushv(&cld.env_array, env->argv); + strvec_pushv(&cld.env_array, env->v); return run_service_command(&cld); } @@ -502,7 +502,7 @@ static int receive_pack(const struct strvec *env) struct child_process cld = CHILD_PROCESS_INIT; strvec_push(&cld.args, "receive-pack"); - strvec_pushv(&cld.env_array, env->argv); + strvec_pushv(&cld.env_array, env->v); return run_service_command(&cld); } @@ -927,7 +927,7 @@ static void handle(int incoming, struct sockaddr *addr, socklen_t addrlen) #endif } - cld.argv = cld_argv.argv; + cld.argv = cld_argv.v; cld.in = incoming; cld.out = dup(incoming); diff --git a/diff.c b/diff.c index f1a3758..f9709de 100644 --- a/diff.c +++ b/diff.c @@ -4239,7 +4239,7 @@ static void run_external_diff(const char *pgm, diff_free_filespec_data(one); diff_free_filespec_data(two); - if (run_command_v_opt_cd_env(argv.argv, RUN_USING_SHELL, NULL, env.argv)) + if (run_command_v_opt_cd_env(argv.v, RUN_USING_SHELL, NULL, env.v)) die(_("external diff died, stopping at %s"), name); remove_tempfile(); diff --git a/environment.c b/environment.c index 00fe20e..52e0c97 100644 --- a/environment.c +++ b/environment.c @@ -164,7 +164,7 @@ static const char *getenv_safe(struct strvec *argv, const char *name) return NULL; strvec_push(argv, value); - return argv->argv[argv->argc - 1]; + return argv->v[argv->nr - 1]; } void setup_git_env(const char *git_dir) diff --git a/exec-cmd.c b/exec-cmd.c index 0f8e888..eeb2ee5 100644 --- a/exec-cmd.c +++ b/exec-cmd.c @@ -324,7 +324,7 @@ const char **prepare_git_cmd(struct strvec *out, const char **argv) { strvec_push(out, "git"); strvec_pushv(out, argv); - return out->argv; + return out->v; } int execv_git_cmd(const char **argv) @@ -332,10 +332,10 @@ int execv_git_cmd(const char **argv) struct strvec nargv = STRVEC_INIT; prepare_git_cmd(&nargv, argv); - trace_argv_printf(nargv.argv, "trace: exec:"); + trace_argv_printf(nargv.v, "trace: exec:"); /* execvp() can only ever return if it fails */ - sane_execvp("git", (char **)nargv.argv); + sane_execvp("git", (char **)nargv.v); trace_printf("trace: exec failed: %s\n", strerror(errno)); diff --git a/git.c b/git.c index 258035c..8bd1d75 100644 --- a/git.c +++ b/git.c @@ -352,7 +352,7 @@ static int handle_alias(int *argcp, const char ***argv) strvec_push(&child.args, alias_string + 1); strvec_pushv(&child.args, (*argv) + 1); - trace2_cmd_alias(alias_command, child.args.argv); + trace2_cmd_alias(alias_command, child.args.v); trace2_cmd_list_config(); trace2_cmd_list_env_vars(); trace2_cmd_name("_run_shell_alias_"); @@ -667,7 +667,7 @@ static void handle_builtin(int argc, const char **argv) } argc++; - argv = args.argv; + argv = args.v; } builtin = get_builtin(cmd); @@ -701,7 +701,7 @@ static void execv_dashed_external(const char **argv) * The code in run_command() logs trace2 child_start/child_exit * events, so we do not need to report exec/exec_result events here. */ - trace_argv_printf(cmd.args.argv, "trace: exec:"); + trace_argv_printf(cmd.args.v, "trace: exec:"); /* * If we fail because the command is not found, it is @@ -762,13 +762,13 @@ static int run_argv(int *argcp, const char ***argv) for (i = 0; i < *argcp; i++) strvec_push(&args, (*argv)[i]); - trace_argv_printf(args.argv, "trace: exec:"); + trace_argv_printf(args.v, "trace: exec:"); /* * if we fail because the command is not found, it is * OK to return. Otherwise, we just pass along the status code. */ - i = run_command_v_opt_tr2(args.argv, RUN_SILENT_EXEC_FAILURE | + i = run_command_v_opt_tr2(args.v, RUN_SILENT_EXEC_FAILURE | RUN_CLEAN_ON_EXIT | RUN_WAIT_AFTER_CLEAN, "git_alias"); if (i >= 0 || errno != ENOENT) exit(i); diff --git a/graph.c b/graph.c index 09c9cc9..c128ad0 100644 --- a/graph.c +++ b/graph.c @@ -355,8 +355,8 @@ struct git_graph *graph_init(struct rev_info *opt) parse_graph_colors_config(&custom_colors, string); free(string); /* graph_set_column_colors takes a max-index, not a count */ - graph_set_column_colors(custom_colors.argv, - custom_colors.argc - 1); + graph_set_column_colors(custom_colors.v, + custom_colors.nr - 1); } } diff --git a/http-push.c b/http-push.c index 31911aa..6a4a43e 100644 --- a/http-push.c +++ b/http-push.c @@ -1931,7 +1931,7 @@ int cmd_main(int argc, const char **argv) strvec_pushf(&commit_argv, "^%s", oid_to_hex(&ref->old_oid)); repo_init_revisions(the_repository, &revs, setup_git_directory()); - setup_revisions(commit_argv.argc, commit_argv.argv, &revs, NULL); + setup_revisions(commit_argv.nr, commit_argv.v, &revs, NULL); revs.edge_hint = 0; /* just in case */ /* Generate a list of objects that need to be pushed */ diff --git a/ls-refs.c b/ls-refs.c index 8192c94..a1e0b47 100644 --- a/ls-refs.c +++ b/ls-refs.c @@ -15,11 +15,11 @@ static int ref_match(const struct strvec *prefixes, const char *refname) { int i; - if (!prefixes->argc) + if (!prefixes->nr) return 1; /* no restriction */ - for (i = 0; i < prefixes->argc; i++) { - const char *prefix = prefixes->argv[i]; + for (i = 0; i < prefixes->nr; i++) { + const char *prefix = prefixes->v[i]; if (starts_with(refname, prefix)) return 1; diff --git a/merge.c b/merge.c index a05b054..753e461 100644 --- a/merge.c +++ b/merge.c @@ -33,7 +33,7 @@ int try_merge_command(struct repository *r, for (j = remotes; j; j = j->next) strvec_push(&args, merge_argument(j->item)); - ret = run_command_v_opt(args.argv, RUN_GIT_CMD); + ret = run_command_v_opt(args.v, RUN_GIT_CMD); strvec_clear(&args); discard_index(r->index); diff --git a/pathspec.c b/pathspec.c index c303126..7a229d8 100644 --- a/pathspec.c +++ b/pathspec.c @@ -652,7 +652,7 @@ void parse_pathspec_file(struct pathspec *pathspec, unsigned magic_mask, if (in != stdin) fclose(in); - parse_pathspec(pathspec, magic_mask, flags, prefix, parsed_file.argv); + parse_pathspec(pathspec, magic_mask, flags, prefix, parsed_file.v); strvec_clear(&parsed_file); } diff --git a/range-diff.c b/range-diff.c index 831c490..24dc435 100644 --- a/range-diff.c +++ b/range-diff.c @@ -67,7 +67,7 @@ static int read_patches(const char *range, struct string_list *list, "--notes", NULL); if (other_arg) - strvec_pushv(&cp.args, other_arg->argv); + strvec_pushv(&cp.args, other_arg->v); strvec_push(&cp.args, range); cp.out = -1; cp.no_stdin = 1; diff --git a/ref-filter.c b/ref-filter.c index 7f01385..0d3a56b 100644 --- a/ref-filter.c +++ b/ref-filter.c @@ -1918,9 +1918,9 @@ static void find_longest_prefixes(struct string_list *out, struct strbuf prefix = STRBUF_INIT; strvec_pushv(&sorted, patterns); - QSORT(sorted.argv, sorted.argc, qsort_strcmp); + QSORT(sorted.v, sorted.nr, qsort_strcmp); - find_longest_prefixes_1(out, &prefix, sorted.argv, sorted.argc); + find_longest_prefixes_1(out, &prefix, sorted.v, sorted.nr); strvec_clear(&sorted); strbuf_release(&prefix); diff --git a/remote-curl.c b/remote-curl.c index 7feaddc..41c3ac5 100644 --- a/remote-curl.c +++ b/remote-curl.c @@ -1190,7 +1190,7 @@ static int fetch_git(struct discovery *heads, rpc.service_name = "git-upload-pack", rpc.gzip_request = 1; - err = rpc_service(&rpc, heads, args.argv, &preamble, &rpc_result); + err = rpc_service(&rpc, heads, args.v, &preamble, &rpc_result); if (rpc_result.len) write_or_die(1, rpc_result.buf, rpc_result.len); strbuf_release(&rpc_result); @@ -1325,7 +1325,7 @@ static int push_git(struct discovery *heads, int nr_spec, const char **specs) memset(&rpc, 0, sizeof(rpc)); rpc.service_name = "git-receive-pack", - err = rpc_service(&rpc, heads, args.argv, &preamble, &rpc_result); + err = rpc_service(&rpc, heads, args.v, &preamble, &rpc_result); if (rpc_result.len) write_or_die(1, rpc_result.buf, rpc_result.len); strbuf_release(&rpc_result); @@ -1366,7 +1366,7 @@ static void parse_push(struct strbuf *buf) break; } while (1); - ret = push(specs.argc, specs.argv); + ret = push(specs.nr, specs.v); printf("\n"); fflush(stdout); diff --git a/remote.c b/remote.c index b4665fe..c5ed74f 100644 --- a/remote.c +++ b/remote.c @@ -1919,7 +1919,7 @@ static int stat_branch_pair(const char *branch_name, const char *base, strvec_push(&argv, "--"); repo_init_revisions(the_repository, &revs, NULL); - setup_revisions(argv.argc, argv.argv, &revs, NULL); + setup_revisions(argv.nr, argv.v, &revs, NULL); if (prepare_revision_walk(&revs)) die(_("revision walk setup failed")); diff --git a/revision.c b/revision.c index e144132..bc69f19 100644 --- a/revision.c +++ b/revision.c @@ -2767,7 +2767,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s got_rev_arg = 1; } - if (prune_data.argc) { + if (prune_data.nr) { /* * If we need to introduce the magic "a lone ':' means no * pathspec whatsoever", here is the place to do so. @@ -2783,7 +2783,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s * } */ parse_pathspec(&revs->prune_data, 0, 0, - revs->prefix, prune_data.argv); + revs->prefix, prune_data.v); } strvec_clear(&prune_data); diff --git a/run-command.c b/run-command.c index b9630a1..cc9c329 100644 --- a/run-command.c +++ b/run-command.c @@ -287,7 +287,7 @@ static const char **prepare_shell_cmd(struct strvec *out, const char **argv) } strvec_pushv(out, argv); - return out->argv; + return out->v; } #ifndef GIT_WINDOWS_NATIVE @@ -426,11 +426,11 @@ static int prepare_cmd(struct strvec *out, const struct child_process *cmd) * there are dir separator characters, we have exec attempt to invoke * the command directly. */ - if (!has_dir_sep(out->argv[1])) { - char *program = locate_in_PATH(out->argv[1]); + if (!has_dir_sep(out->v[1])) { + char *program = locate_in_PATH(out->v[1]); if (program) { - free((char *)out->argv[1]); - out->argv[1] = program; + free((char *)out->v[1]); + out->v[1] = program; } else { strvec_clear(out); errno = ENOENT; @@ -672,9 +672,9 @@ int start_command(struct child_process *cmd) char *str; if (!cmd->argv) - cmd->argv = cmd->args.argv; + cmd->argv = cmd->args.v; if (!cmd->env) - cmd->env = cmd->env_array.argv; + cmd->env = cmd->env_array.v; /* * In case of errors we must keep the promise to close FDs @@ -846,10 +846,10 @@ fail_pipe: * be used in the event exec failed with ENOEXEC at which point * we will try to interpret the command using 'sh'. */ - execve(argv.argv[1], (char *const *) argv.argv + 1, + execve(argv.v[1], (char *const *) argv.v + 1, (char *const *) childenv); if (errno == ENOEXEC) - execve(argv.argv[0], (char *const *) argv.argv, + execve(argv.v[0], (char *const *) argv.v, (char *const *) childenv); if (errno == ENOENT) { @@ -1874,7 +1874,7 @@ int run_auto_gc(int quiet) strvec_pushl(&argv_gc_auto, "gc", "--auto", NULL); if (quiet) strvec_push(&argv_gc_auto, "--quiet"); - status = run_command_v_opt(argv_gc_auto.argv, RUN_GIT_CMD); + status = run_command_v_opt(argv_gc_auto.v, RUN_GIT_CMD); strvec_clear(&argv_gc_auto); return status; } diff --git a/sequencer.c b/sequencer.c index 31a2b1a..cc3f8fa 100644 --- a/sequencer.c +++ b/sequencer.c @@ -2761,7 +2761,7 @@ static int reset_merge(const struct object_id *oid) if (!is_null_oid(oid)) strvec_push(&argv, oid_to_hex(oid)); - ret = run_command_v_opt(argv.argv, RUN_GIT_CMD); + ret = run_command_v_opt(argv.v, RUN_GIT_CMD); strvec_clear(&argv); return ret; @@ -3135,7 +3135,7 @@ static int do_exec(struct repository *r, const char *command_line) strvec_pushf(&child_env, "GIT_WORK_TREE=%s", absolute_path(get_git_work_tree())); status = run_command_v_opt_cd_env(child_argv, RUN_USING_SHELL, NULL, - child_env.argv); + child_env.v); /* force re-reading of the cache */ if (discard_index(r->index) < 0 || repo_read_index(r) < 0) diff --git a/serve.c b/serve.c index 523a9be..f634120 100644 --- a/serve.c +++ b/serve.c @@ -146,9 +146,9 @@ int has_capability(const struct strvec *keys, const char *capability, const char **value) { int i; - for (i = 0; i < keys->argc; i++) { + for (i = 0; i < keys->nr; i++) { const char *out; - if (skip_prefix(keys->argv[i], capability, &out) && + if (skip_prefix(keys->v[i], capability, &out) && (!*out || *out == '=')) { if (value) { if (*out == '=') @@ -223,7 +223,7 @@ static int process_request(void) * If no command and no keys were given then the client * wanted to terminate the connection. */ - if (!keys.argc) + if (!keys.nr) return 1; /* diff --git a/strvec.c b/strvec.c index 9e76ab9..21dce0a 100644 --- a/strvec.c +++ b/strvec.c @@ -6,25 +6,25 @@ const char *empty_strvec[] = { NULL }; void strvec_init(struct strvec *array) { - array->argv = empty_strvec; - array->argc = 0; + array->v = empty_strvec; + array->nr = 0; array->alloc = 0; } static void strvec_push_nodup(struct strvec *array, const char *value) { - if (array->argv == empty_strvec) - array->argv = NULL; + if (array->v == empty_strvec) + array->v = NULL; - ALLOC_GROW(array->argv, array->argc + 2, array->alloc); - array->argv[array->argc++] = value; - array->argv[array->argc] = NULL; + ALLOC_GROW(array->v, array->nr + 2, array->alloc); + array->v[array->nr++] = value; + array->v[array->nr] = NULL; } const char *strvec_push(struct strvec *array, const char *value) { strvec_push_nodup(array, xstrdup(value)); - return array->argv[array->argc - 1]; + return array->v[array->nr - 1]; } const char *strvec_pushf(struct strvec *array, const char *fmt, ...) @@ -37,7 +37,7 @@ const char *strvec_pushf(struct strvec *array, const char *fmt, ...) va_end(ap); strvec_push_nodup(array, strbuf_detach(&v, NULL)); - return array->argv[array->argc - 1]; + return array->v[array->nr - 1]; } void strvec_pushl(struct strvec *array, ...) @@ -51,19 +51,19 @@ void strvec_pushl(struct strvec *array, ...) va_end(ap); } -void strvec_pushv(struct strvec *array, const char **argv) +void strvec_pushv(struct strvec *array, const char **items) { - for (; *argv; argv++) - strvec_push(array, *argv); + for (; *items; items++) + strvec_push(array, *items); } void strvec_pop(struct strvec *array) { - if (!array->argc) + if (!array->nr) return; - free((char *)array->argv[array->argc - 1]); - array->argv[array->argc - 1] = NULL; - array->argc--; + free((char *)array->v[array->nr - 1]); + array->v[array->nr - 1] = NULL; + array->nr--; } void strvec_split(struct strvec *array, const char *to_split) @@ -88,21 +88,21 @@ void strvec_split(struct strvec *array, const char *to_split) void strvec_clear(struct strvec *array) { - if (array->argv != empty_strvec) { + if (array->v != empty_strvec) { int i; - for (i = 0; i < array->argc; i++) - free((char *)array->argv[i]); - free(array->argv); + for (i = 0; i < array->nr; i++) + free((char *)array->v[i]); + free(array->v); } strvec_init(array); } const char **strvec_detach(struct strvec *array) { - if (array->argv == empty_strvec) + if (array->v == empty_strvec) return xcalloc(1, sizeof(const char *)); else { - const char **ret = array->argv; + const char **ret = array->v; strvec_init(array); return ret; } diff --git a/strvec.h b/strvec.h index bd35de1..fdcad75 100644 --- a/strvec.h +++ b/strvec.h @@ -2,10 +2,10 @@ #define STRVEC_H /** - * The argv-array API allows one to dynamically build and store - * NULL-terminated lists. An argv-array maintains the invariant that the - * `argv` member always points to a non-NULL array, and that the array is - * always NULL-terminated at the element pointed to by `argv[argc]`. This + * The strvec API allows one to dynamically build and store + * NULL-terminated arrays of strings. A strvec maintains the invariant that the + * `items` member always points to a non-NULL array, and that the array is + * always NULL-terminated at the element pointed to by `items[nr]`. This * makes the result suitable for passing to functions expecting to receive * argv from main(). * @@ -22,15 +22,15 @@ extern const char *empty_strvec[]; /** * A single array. This should be initialized by assignment from - * `STRVEC_INIT`, or by calling `strvec_init`. The `argv` - * member contains the actual array; the `argc` member contains the + * `STRVEC_INIT`, or by calling `strvec_init`. The `items` + * member contains the actual array; the `nr` member contains the * number of elements in the array, not including the terminating * NULL. */ struct strvec { - const char **argv; - size_t argc; - size_t alloc; + const char **v; + int nr; + int alloc; }; #define STRVEC_INIT { empty_strvec, 0, 0 } @@ -78,7 +78,7 @@ void strvec_split(struct strvec *, const char *); void strvec_clear(struct strvec *); /** - * Disconnect the `argv` member from the `strvec` struct and + * Disconnect the `items` member from the `strvec` struct and * return it. The caller is responsible for freeing the memory used * by the array, and by the strings it references. After detaching, * the `strvec` is in a reinitialized state and can be pushed diff --git a/submodule.c b/submodule.c index fb96d59..a52b93a 100644 --- a/submodule.c +++ b/submodule.c @@ -269,7 +269,7 @@ int is_submodule_active(struct repository *repo, const char *path) strvec_push(&args, item->string); } - parse_pathspec(&ps, 0, 0, NULL, args.argv); + parse_pathspec(&ps, 0, 0, NULL, args.v); ret = match_pathspec(repo->index, &ps, path, strlen(path), 0, NULL, 1); strvec_clear(&args); @@ -842,7 +842,7 @@ static void collect_changed_submodules(struct repository *r, const struct commit *commit; repo_init_revisions(r, &rev, NULL); - setup_revisions(argv->argc, argv->argv, &rev, NULL); + setup_revisions(argv->nr, argv->v, &rev, NULL); if (prepare_revision_walk(&rev)) die(_("revision walk setup failed")); @@ -1014,7 +1014,7 @@ int find_unpushed_submodules(struct repository *r, struct string_list_item *name; struct strvec argv = STRVEC_INIT; - /* argv.argv[0] will be ignored by setup_revisions */ + /* argv.v[0] will be ignored by setup_revisions */ strvec_push(&argv, "find_unpushed_submodules"); oid_array_for_each_unique(commits, append_oid_to_argv, &argv); strvec_push(&argv, "--not"); @@ -1453,7 +1453,7 @@ static int get_next_submodule(struct child_process *cp, strbuf_addf(err, _("Fetching submodule %s%s\n"), spf->prefix, ce->name); strvec_init(&cp->args); - strvec_pushv(&cp->args, spf->args.argv); + strvec_pushv(&cp->args, spf->args.v); strvec_push(&cp->args, default_argv); strvec_push(&cp->args, "--submodule-prefix"); @@ -1501,7 +1501,7 @@ static int get_next_submodule(struct child_process *cp, cp->dir = task->repo->gitdir; strvec_init(&cp->args); - strvec_pushv(&cp->args, spf->args.argv); + strvec_pushv(&cp->args, spf->args.v); strvec_push(&cp->args, "on-demand"); strvec_push(&cp->args, "--submodule-prefix"); strvec_push(&cp->args, submodule_prefix.buf); @@ -1619,8 +1619,8 @@ int fetch_populated_submodules(struct repository *r, die(_("index file corrupt")); strvec_push(&spf.args, "fetch"); - for (i = 0; i < options->argc; i++) - strvec_push(&spf.args, options->argv[i]); + for (i = 0; i < options->nr; i++) + strvec_push(&spf.args, options->v[i]); strvec_push(&spf.args, "--recurse-submodules-default"); /* default value, "--submodule-prefix" and its value are added later */ diff --git a/t/helper/test-run-command.c b/t/helper/test-run-command.c index 726835f..7ae03dc 100644 --- a/t/helper/test-run-command.c +++ b/t/helper/test-run-command.c @@ -248,7 +248,7 @@ static int quote_stress_test(int argc, const char **argv) else strvec_pushl(&args, "test-tool", "run-command", "quote-echo", NULL); - arg_offset = args.argc; + arg_offset = args.nr; if (argc > 0) { trials = 1; @@ -275,13 +275,13 @@ static int quote_stress_test(int argc, const char **argv) if (i < skip) continue; - cp.argv = args.argv; + cp.argv = args.v; strbuf_reset(&out); if (pipe_command(&cp, NULL, 0, &out, 0, NULL, 0) < 0) return error("Failed to spawn child process"); for (j = 0, k = 0; j < arg_count; j++) { - const char *arg = args.argv[j + arg_offset]; + const char *arg = args.v[j + arg_offset]; if (strcmp(arg, out.buf + k)) ret = error("incorrectly quoted arg: '%s', " @@ -298,7 +298,7 @@ static int quote_stress_test(int argc, const char **argv) fprintf(stderr, "Trial #%d failed. Arguments:\n", i); for (j = 0; j < arg_count; j++) fprintf(stderr, "arg #%d: '%s'\n", - (int)j, args.argv[j + arg_offset]); + (int)j, args.v[j + arg_offset]); strbuf_release(&out); strvec_clear(&args); diff --git a/tmp-objdir.c b/tmp-objdir.c index e78e481..42ed4db 100644 --- a/tmp-objdir.c +++ b/tmp-objdir.c @@ -283,7 +283,7 @@ const char **tmp_objdir_env(const struct tmp_objdir *t) { if (!t) return NULL; - return t->env.argv; + return t->env.v; } void tmp_objdir_add_as_alternate(const struct tmp_objdir *t) diff --git a/transport-helper.c b/transport-helper.c index ae8011e..defafbf 100644 --- a/transport-helper.c +++ b/transport-helper.c @@ -138,7 +138,7 @@ static struct child_process *get_helper(struct transport *transport) strvec_pushf(&helper->env_array, "%s=%s", GIT_DIR_ENVIRONMENT, get_git_dir()); - helper->trace2_child_class = helper->args.argv[0]; /* "remote-" */ + helper->trace2_child_class = helper->args.v[0]; /* "remote-" */ code = start_command(helper); if (code < 0 && errno == ENOENT) diff --git a/upload-pack.c b/upload-pack.c index 4a7918e..db8c650 100644 --- a/upload-pack.c +++ b/upload-pack.c @@ -897,7 +897,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.argc, av.argv); + deepen_by_rev_list(data, av.nr, av.v); strvec_clear(&av); ret = 1; } else { -- cgit v0.10.2-6-g49f6