summaryrefslogtreecommitdiff
path: root/strvec.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2020-07-29 00:37:20 (GMT)
committerJunio C Hamano <gitster@pobox.com>2020-07-31 02:18:06 (GMT)
commitd70a9eb611a9d242c1d26847d223b8677609305b (patch)
tree2c7f218e0037607dfbf8c92ef34a5d412ceac78c /strvec.c
parentb5eb741a00155f888a9a4ced87c840a2b7b04f5a (diff)
downloadgit-d70a9eb611a9d242c1d26847d223b8677609305b.zip
git-d70a9eb611a9d242c1d26847d223b8677609305b.tar.gz
git-d70a9eb611a9d242c1d26847d223b8677609305b.tar.bz2
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 <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'strvec.c')
-rw-r--r--strvec.c44
1 files changed, 22 insertions, 22 deletions
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;
}