Skip to content

Commit 183113a

Browse files
tfarinagitster
authored andcommitted
string_list: Add STRING_LIST_INIT macro and make use of it.
Acked-by: Jonathan Nieder <[email protected]> Signed-off-by: Thiago Farina <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8a57c6e commit 183113a

16 files changed

+36
-31
lines changed

builtin/fast-export.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -566,7 +566,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
566566
{
567567
struct rev_info revs;
568568
struct object_array commits = { 0, 0, NULL };
569-
struct string_list extra_refs = { NULL, 0, 0, 0 };
569+
struct string_list extra_refs = STRING_LIST_INIT_NODUP;
570570
struct commit *commit;
571571
char *export_filename = NULL, *import_filename = NULL;
572572
struct option options[] = {

builtin/fetch.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -548,8 +548,8 @@ static void find_non_local_tags(struct transport *transport,
548548
struct ref **head,
549549
struct ref ***tail)
550550
{
551-
struct string_list existing_refs = { NULL, 0, 0, 0 };
552-
struct string_list remote_refs = { NULL, 0, 0, 0 };
551+
struct string_list existing_refs = STRING_LIST_INIT_NODUP;
552+
struct string_list remote_refs = STRING_LIST_INIT_NODUP;
553553
const struct ref *ref;
554554
struct string_list_item *item = NULL;
555555

@@ -651,7 +651,7 @@ static int truncate_fetch_head(void)
651651
static int do_fetch(struct transport *transport,
652652
struct refspec *refs, int ref_count)
653653
{
654-
struct string_list existing_refs = { NULL, 0, 0, 0 };
654+
struct string_list existing_refs = STRING_LIST_INIT_NODUP;
655655
struct string_list_item *peer_item = NULL;
656656
struct ref *ref_map;
657657
struct ref *rm;
@@ -874,7 +874,7 @@ static int fetch_one(struct remote *remote, int argc, const char **argv)
874874
int cmd_fetch(int argc, const char **argv, const char *prefix)
875875
{
876876
int i;
877-
struct string_list list = { NULL, 0, 0, 0 };
877+
struct string_list list = STRING_LIST_INIT_NODUP;
878878
struct remote *remote;
879879
int result = 0;
880880

builtin/fmt-merge-msg.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,8 @@ void init_src_data(struct src_data *data)
3838
data->generic.strdup_strings = 1;
3939
}
4040

41-
static struct string_list srcs = { NULL, 0, 0, 1 };
42-
static struct string_list origins = { NULL, 0, 0, 1 };
41+
static struct string_list srcs = STRING_LIST_INIT_DUP;
42+
static struct string_list origins = STRING_LIST_INIT_DUP;
4343

4444
static int handle_line(char *line)
4545
{
@@ -146,7 +146,7 @@ static void shortlog(const char *name, unsigned char *sha1,
146146
int i, count = 0;
147147
struct commit *commit;
148148
struct object *branch;
149-
struct string_list subjects = { NULL, 0, 0, 1 };
149+
struct string_list subjects = STRING_LIST_INIT_DUP;
150150
int flags = UNINTERESTING | TREESAME | SEEN | SHOWN | ADDED;
151151
struct strbuf sb = STRBUF_INIT;
152152

builtin/grep.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -836,7 +836,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
836836
struct grep_opt opt;
837837
struct object_array list = { 0, 0, NULL };
838838
const char **paths = NULL;
839-
struct string_list path_list = { NULL, 0, 0, 0 };
839+
struct string_list path_list = STRING_LIST_INIT_NODUP;
840840
int i;
841841
int dummy;
842842
int nongit = 0, use_index = 1;

builtin/mailsplit.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ static int split_maildir(const char *maildir, const char *dir,
137137
char name[PATH_MAX];
138138
int ret = -1;
139139
int i;
140-
struct string_list list = {NULL, 0, 0, 1};
140+
struct string_list list = STRING_LIST_INIT_DUP;
141141

142142
if (populate_maildir_list(&list, maildir) < 0)
143143
goto out;

builtin/mv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
6363
const char **source, **destination, **dest_path;
6464
enum update_mode { BOTH = 0, WORKING_DIRECTORY, INDEX } *modes;
6565
struct stat st;
66-
struct string_list src_for_dst = {NULL, 0, 0, 0};
66+
struct string_list src_for_dst = STRING_LIST_INIT_NODUP;
6767

6868
git_config(git_default_config, NULL);
6969

builtin/receive-pack.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -530,7 +530,7 @@ static void check_aliased_update(struct command *cmd, struct string_list *list)
530530
static void check_aliased_updates(struct command *commands)
531531
{
532532
struct command *cmd;
533-
struct string_list ref_list = { NULL, 0, 0, 0 };
533+
struct string_list ref_list = STRING_LIST_INIT_NODUP;
534534

535535
for (cmd = commands; cmd; cmd = cmd->next) {
536536
struct string_list_item *item =

builtin/remote.c

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -134,7 +134,7 @@ static int add_branch(const char *key, const char *branchname,
134134
static int add(int argc, const char **argv)
135135
{
136136
int fetch = 0, mirror = 0, fetch_tags = TAGS_DEFAULT;
137-
struct string_list track = { NULL, 0, 0 };
137+
struct string_list track = STRING_LIST_INIT_NODUP;
138138
const char *master = NULL;
139139
struct remote *remote;
140140
struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT;
@@ -596,7 +596,7 @@ static int mv(int argc, const char **argv)
596596
};
597597
struct remote *oldremote, *newremote;
598598
struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT, buf3 = STRBUF_INIT;
599-
struct string_list remote_branches = { NULL, 0, 0, 0 };
599+
struct string_list remote_branches = STRING_LIST_INIT_NODUP;
600600
struct rename_info rename;
601601
int i;
602602

@@ -734,8 +734,8 @@ static int rm(int argc, const char **argv)
734734
struct remote *remote;
735735
struct strbuf buf = STRBUF_INIT;
736736
struct known_remotes known_remotes = { NULL, NULL };
737-
struct string_list branches = { NULL, 0, 0, 1 };
738-
struct string_list skipped = { NULL, 0, 0, 1 };
737+
struct string_list branches = STRING_LIST_INIT_DUP;
738+
struct string_list skipped = STRING_LIST_INIT_DUP;
739739
struct branches_for_remote cb_data;
740740
int i, result;
741741

@@ -1044,7 +1044,7 @@ static int show(int argc, const char **argv)
10441044
OPT_END()
10451045
};
10461046
struct ref_states states;
1047-
struct string_list info_list = { NULL, 0, 0, 0 };
1047+
struct string_list info_list = STRING_LIST_INIT_NODUP;
10481048
struct show_info info;
10491049

10501050
argc = parse_options(argc, argv, NULL, options, builtin_remote_show_usage,
@@ -1483,7 +1483,7 @@ static int get_one_entry(struct remote *remote, void *priv)
14831483

14841484
static int show_all(void)
14851485
{
1486-
struct string_list list = { NULL, 0, 0 };
1486+
struct string_list list = STRING_LIST_INIT_NODUP;
14871487
int result;
14881488

14891489
list.strdup_strings = 1;

builtin/rerere.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ static int git_rerere_gc_config(const char *var, const char *value, void *cb)
4040

4141
static void garbage_collect(struct string_list *rr)
4242
{
43-
struct string_list to_remove = { NULL, 0, 0, 1 };
43+
struct string_list to_remove = STRING_LIST_INIT_DUP;
4444
DIR *dir;
4545
struct dirent *e;
4646
int i, cutoff;
@@ -102,7 +102,7 @@ static int diff_two(const char *file1, const char *label1,
102102

103103
int cmd_rerere(int argc, const char **argv, const char *prefix)
104104
{
105-
struct string_list merge_rr = { NULL, 0, 0, 1 };
105+
struct string_list merge_rr = STRING_LIST_INIT_DUP;
106106
int i, fd, flags = 0;
107107

108108
if (2 < argc) {

builtin/show-ref.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ static int add_existing(const char *refname, const unsigned char *sha1, int flag
120120
*/
121121
static int exclude_existing(const char *match)
122122
{
123-
static struct string_list existing_refs = { NULL, 0, 0, 0 };
123+
static struct string_list existing_refs = STRING_LIST_INIT_NODUP;
124124
char buf[1024];
125125
int matchlen = match ? strlen(match) : 0;
126126

diff-no-index.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,8 @@ static int queue_diff(struct diff_options *o,
6464

6565
if (S_ISDIR(mode1) || S_ISDIR(mode2)) {
6666
char buffer1[PATH_MAX], buffer2[PATH_MAX];
67-
struct string_list p1 = {NULL, 0, 0, 1}, p2 = {NULL, 0, 0, 1};
67+
struct string_list p1 = STRING_LIST_INIT_DUP;
68+
struct string_list p2 = STRING_LIST_INIT_DUP;
6869
int len1 = 0, len2 = 0, i1, i2, ret = 0;
6970

7071
if (name1 && read_directory(name1, &p1))

merge-recursive.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -806,7 +806,8 @@ static int process_renames(struct merge_options *o,
806806
struct string_list *b_renames)
807807
{
808808
int clean_merge = 1, i, j;
809-
struct string_list a_by_dst = {NULL, 0, 0, 0}, b_by_dst = {NULL, 0, 0, 0};
809+
struct string_list a_by_dst = STRING_LIST_INIT_NODUP;
810+
struct string_list b_by_dst = STRING_LIST_INIT_NODUP;
810811
const struct rename *sre;
811812

812813
for (i = 0; i < a_renames->nr; i++) {

remote.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -754,7 +754,7 @@ int for_each_remote(each_remote_fn fn, void *priv)
754754

755755
void ref_remove_duplicates(struct ref *ref_map)
756756
{
757-
struct string_list refs = { NULL, 0, 0, 0 };
757+
struct string_list refs = STRING_LIST_INIT_NODUP;
758758
struct string_list_item *item = NULL;
759759
struct ref *prev = NULL, *next = NULL;
760760
for (; ref_map; prev = ref_map, ref_map = next) {
@@ -1704,7 +1704,7 @@ static int get_stale_heads_cb(const char *refname,
17041704
struct ref *get_stale_heads(struct remote *remote, struct ref *fetch_map)
17051705
{
17061706
struct ref *ref, *stale_refs = NULL;
1707-
struct string_list ref_names = { NULL, 0, 0, 0 };
1707+
struct string_list ref_names = STRING_LIST_INIT_NODUP;
17081708
struct stale_heads_info info;
17091709
info.remote = remote;
17101710
info.ref_names = &ref_names;

rerere.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -426,8 +426,8 @@ static int update_paths(struct string_list *update)
426426

427427
static int do_plain_rerere(struct string_list *rr, int fd)
428428
{
429-
struct string_list conflict = { NULL, 0, 0, 1 };
430-
struct string_list update = { NULL, 0, 0, 1 };
429+
struct string_list conflict = STRING_LIST_INIT_DUP;
430+
struct string_list update = STRING_LIST_INIT_DUP;
431431
int i;
432432

433433
find_conflict(&conflict);
@@ -547,7 +547,7 @@ int setup_rerere(struct string_list *merge_rr, int flags)
547547

548548
int rerere(int flags)
549549
{
550-
struct string_list merge_rr = { NULL, 0, 0, 1 };
550+
struct string_list merge_rr = STRING_LIST_INIT_DUP;
551551
int fd;
552552

553553
fd = setup_rerere(&merge_rr, flags);
@@ -585,8 +585,8 @@ static int rerere_forget_one_path(const char *path, struct string_list *rr)
585585
int rerere_forget(const char **pathspec)
586586
{
587587
int i, fd;
588-
struct string_list conflict = { NULL, 0, 0, 1 };
589-
struct string_list merge_rr = { NULL, 0, 0, 1 };
588+
struct string_list conflict = STRING_LIST_INIT_DUP;
589+
struct string_list merge_rr = STRING_LIST_INIT_DUP;
590590

591591
if (read_cache() < 0)
592592
return error("Could not read index");

string-list.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ struct string_list
1212
unsigned int strdup_strings:1;
1313
};
1414

15+
#define STRING_LIST_INIT_NODUP { NULL, 0, 0, 0 }
16+
#define STRING_LIST_INIT_DUP { NULL, 0, 0, 1 }
17+
1518
void print_string_list(const struct string_list *p, const char *text);
1619
void string_list_clear(struct string_list *list, int free_util);
1720

transport-helper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -689,7 +689,7 @@ static int push_refs_with_export(struct transport *transport,
689689
struct child_process *helper, exporter;
690690
struct helper_data *data = transport->data;
691691
char *export_marks = NULL, *import_marks = NULL;
692-
struct string_list revlist_args = { NULL, 0, 0 };
692+
struct string_list revlist_args = STRING_LIST_INIT_NODUP;
693693
struct strbuf buf = STRBUF_INIT;
694694

695695
helper = get_helper(transport);

0 commit comments

Comments
 (0)