@matheusbsbs / matheus-bagliano / commits / 183113a5ca
Fork 0

string_list: Add STRING_LIST_INIT macro and make use of it.

Acked-by: Jonathan Nieder <jrnieder@gmail.com> Signed-off-by: Thiago Farina <tfransosi@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Thiago Farina committed Jul 4, 2010 at 16:46 UTC 183113a5ca99cb228b2ba0a29e53f1ac11f2c7c2
16 files changed +36 -31
builtin/fast-export.c
+1 -1
@@ -566,7 +566,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
566 {
567 struct rev_info revs;
568 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;
570 struct commit *commit;
571 char *export_filename = NULL, *import_filename = NULL;
572 struct option options[] = {
builtin/fetch.c
+4 -4
@@ -548,8 +548,8 @@ static void find_non_local_tags(struct transport *transport,
548 struct ref **head,
549 struct ref ***tail)
550 {
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;
553 const struct ref *ref;
554 struct string_list_item *item = NULL;
555
@@ -651,7 +651,7 @@ static int truncate_fetch_head(void)
651 static int do_fetch(struct transport *transport,
652 struct refspec *refs, int ref_count)
653 {
654 - struct string_list existing_refs = { NULL, 0, 0, 0 };
654 + struct string_list existing_refs = STRING_LIST_INIT_NODUP;
655 struct string_list_item *peer_item = NULL;
656 struct ref *ref_map;
657 struct ref *rm;
@@ -874,7 +874,7 @@ static int fetch_one(struct remote *remote, int argc, const char **argv)
874 int cmd_fetch(int argc, const char **argv, const char *prefix)
875 {
876 int i;
877 - struct string_list list = { NULL, 0, 0, 0 };
877 + struct string_list list = STRING_LIST_INIT_NODUP;
878 struct remote *remote;
879 int result = 0;
880
builtin/fmt-merge-msg.c
+3 -3
@@ -38,8 +38,8 @@ void init_src_data(struct src_data *data)
38 data->generic.strdup_strings = 1;
39 }
40
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;
43
44 static int handle_line(char *line)
45 {
@@ -146,7 +146,7 @@ static void shortlog(const char *name, unsigned char *sha1,
146 int i, count = 0;
147 struct commit *commit;
148 struct object *branch;
149 - struct string_list subjects = { NULL, 0, 0, 1 };
149 + struct string_list subjects = STRING_LIST_INIT_DUP;
150 int flags = UNINTERESTING | TREESAME | SEEN | SHOWN | ADDED;
151 struct strbuf sb = STRBUF_INIT;
152
builtin/grep.c
+1 -1
@@ -836,7 +836,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
836 struct grep_opt opt;
837 struct object_array list = { 0, 0, NULL };
838 const char **paths = NULL;
839 - struct string_list path_list = { NULL, 0, 0, 0 };
839 + struct string_list path_list = STRING_LIST_INIT_NODUP;
840 int i;
841 int dummy;
842 int nongit = 0, use_index = 1;
builtin/mailsplit.c
+1 -1
@@ -137,7 +137,7 @@ static int split_maildir(const char *maildir, const char *dir,
137 char name[PATH_MAX];
138 int ret = -1;
139 int i;
140 - struct string_list list = {NULL, 0, 0, 1};
140 + struct string_list list = STRING_LIST_INIT_DUP;
141
142 if (populate_maildir_list(&list, maildir) < 0)
143 goto out;
builtin/mv.c
+1 -1
@@ -63,7 +63,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
63 const char **source, **destination, **dest_path;
64 enum update_mode { BOTH = 0, WORKING_DIRECTORY, INDEX } *modes;
65 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;
67
68 git_config(git_default_config, NULL);
69
builtin/receive-pack.c
+1 -1
@@ -530,7 +530,7 @@ static void check_aliased_update(struct command *cmd, struct string_list *list)
530 static void check_aliased_updates(struct command *commands)
531 {
532 struct command *cmd;
533 - struct string_list ref_list = { NULL, 0, 0, 0 };
533 + struct string_list ref_list = STRING_LIST_INIT_NODUP;
534
535 for (cmd = commands; cmd; cmd = cmd->next) {
536 struct string_list_item *item =
builtin/remote.c
+6 -6
@@ -134,7 +134,7 @@ static int add_branch(const char *key, const char *branchname,
134 static int add(int argc, const char **argv)
135 {
136 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;
138 const char *master = NULL;
139 struct remote *remote;
140 struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT;
@@ -596,7 +596,7 @@ static int mv(int argc, const char **argv)
596 };
597 struct remote *oldremote, *newremote;
598 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;
600 struct rename_info rename;
601 int i;
602
@@ -734,8 +734,8 @@ static int rm(int argc, const char **argv)
734 struct remote *remote;
735 struct strbuf buf = STRBUF_INIT;
736 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;
739 struct branches_for_remote cb_data;
740 int i, result;
741
@@ -1044,7 +1044,7 @@ static int show(int argc, const char **argv)
1044 OPT_END()
1045 };
1046 struct ref_states states;
1047 - struct string_list info_list = { NULL, 0, 0, 0 };
1047 + struct string_list info_list = STRING_LIST_INIT_NODUP;
1048 struct show_info info;
1049
1050 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)
1483
1484 static int show_all(void)
1485 {
1486 - struct string_list list = { NULL, 0, 0 };
1486 + struct string_list list = STRING_LIST_INIT_NODUP;
1487 int result;
1488
1489 list.strdup_strings = 1;
builtin/rerere.c
+2 -2
@@ -40,7 +40,7 @@ static int git_rerere_gc_config(const char *var, const char *value, void *cb)
40
41 static void garbage_collect(struct string_list *rr)
42 {
43 - struct string_list to_remove = { NULL, 0, 0, 1 };
43 + struct string_list to_remove = STRING_LIST_INIT_DUP;
44 DIR *dir;
45 struct dirent *e;
46 int i, cutoff;
@@ -102,7 +102,7 @@ static int diff_two(const char *file1, const char *label1,
102
103 int cmd_rerere(int argc, const char **argv, const char *prefix)
104 {
105 - struct string_list merge_rr = { NULL, 0, 0, 1 };
105 + struct string_list merge_rr = STRING_LIST_INIT_DUP;
106 int i, fd, flags = 0;
107
108 if (2 < argc) {
builtin/show-ref.c
+1 -1
@@ -120,7 +120,7 @@ static int add_existing(const char *refname, const unsigned char *sha1, int flag
120 */
121 static int exclude_existing(const char *match)
122 {
123 - static struct string_list existing_refs = { NULL, 0, 0, 0 };
123 + static struct string_list existing_refs = STRING_LIST_INIT_NODUP;
124 char buf[1024];
125 int matchlen = match ? strlen(match) : 0;
126
diff-no-index.c
+2 -1
@@ -64,7 +64,8 @@ static int queue_diff(struct diff_options *o,
64
65 if (S_ISDIR(mode1) || S_ISDIR(mode2)) {
66 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;
69 int len1 = 0, len2 = 0, i1, i2, ret = 0;
70
71 if (name1 && read_directory(name1, &p1))
merge-recursive.c
+2 -1
@@ -806,7 +806,8 @@ static int process_renames(struct merge_options *o,
806 struct string_list *b_renames)
807 {
808 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;
811 const struct rename *sre;
812
813 for (i = 0; i < a_renames->nr; i++) {
remote.c
+2 -2
@@ -754,7 +754,7 @@ int for_each_remote(each_remote_fn fn, void *priv)
754
755 void ref_remove_duplicates(struct ref *ref_map)
756 {
757 - struct string_list refs = { NULL, 0, 0, 0 };
757 + struct string_list refs = STRING_LIST_INIT_NODUP;
758 struct string_list_item *item = NULL;
759 struct ref *prev = NULL, *next = NULL;
760 for (; ref_map; prev = ref_map, ref_map = next) {
@@ -1704,7 +1704,7 @@ static int get_stale_heads_cb(const char *refname,
1704 struct ref *get_stale_heads(struct remote *remote, struct ref *fetch_map)
1705 {
1706 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;
1708 struct stale_heads_info info;
1709 info.remote = remote;
1710 info.ref_names = &ref_names;
rerere.c
+5 -5
@@ -426,8 +426,8 @@ static int update_paths(struct string_list *update)
426
427 static int do_plain_rerere(struct string_list *rr, int fd)
428 {
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;
431 int i;
432
433 find_conflict(&conflict);
@@ -547,7 +547,7 @@ int setup_rerere(struct string_list *merge_rr, int flags)
547
548 int rerere(int flags)
549 {
550 - struct string_list merge_rr = { NULL, 0, 0, 1 };
550 + struct string_list merge_rr = STRING_LIST_INIT_DUP;
551 int fd;
552
553 fd = setup_rerere(&merge_rr, flags);
@@ -585,8 +585,8 @@ static int rerere_forget_one_path(const char *path, struct string_list *rr)
585 int rerere_forget(const char **pathspec)
586 {
587 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;
590
591 if (read_cache() < 0)
592 return error("Could not read index");
string-list.h
+3
@@ -12,6 +12,9 @@ struct string_list
12 unsigned int strdup_strings:1;
13 };
14
15 +#define STRING_LIST_INIT_NODUP { NULL, 0, 0, 0 }
16 +#define STRING_LIST_INIT_DUP { NULL, 0, 0, 1 }
17 +
18 void print_string_list(const struct string_list *p, const char *text);
19 void string_list_clear(struct string_list *list, int free_util);
20
transport-helper.c
+1 -1
@@ -689,7 +689,7 @@ static int push_refs_with_export(struct transport *transport,
689 struct child_process *helper, exporter;
690 struct helper_data *data = transport->data;
691 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;
693 struct strbuf buf = STRBUF_INIT;
694
695 helper = get_helper(transport);