Skip to content

Commit bd4232f

Browse files
committed
Merge branch 'ab/struct-init'
Code cleanup around struct_type_init() functions. * ab/struct-init: string-list.h users: change to use *_{nodup,dup}() string-list.[ch]: add a string_list_init_{nodup,dup}() dir.[ch]: replace dir_init() with DIR_INIT *.c *_init(): define in terms of corresponding *_INIT macro *.h: move some *_INIT to designated initializers
2 parents 832a239 + bc40dfb commit bd4232f

29 files changed

+76
-64
lines changed

apply.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -101,9 +101,9 @@ int init_apply_state(struct apply_state *state,
101101
state->ws_error_action = warn_on_ws_error;
102102
state->ws_ignore_action = ignore_ws_none;
103103
state->linenr = 1;
104-
string_list_init(&state->fn_table, 0);
105-
string_list_init(&state->limit_by_name, 0);
106-
string_list_init(&state->symlink_changes, 0);
104+
string_list_init_nodup(&state->fn_table);
105+
string_list_init_nodup(&state->limit_by_name);
106+
string_list_init_nodup(&state->symlink_changes);
107107
strbuf_init(&state->root, 0);
108108

109109
git_apply_config();

archive.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ int write_archive(int argc, const char **argv, const char *prefix,
645645
args.pretty_ctx = &ctx;
646646
args.repo = repo;
647647
args.prefix = prefix;
648-
string_list_init(&args.extra_files, 1);
648+
string_list_init_dup(&args.extra_files);
649649
argc = parse_archive_args(argc, argv, &ar, &args, name_hint, remote);
650650
if (!startup_info->have_repository) {
651651
/*

builtin/add.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -470,7 +470,7 @@ int cmd_add(int argc, const char **argv, const char *prefix)
470470
{
471471
int exit_status = 0;
472472
struct pathspec pathspec;
473-
struct dir_struct dir;
473+
struct dir_struct dir = DIR_INIT;
474474
int flags;
475475
int add_new_files;
476476
int require_pathspec;
@@ -577,7 +577,6 @@ int cmd_add(int argc, const char **argv, const char *prefix)
577577
die_in_unpopulated_submodule(&the_index, prefix);
578578
die_path_inside_submodule(&the_index, &pathspec);
579579

580-
dir_init(&dir);
581580
if (add_new_files) {
582581
int baselen;
583582

builtin/check-ignore.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ static int check_ignore_stdin_paths(struct dir_struct *dir, const char *prefix)
153153
int cmd_check_ignore(int argc, const char **argv, const char *prefix)
154154
{
155155
int num_ignored;
156-
struct dir_struct dir;
156+
struct dir_struct dir = DIR_INIT;
157157

158158
git_config(git_default_config, NULL);
159159

@@ -182,7 +182,6 @@ int cmd_check_ignore(int argc, const char **argv, const char *prefix)
182182
if (!no_index && read_cache() < 0)
183183
die(_("index file corrupt"));
184184

185-
dir_init(&dir);
186185
setup_standard_excludes(&dir);
187186

188187
if (stdin_paths) {

builtin/clean.c

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -641,7 +641,7 @@ static int clean_cmd(void)
641641

642642
static int filter_by_patterns_cmd(void)
643643
{
644-
struct dir_struct dir;
644+
struct dir_struct dir = DIR_INIT;
645645
struct strbuf confirm = STRBUF_INIT;
646646
struct strbuf **ignore_list;
647647
struct string_list_item *item;
@@ -665,7 +665,6 @@ static int filter_by_patterns_cmd(void)
665665
if (!confirm.len)
666666
break;
667667

668-
dir_init(&dir);
669668
pl = add_pattern_list(&dir, EXC_CMDL, "manual exclude");
670669
ignore_list = strbuf_split_max(&confirm, ' ', 0);
671670

@@ -890,7 +889,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
890889
int ignored_only = 0, config_set = 0, errors = 0, gone = 1;
891890
int rm_flags = REMOVE_DIR_KEEP_NESTED_GIT;
892891
struct strbuf abs_path = STRBUF_INIT;
893-
struct dir_struct dir;
892+
struct dir_struct dir = DIR_INIT;
894893
struct pathspec pathspec;
895894
struct strbuf buf = STRBUF_INIT;
896895
struct string_list exclude_list = STRING_LIST_INIT_NODUP;
@@ -921,7 +920,6 @@ int cmd_clean(int argc, const char **argv, const char *prefix)
921920
argc = parse_options(argc, argv, prefix, options, builtin_clean_usage,
922921
0);
923922

924-
dir_init(&dir);
925923
if (!interactive && !dry_run && !force) {
926924
if (config_set)
927925
die(_("clean.requireForce set to true and neither -i, -n, nor -f given; "

builtin/grep.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -704,10 +704,9 @@ static int grep_objects(struct grep_opt *opt, const struct pathspec *pathspec,
704704
static int grep_directory(struct grep_opt *opt, const struct pathspec *pathspec,
705705
int exc_std, int use_index)
706706
{
707-
struct dir_struct dir;
707+
struct dir_struct dir = DIR_INIT;
708708
int i, hit = 0;
709709

710-
dir_init(&dir);
711710
if (!use_index)
712711
dir.flags |= DIR_NO_GITLINKS;
713712
if (exc_std)

builtin/ls-files.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -608,7 +608,7 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
608608
{
609609
int require_work_tree = 0, show_tag = 0, i;
610610
char *max_prefix;
611-
struct dir_struct dir;
611+
struct dir_struct dir = DIR_INIT;
612612
struct pattern_list *pl;
613613
struct string_list exclude_list = STRING_LIST_INIT_NODUP;
614614
struct option builtin_ls_files_options[] = {
@@ -678,7 +678,6 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix)
678678
if (argc == 2 && !strcmp(argv[1], "-h"))
679679
usage_with_options(ls_files_usage, builtin_ls_files_options);
680680

681-
dir_init(&dir);
682681
prefix = cmd_prefix;
683682
if (prefix)
684683
prefix_len = strlen(prefix);

builtin/stash.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -991,9 +991,8 @@ static int get_untracked_files(const struct pathspec *ps, int include_untracked,
991991
{
992992
int i;
993993
int found = 0;
994-
struct dir_struct dir;
994+
struct dir_struct dir = DIR_INIT;
995995

996-
dir_init(&dir);
997996
if (include_untracked != INCLUDE_ALL_FILES)
998997
setup_standard_excludes(&dir);
999998

config.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2073,7 +2073,7 @@ static int configset_add_value(struct config_set *cs, const char *key, const cha
20732073
e = xmalloc(sizeof(*e));
20742074
hashmap_entry_init(&e->ent, strhash(key));
20752075
e->key = xstrdup(key);
2076-
string_list_init(&e->value_list, 1);
2076+
string_list_init_dup(&e->value_list);
20772077
hashmap_add(&cs->config_hash, &e->ent);
20782078
}
20792079
si = string_list_append_nodup(&e->value_list, xstrdup_or_null(value));

credential.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,8 @@
1010

1111
void credential_init(struct credential *c)
1212
{
13-
memset(c, 0, sizeof(*c));
14-
c->helpers.strdup_strings = 1;
13+
struct credential blank = CREDENTIAL_INIT;
14+
memcpy(c, &blank, sizeof(*c));
1515
}
1616

1717
void credential_clear(struct credential *c)

0 commit comments

Comments
 (0)