提交 6b5005c8 编写于 作者: J Junio C Hamano

Merge branch 'tf/string-list-init'

* tf/string-list-init:
  string_list: Add STRING_LIST_INIT macro and make use of it.
...@@ -566,7 +566,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix) ...@@ -566,7 +566,7 @@ int cmd_fast_export(int argc, const char **argv, const char *prefix)
{ {
struct rev_info revs; struct rev_info revs;
struct object_array commits = { 0, 0, NULL }; struct object_array commits = { 0, 0, NULL };
struct string_list extra_refs = { NULL, 0, 0, 0 }; struct string_list extra_refs = STRING_LIST_INIT_NODUP;
struct commit *commit; struct commit *commit;
char *export_filename = NULL, *import_filename = NULL; char *export_filename = NULL, *import_filename = NULL;
struct option options[] = { struct option options[] = {
......
...@@ -548,8 +548,8 @@ static void find_non_local_tags(struct transport *transport, ...@@ -548,8 +548,8 @@ static void find_non_local_tags(struct transport *transport,
struct ref **head, struct ref **head,
struct ref ***tail) struct ref ***tail)
{ {
struct string_list existing_refs = { NULL, 0, 0, 0 }; struct string_list existing_refs = STRING_LIST_INIT_NODUP;
struct string_list remote_refs = { NULL, 0, 0, 0 }; struct string_list remote_refs = STRING_LIST_INIT_NODUP;
const struct ref *ref; const struct ref *ref;
struct string_list_item *item = NULL; struct string_list_item *item = NULL;
...@@ -651,7 +651,7 @@ static int truncate_fetch_head(void) ...@@ -651,7 +651,7 @@ static int truncate_fetch_head(void)
static int do_fetch(struct transport *transport, static int do_fetch(struct transport *transport,
struct refspec *refs, int ref_count) struct refspec *refs, int ref_count)
{ {
struct string_list existing_refs = { NULL, 0, 0, 0 }; struct string_list existing_refs = STRING_LIST_INIT_NODUP;
struct string_list_item *peer_item = NULL; struct string_list_item *peer_item = NULL;
struct ref *ref_map; struct ref *ref_map;
struct ref *rm; struct ref *rm;
...@@ -875,7 +875,7 @@ static int fetch_one(struct remote *remote, int argc, const char **argv) ...@@ -875,7 +875,7 @@ static int fetch_one(struct remote *remote, int argc, const char **argv)
int cmd_fetch(int argc, const char **argv, const char *prefix) int cmd_fetch(int argc, const char **argv, const char *prefix)
{ {
int i; int i;
struct string_list list = { NULL, 0, 0, 0 }; struct string_list list = STRING_LIST_INIT_NODUP;
struct remote *remote; struct remote *remote;
int result = 0; int result = 0;
......
...@@ -38,8 +38,8 @@ void init_src_data(struct src_data *data) ...@@ -38,8 +38,8 @@ void init_src_data(struct src_data *data)
data->generic.strdup_strings = 1; data->generic.strdup_strings = 1;
} }
static struct string_list srcs = { NULL, 0, 0, 1 }; static struct string_list srcs = STRING_LIST_INIT_DUP;
static struct string_list origins = { NULL, 0, 0, 1 }; static struct string_list origins = STRING_LIST_INIT_DUP;
static int handle_line(char *line) static int handle_line(char *line)
{ {
...@@ -146,7 +146,7 @@ static void shortlog(const char *name, unsigned char *sha1, ...@@ -146,7 +146,7 @@ static void shortlog(const char *name, unsigned char *sha1,
int i, count = 0; int i, count = 0;
struct commit *commit; struct commit *commit;
struct object *branch; struct object *branch;
struct string_list subjects = { NULL, 0, 0, 1 }; struct string_list subjects = STRING_LIST_INIT_DUP;
int flags = UNINTERESTING | TREESAME | SEEN | SHOWN | ADDED; int flags = UNINTERESTING | TREESAME | SEEN | SHOWN | ADDED;
struct strbuf sb = STRBUF_INIT; struct strbuf sb = STRBUF_INIT;
......
...@@ -836,7 +836,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix) ...@@ -836,7 +836,7 @@ int cmd_grep(int argc, const char **argv, const char *prefix)
struct grep_opt opt; struct grep_opt opt;
struct object_array list = { 0, 0, NULL }; struct object_array list = { 0, 0, NULL };
const char **paths = NULL; const char **paths = NULL;
struct string_list path_list = { NULL, 0, 0, 0 }; struct string_list path_list = STRING_LIST_INIT_NODUP;
int i; int i;
int dummy; int dummy;
int nongit = 0, use_index = 1; int nongit = 0, use_index = 1;
......
...@@ -137,7 +137,7 @@ static int split_maildir(const char *maildir, const char *dir, ...@@ -137,7 +137,7 @@ static int split_maildir(const char *maildir, const char *dir,
char name[PATH_MAX]; char name[PATH_MAX];
int ret = -1; int ret = -1;
int i; int i;
struct string_list list = {NULL, 0, 0, 1}; struct string_list list = STRING_LIST_INIT_DUP;
if (populate_maildir_list(&list, maildir) < 0) if (populate_maildir_list(&list, maildir) < 0)
goto out; goto out;
......
...@@ -63,7 +63,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix) ...@@ -63,7 +63,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
const char **source, **destination, **dest_path; const char **source, **destination, **dest_path;
enum update_mode { BOTH = 0, WORKING_DIRECTORY, INDEX } *modes; enum update_mode { BOTH = 0, WORKING_DIRECTORY, INDEX } *modes;
struct stat st; struct stat st;
struct string_list src_for_dst = {NULL, 0, 0, 0}; struct string_list src_for_dst = STRING_LIST_INIT_NODUP;
git_config(git_default_config, NULL); git_config(git_default_config, NULL);
......
...@@ -530,7 +530,7 @@ static void check_aliased_update(struct command *cmd, struct string_list *list) ...@@ -530,7 +530,7 @@ static void check_aliased_update(struct command *cmd, struct string_list *list)
static void check_aliased_updates(struct command *commands) static void check_aliased_updates(struct command *commands)
{ {
struct command *cmd; struct command *cmd;
struct string_list ref_list = { NULL, 0, 0, 0 }; struct string_list ref_list = STRING_LIST_INIT_NODUP;
for (cmd = commands; cmd; cmd = cmd->next) { for (cmd = commands; cmd; cmd = cmd->next) {
struct string_list_item *item = struct string_list_item *item =
......
...@@ -134,7 +134,7 @@ static int add_branch(const char *key, const char *branchname, ...@@ -134,7 +134,7 @@ static int add_branch(const char *key, const char *branchname,
static int add(int argc, const char **argv) static int add(int argc, const char **argv)
{ {
int fetch = 0, mirror = 0, fetch_tags = TAGS_DEFAULT; int fetch = 0, mirror = 0, fetch_tags = TAGS_DEFAULT;
struct string_list track = { NULL, 0, 0 }; struct string_list track = STRING_LIST_INIT_NODUP;
const char *master = NULL; const char *master = NULL;
struct remote *remote; struct remote *remote;
struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT; struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT;
...@@ -596,7 +596,7 @@ static int mv(int argc, const char **argv) ...@@ -596,7 +596,7 @@ static int mv(int argc, const char **argv)
}; };
struct remote *oldremote, *newremote; struct remote *oldremote, *newremote;
struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT, buf3 = STRBUF_INIT; struct strbuf buf = STRBUF_INIT, buf2 = STRBUF_INIT, buf3 = STRBUF_INIT;
struct string_list remote_branches = { NULL, 0, 0, 0 }; struct string_list remote_branches = STRING_LIST_INIT_NODUP;
struct rename_info rename; struct rename_info rename;
int i; int i;
...@@ -734,8 +734,8 @@ static int rm(int argc, const char **argv) ...@@ -734,8 +734,8 @@ static int rm(int argc, const char **argv)
struct remote *remote; struct remote *remote;
struct strbuf buf = STRBUF_INIT; struct strbuf buf = STRBUF_INIT;
struct known_remotes known_remotes = { NULL, NULL }; struct known_remotes known_remotes = { NULL, NULL };
struct string_list branches = { NULL, 0, 0, 1 }; struct string_list branches = STRING_LIST_INIT_DUP;
struct string_list skipped = { NULL, 0, 0, 1 }; struct string_list skipped = STRING_LIST_INIT_DUP;
struct branches_for_remote cb_data; struct branches_for_remote cb_data;
int i, result; int i, result;
...@@ -1044,7 +1044,7 @@ static int show(int argc, const char **argv) ...@@ -1044,7 +1044,7 @@ static int show(int argc, const char **argv)
OPT_END() OPT_END()
}; };
struct ref_states states; struct ref_states states;
struct string_list info_list = { NULL, 0, 0, 0 }; struct string_list info_list = STRING_LIST_INIT_NODUP;
struct show_info info; struct show_info info;
argc = parse_options(argc, argv, NULL, options, builtin_remote_show_usage, 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,7 +1483,7 @@ static int get_one_entry(struct remote *remote, void *priv)
static int show_all(void) static int show_all(void)
{ {
struct string_list list = { NULL, 0, 0 }; struct string_list list = STRING_LIST_INIT_NODUP;
int result; int result;
list.strdup_strings = 1; list.strdup_strings = 1;
......
...@@ -40,7 +40,7 @@ static int git_rerere_gc_config(const char *var, const char *value, void *cb) ...@@ -40,7 +40,7 @@ static int git_rerere_gc_config(const char *var, const char *value, void *cb)
static void garbage_collect(struct string_list *rr) static void garbage_collect(struct string_list *rr)
{ {
struct string_list to_remove = { NULL, 0, 0, 1 }; struct string_list to_remove = STRING_LIST_INIT_DUP;
DIR *dir; DIR *dir;
struct dirent *e; struct dirent *e;
int i, cutoff; int i, cutoff;
...@@ -102,7 +102,7 @@ static int diff_two(const char *file1, const char *label1, ...@@ -102,7 +102,7 @@ static int diff_two(const char *file1, const char *label1,
int cmd_rerere(int argc, const char **argv, const char *prefix) int cmd_rerere(int argc, const char **argv, const char *prefix)
{ {
struct string_list merge_rr = { NULL, 0, 0, 1 }; struct string_list merge_rr = STRING_LIST_INIT_DUP;
int i, fd, flags = 0; int i, fd, flags = 0;
if (2 < argc) { if (2 < argc) {
......
...@@ -120,7 +120,7 @@ static int add_existing(const char *refname, const unsigned char *sha1, int flag ...@@ -120,7 +120,7 @@ static int add_existing(const char *refname, const unsigned char *sha1, int flag
*/ */
static int exclude_existing(const char *match) static int exclude_existing(const char *match)
{ {
static struct string_list existing_refs = { NULL, 0, 0, 0 }; static struct string_list existing_refs = STRING_LIST_INIT_NODUP;
char buf[1024]; char buf[1024];
int matchlen = match ? strlen(match) : 0; int matchlen = match ? strlen(match) : 0;
......
...@@ -64,7 +64,8 @@ static int queue_diff(struct diff_options *o, ...@@ -64,7 +64,8 @@ static int queue_diff(struct diff_options *o,
if (S_ISDIR(mode1) || S_ISDIR(mode2)) { if (S_ISDIR(mode1) || S_ISDIR(mode2)) {
char buffer1[PATH_MAX], buffer2[PATH_MAX]; char buffer1[PATH_MAX], buffer2[PATH_MAX];
struct string_list p1 = {NULL, 0, 0, 1}, p2 = {NULL, 0, 0, 1}; struct string_list p1 = STRING_LIST_INIT_DUP;
struct string_list p2 = STRING_LIST_INIT_DUP;
int len1 = 0, len2 = 0, i1, i2, ret = 0; int len1 = 0, len2 = 0, i1, i2, ret = 0;
if (name1 && read_directory(name1, &p1)) if (name1 && read_directory(name1, &p1))
......
...@@ -800,7 +800,8 @@ static int process_renames(struct merge_options *o, ...@@ -800,7 +800,8 @@ static int process_renames(struct merge_options *o,
struct string_list *b_renames) struct string_list *b_renames)
{ {
int clean_merge = 1, i, j; int clean_merge = 1, i, j;
struct string_list a_by_dst = {NULL, 0, 0, 0}, b_by_dst = {NULL, 0, 0, 0}; struct string_list a_by_dst = STRING_LIST_INIT_NODUP;
struct string_list b_by_dst = STRING_LIST_INIT_NODUP;
const struct rename *sre; const struct rename *sre;
for (i = 0; i < a_renames->nr; i++) { for (i = 0; i < a_renames->nr; i++) {
......
...@@ -754,7 +754,7 @@ int for_each_remote(each_remote_fn fn, void *priv) ...@@ -754,7 +754,7 @@ int for_each_remote(each_remote_fn fn, void *priv)
void ref_remove_duplicates(struct ref *ref_map) void ref_remove_duplicates(struct ref *ref_map)
{ {
struct string_list refs = { NULL, 0, 0, 0 }; struct string_list refs = STRING_LIST_INIT_NODUP;
struct string_list_item *item = NULL; struct string_list_item *item = NULL;
struct ref *prev = NULL, *next = NULL; struct ref *prev = NULL, *next = NULL;
for (; ref_map; prev = ref_map, ref_map = next) { for (; ref_map; prev = ref_map, ref_map = next) {
...@@ -1704,7 +1704,7 @@ static int get_stale_heads_cb(const char *refname, ...@@ -1704,7 +1704,7 @@ static int get_stale_heads_cb(const char *refname,
struct ref *get_stale_heads(struct remote *remote, struct ref *fetch_map) struct ref *get_stale_heads(struct remote *remote, struct ref *fetch_map)
{ {
struct ref *ref, *stale_refs = NULL; struct ref *ref, *stale_refs = NULL;
struct string_list ref_names = { NULL, 0, 0, 0 }; struct string_list ref_names = STRING_LIST_INIT_NODUP;
struct stale_heads_info info; struct stale_heads_info info;
info.remote = remote; info.remote = remote;
info.ref_names = &ref_names; info.ref_names = &ref_names;
......
...@@ -426,8 +426,8 @@ static int update_paths(struct string_list *update) ...@@ -426,8 +426,8 @@ static int update_paths(struct string_list *update)
static int do_plain_rerere(struct string_list *rr, int fd) static int do_plain_rerere(struct string_list *rr, int fd)
{ {
struct string_list conflict = { NULL, 0, 0, 1 }; struct string_list conflict = STRING_LIST_INIT_DUP;
struct string_list update = { NULL, 0, 0, 1 }; struct string_list update = STRING_LIST_INIT_DUP;
int i; int i;
find_conflict(&conflict); find_conflict(&conflict);
...@@ -547,7 +547,7 @@ int setup_rerere(struct string_list *merge_rr, int flags) ...@@ -547,7 +547,7 @@ int setup_rerere(struct string_list *merge_rr, int flags)
int rerere(int flags) int rerere(int flags)
{ {
struct string_list merge_rr = { NULL, 0, 0, 1 }; struct string_list merge_rr = STRING_LIST_INIT_DUP;
int fd; int fd;
fd = setup_rerere(&merge_rr, flags); fd = setup_rerere(&merge_rr, flags);
...@@ -585,8 +585,8 @@ static int rerere_forget_one_path(const char *path, struct string_list *rr) ...@@ -585,8 +585,8 @@ static int rerere_forget_one_path(const char *path, struct string_list *rr)
int rerere_forget(const char **pathspec) int rerere_forget(const char **pathspec)
{ {
int i, fd; int i, fd;
struct string_list conflict = { NULL, 0, 0, 1 }; struct string_list conflict = STRING_LIST_INIT_DUP;
struct string_list merge_rr = { NULL, 0, 0, 1 }; struct string_list merge_rr = STRING_LIST_INIT_DUP;
if (read_cache() < 0) if (read_cache() < 0)
return error("Could not read index"); return error("Could not read index");
......
...@@ -12,6 +12,9 @@ struct string_list ...@@ -12,6 +12,9 @@ struct string_list
unsigned int strdup_strings:1; unsigned int strdup_strings:1;
}; };
#define STRING_LIST_INIT_NODUP { NULL, 0, 0, 0 }
#define STRING_LIST_INIT_DUP { NULL, 0, 0, 1 }
void print_string_list(const struct string_list *p, const char *text); void print_string_list(const struct string_list *p, const char *text);
void string_list_clear(struct string_list *list, int free_util); void string_list_clear(struct string_list *list, int free_util);
......
...@@ -689,7 +689,7 @@ static int push_refs_with_export(struct transport *transport, ...@@ -689,7 +689,7 @@ static int push_refs_with_export(struct transport *transport,
struct child_process *helper, exporter; struct child_process *helper, exporter;
struct helper_data *data = transport->data; struct helper_data *data = transport->data;
char *export_marks = NULL, *import_marks = NULL; char *export_marks = NULL, *import_marks = NULL;
struct string_list revlist_args = { NULL, 0, 0 }; struct string_list revlist_args = STRING_LIST_INIT_NODUP;
struct strbuf buf = STRBUF_INIT; struct strbuf buf = STRBUF_INIT;
helper = get_helper(transport); helper = get_helper(transport);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册