replace memset with string-list initializers

Using memset and then manually setting values of the string-list members is not future proof as the internal representation of string-list may change any time. Use `string_list_init()` or STRING_LIST_INIT_* macros instead of memset. Signed-off-by: Tanay Abhra <tanayabh@gmail.com> Reviewed-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Tanay Abhra committed Jul 18, 2014 at 02:19 UTC f93d7c6fa0548e95ca2795d900671a87c1a88ea3
4 files changed +6 -15
builtin/commit.c
+1 -2
@@ -423,8 +423,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,
423 die(_("cannot do a partial commit during a cherry-pick."));
424 }
425
426 - memset(&partial, 0, sizeof(partial));
427 - partial.strdup_strings = 1;
426 + string_list_init(&partial, 1);
427 if (list_paths(&partial, !current_head ? NULL : "HEAD", prefix, &pathspec))
428 exit(1);
429
merge-recursive.c
+3 -6
@@ -2062,12 +2062,9 @@ void init_merge_options(struct merge_options *o)
2062 if (o->verbosity >= 5)
2063 o->buffer_output = 0;
2064 strbuf_init(&o->obuf, 0);
2065 - memset(&o->current_file_set, 0, sizeof(struct string_list));
2066 - o->current_file_set.strdup_strings = 1;
2067 - memset(&o->current_directory_set, 0, sizeof(struct string_list));
2068 - o->current_directory_set.strdup_strings = 1;
2069 - memset(&o->df_conflict_file_set, 0, sizeof(struct string_list));
2070 - o->df_conflict_file_set.strdup_strings = 1;
2065 + string_list_init(&o->current_file_set, 1);
2066 + string_list_init(&o->current_directory_set, 1);
2067 + string_list_init(&o->df_conflict_file_set, 1);
2068 }
2069
2070 int parse_merge_opt(struct merge_options *o, const char *s)
submodule.c
+1 -4
@@ -544,10 +544,7 @@ static int push_submodule(const char *path)
544 int push_unpushed_submodules(unsigned char new_sha1[20], const char *remotes_name)
545 {
546 int i, ret = 1;
547 - struct string_list needs_pushing;
548 -
549 - memset(&needs_pushing, 0, sizeof(struct string_list));
550 - needs_pushing.strdup_strings = 1;
547 + struct string_list needs_pushing = STRING_LIST_INIT_DUP;
548
549 if (!find_unpushed_submodules(new_sha1, remotes_name, &needs_pushing))
550 return 1;
transport.c
+1 -3
@@ -1188,10 +1188,8 @@ int transport_push(struct transport *transport,
1188 if ((flags & (TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND |
1189 TRANSPORT_RECURSE_SUBMODULES_CHECK)) && !is_bare_repository()) {
1190 struct ref *ref = remote_refs;
1191 - struct string_list needs_pushing;
1191 + struct string_list needs_pushing = STRING_LIST_INIT_DUP;
1192
1193 - memset(&needs_pushing, 0, sizeof(struct string_list));
1194 - needs_pushing.strdup_strings = 1;
1193 for (; ref; ref = ref->next)
1194 if (!is_null_sha1(ref->new_sha1) &&
1195 find_unpushed_submodules(ref->new_sha1,