Skip to content

Commit b8b6365

Browse files
committed
Merge branch 'jk/string-list-static-init'
Instead of taking advantage of a struct string_list that is allocated with all NULs happens to be STRING_LIST_INIT_NODUP kind, initialize them explicitly as such, to document their behaviour better. * jk/string-list-static-init: use string_list initializer consistently blame,shortlog: don't make local option variables static interpret-trailers: don't duplicate option strings parse_opt_string_list: stop allocating new strings
2 parents 7e58b81 + 2721ce2 commit b8b6365

File tree

11 files changed

+24
-21
lines changed

11 files changed

+24
-21
lines changed

builtin/apply.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4667,6 +4667,9 @@ static void init_apply_state(struct apply_state *state,
46674667
state->ws_error_action = warn_on_ws_error;
46684668
state->ws_ignore_action = ignore_ws_none;
46694669
state->linenr = 1;
4670+
string_list_init(&state->fn_table, 0);
4671+
string_list_init(&state->limit_by_name, 0);
4672+
string_list_init(&state->symlink_changes, 0);
46704673
strbuf_init(&state->root, 0);
46714674

46724675
git_apply_config();

builtin/blame.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ static int show_progress;
5656
static struct date_mode blame_date_mode = { DATE_ISO8601 };
5757
static size_t blame_date_width;
5858

59-
static struct string_list mailmap;
59+
static struct string_list mailmap = STRING_LIST_INIT_NODUP;
6060

6161
#ifndef DEBUG
6262
#define DEBUG 0
@@ -2520,12 +2520,12 @@ int cmd_blame(int argc, const char **argv, const char *prefix)
25202520
enum object_type type;
25212521
struct commit *final_commit = NULL;
25222522

2523-
static struct string_list range_list;
2524-
static int output_option = 0, opt = 0;
2525-
static int show_stats = 0;
2526-
static const char *revs_file = NULL;
2527-
static const char *contents_from = NULL;
2528-
static const struct option options[] = {
2523+
struct string_list range_list = STRING_LIST_INIT_NODUP;
2524+
int output_option = 0, opt = 0;
2525+
int show_stats = 0;
2526+
const char *revs_file = NULL;
2527+
const char *contents_from = NULL;
2528+
const struct option options[] = {
25292529
OPT_BOOL(0, "incremental", &incremental, N_("Show blame entries as we find them, incrementally")),
25302530
OPT_BOOL('b', NULL, &blank_boundary, N_("Show blank SHA-1 for boundary commits (Default: off)")),
25312531
OPT_BOOL(0, "root", &show_root, N_("Do not treat root commits as boundaries (Default: off)")),

builtin/clone.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ static char *option_upload_pack = "git-upload-pack";
4949
static int option_verbosity;
5050
static int option_progress = -1;
5151
static enum transport_family family;
52-
static struct string_list option_config;
53-
static struct string_list option_reference;
52+
static struct string_list option_config = STRING_LIST_INIT_NODUP;
53+
static struct string_list option_reference = STRING_LIST_INIT_NODUP;
5454
static int option_dissociate;
5555
static int max_jobs = -1;
5656

builtin/interpret-trailers.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ int cmd_interpret_trailers(int argc, const char **argv, const char *prefix)
2020
{
2121
int in_place = 0;
2222
int trim_empty = 0;
23-
struct string_list trailers = STRING_LIST_INIT_DUP;
23+
struct string_list trailers = STRING_LIST_INIT_NODUP;
2424

2525
struct option options[] = {
2626
OPT_BOOL(0, "in-place", &in_place, N_("edit files in place")),

builtin/log.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -674,9 +674,9 @@ static int auto_number = 1;
674674

675675
static char *default_attach = NULL;
676676

677-
static struct string_list extra_hdr;
678-
static struct string_list extra_to;
679-
static struct string_list extra_cc;
677+
static struct string_list extra_hdr = STRING_LIST_INIT_NODUP;
678+
static struct string_list extra_to = STRING_LIST_INIT_NODUP;
679+
static struct string_list extra_cc = STRING_LIST_INIT_NODUP;
680680

681681
static void add_header(const char *value)
682682
{

builtin/remote.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -247,7 +247,7 @@ struct branch_info {
247247
enum { NO_REBASE, NORMAL_REBASE, INTERACTIVE_REBASE } rebase;
248248
};
249249

250-
static struct string_list branch_list;
250+
static struct string_list branch_list = STRING_LIST_INIT_NODUP;
251251

252252
static const char *abbrev_ref(const char *name, const char *prefix)
253253
{

builtin/shortlog.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -233,11 +233,11 @@ void shortlog_init(struct shortlog *log)
233233

234234
int cmd_shortlog(int argc, const char **argv, const char *prefix)
235235
{
236-
static struct shortlog log;
237-
static struct rev_info rev;
236+
struct shortlog log = { STRING_LIST_INIT_NODUP };
237+
struct rev_info rev;
238238
int nongit = !startup_info->have_repository;
239239

240-
static const struct option options[] = {
240+
const struct option options[] = {
241241
OPT_BOOL('n', "numbered", &log.sort_by_number,
242242
N_("sort output according to the number of commits per author")),
243243
OPT_BOOL('s', "summary", &log.summary,

notes.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -70,7 +70,7 @@ struct non_note {
7070

7171
struct notes_tree default_notes_tree;
7272

73-
static struct string_list display_notes_refs;
73+
static struct string_list display_notes_refs = STRING_LIST_INIT_NODUP;
7474
static struct notes_tree **display_notes_trees;
7575

7676
static void load_subtree(struct notes_tree *t, struct leaf_node *subtree,

parse-options-cb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ int parse_opt_string_list(const struct option *opt, const char *arg, int unset)
144144
if (!arg)
145145
return -1;
146146

147-
string_list_append(v, xstrdup(arg));
147+
string_list_append(v, arg);
148148
return 0;
149149
}
150150

submodule.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@
1717

1818
static int config_fetch_recurse_submodules = RECURSE_SUBMODULES_ON_DEMAND;
1919
static int parallel_jobs = 1;
20-
static struct string_list changed_submodule_paths;
20+
static struct string_list changed_submodule_paths = STRING_LIST_INIT_NODUP;
2121
static int initialized_fetch_ref_tips;
2222
static struct sha1_array ref_tips_before_fetch;
2323
static struct sha1_array ref_tips_after_fetch;

0 commit comments

Comments
 (0)