Skip to content

Commit f93d7c6

Browse files
tanayabhgitster
authored andcommitted
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 <[email protected]> Reviewed-by: Matthieu Moy <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 3ed3f5f commit f93d7c6

File tree

4 files changed

+6
-15
lines changed

4 files changed

+6
-15
lines changed

builtin/commit.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -423,8 +423,7 @@ static char *prepare_index(int argc, const char **argv, const char *prefix,
423423
die(_("cannot do a partial commit during a cherry-pick."));
424424
}
425425

426-
memset(&partial, 0, sizeof(partial));
427-
partial.strdup_strings = 1;
426+
string_list_init(&partial, 1);
428427
if (list_paths(&partial, !current_head ? NULL : "HEAD", prefix, &pathspec))
429428
exit(1);
430429

merge-recursive.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2062,12 +2062,9 @@ void init_merge_options(struct merge_options *o)
20622062
if (o->verbosity >= 5)
20632063
o->buffer_output = 0;
20642064
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);
20712068
}
20722069

20732070
int parse_merge_opt(struct merge_options *o, const char *s)

submodule.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -544,10 +544,7 @@ static int push_submodule(const char *path)
544544
int push_unpushed_submodules(unsigned char new_sha1[20], const char *remotes_name)
545545
{
546546
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;
551548

552549
if (!find_unpushed_submodules(new_sha1, remotes_name, &needs_pushing))
553550
return 1;

transport.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1188,10 +1188,8 @@ int transport_push(struct transport *transport,
11881188
if ((flags & (TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND |
11891189
TRANSPORT_RECURSE_SUBMODULES_CHECK)) && !is_bare_repository()) {
11901190
struct ref *ref = remote_refs;
1191-
struct string_list needs_pushing;
1191+
struct string_list needs_pushing = STRING_LIST_INIT_DUP;
11921192

1193-
memset(&needs_pushing, 0, sizeof(struct string_list));
1194-
needs_pushing.strdup_strings = 1;
11951193
for (; ref; ref = ref->next)
11961194
if (!is_null_sha1(ref->new_sha1) &&
11971195
find_unpushed_submodules(ref->new_sha1,

0 commit comments

Comments
 (0)