Skip to content
This repository was archived by the owner on Nov 9, 2017. It is now read-only.

Commit 955d7be

Browse files
committed
Merge branch 'ta/string-list-init'
* ta/string-list-init: replace memset with string-list initializers string-list: add string_list initializer helper function
2 parents bc88def + f93d7c6 commit 955d7be

File tree

7 files changed

+19
-15
lines changed

7 files changed

+19
-15
lines changed

Documentation/technical/api-string-list.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,11 @@ Functions
6868

6969
* General ones (works with sorted and unsorted lists as well)
7070

71+
`string_list_init`::
72+
73+
Initialize the members of the string_list, set `strdup_strings`
74+
member according to the value of the second parameter.
75+
7176
`filter_string_list`::
7277

7378
Apply a function to each item in a list, retaining only the

builtin/commit.c

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

423-
memset(&partial, 0, sizeof(partial));
424-
partial.strdup_strings = 1;
423+
string_list_init(&partial, 1);
425424
if (list_paths(&partial, !current_head ? NULL : "HEAD", prefix, &pathspec))
426425
exit(1);
427426

merge-recursive.c

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2059,12 +2059,9 @@ void init_merge_options(struct merge_options *o)
20592059
if (o->verbosity >= 5)
20602060
o->buffer_output = 0;
20612061
strbuf_init(&o->obuf, 0);
2062-
memset(&o->current_file_set, 0, sizeof(struct string_list));
2063-
o->current_file_set.strdup_strings = 1;
2064-
memset(&o->current_directory_set, 0, sizeof(struct string_list));
2065-
o->current_directory_set.strdup_strings = 1;
2066-
memset(&o->df_conflict_file_set, 0, sizeof(struct string_list));
2067-
o->df_conflict_file_set.strdup_strings = 1;
2062+
string_list_init(&o->current_file_set, 1);
2063+
string_list_init(&o->current_directory_set, 1);
2064+
string_list_init(&o->df_conflict_file_set, 1);
20682065
}
20692066

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

string-list.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,12 @@
11
#include "cache.h"
22
#include "string-list.h"
33

4+
void string_list_init(struct string_list *list, int strdup_strings)
5+
{
6+
memset(list, 0, sizeof(*list));
7+
list->strdup_strings = strdup_strings;
8+
}
9+
410
/* if there is no exact match, point to the index where the entry could be
511
* inserted */
612
static int get_entry_index(const struct string_list *list, const char *string,

string-list.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,8 @@ struct string_list {
1818
#define STRING_LIST_INIT_NODUP { NULL, 0, 0, 0, NULL }
1919
#define STRING_LIST_INIT_DUP { NULL, 0, 0, 1, NULL }
2020

21+
void string_list_init(struct string_list *list, int strdup_strings);
22+
2123
void print_string_list(const struct string_list *p, const char *text);
2224
void string_list_clear(struct string_list *list, int free_util);
2325

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
@@ -1176,10 +1176,8 @@ int transport_push(struct transport *transport,
11761176
if ((flags & (TRANSPORT_RECURSE_SUBMODULES_ON_DEMAND |
11771177
TRANSPORT_RECURSE_SUBMODULES_CHECK)) && !is_bare_repository()) {
11781178
struct ref *ref = remote_refs;
1179-
struct string_list needs_pushing;
1179+
struct string_list needs_pushing = STRING_LIST_INIT_DUP;
11801180

1181-
memset(&needs_pushing, 0, sizeof(struct string_list));
1182-
needs_pushing.strdup_strings = 1;
11831181
for (; ref; ref = ref->next)
11841182
if (!is_null_sha1(ref->new_sha1) &&
11851183
find_unpushed_submodules(ref->new_sha1,

0 commit comments

Comments
 (0)