Merge branch 'ab/c99-designated-initializers'

Use designated initializers we started using in mid 2017 in more
parts of the codebase that are relatively quiescent.

* ab/c99-designated-initializers:
  fast-import.c: use designated initializers for "partial" struct assignments
  refspec.c: use designated initializers for "struct refspec_item"
  convert.c: use designated initializers for "struct stream_filter*"
  userdiff.c: use designated initializers for "struct userdiff_driver"
  archive-*.c: use designated initializers for "struct archiver"
  object-file: use designated initializers for "struct git_hash_algo"
  trace2: use designated initializers for "struct tr2_dst"
  trace2: use designated initializers for "struct tr2_tgt"
  imap-send.c: use designated initializers for "struct imap_server_conf"
This commit is contained in:
Junio C Hamano 2022-03-06 21:25:32 -08:00
commit 20d34c07ea
11 changed files with 187 additions and 177 deletions

View File

@ -461,9 +461,9 @@ static int write_tar_filter_archive(const struct archiver *ar,
}
static struct archiver tar_archiver = {
"tar",
write_tar_archive,
ARCHIVER_REMOTE
.name = "tar",
.write_archive = write_tar_archive,
.flags = ARCHIVER_REMOTE,
};
void init_tar_archiver(void)

View File

@ -638,9 +638,9 @@ static int write_zip_archive(const struct archiver *ar,
}
static struct archiver zip_archiver = {
"zip",
write_zip_archive,
ARCHIVER_WANT_COMPRESSION_LEVELS|ARCHIVER_REMOTE
.name = "zip",
.write_archive = write_zip_archive,
.flags = ARCHIVER_WANT_COMPRESSION_LEVELS|ARCHIVER_REMOTE,
};
void init_zip_archiver(void)

View File

@ -177,8 +177,9 @@ static int global_argc;
static const char **global_argv;
/* Memory pools */
static struct mem_pool fi_mem_pool = {NULL, 2*1024*1024 -
sizeof(struct mp_block), 0 };
static struct mem_pool fi_mem_pool = {
.block_alloc = 2*1024*1024 - sizeof(struct mp_block),
};
/* Atom management */
static unsigned int atom_table_sz = 4451;
@ -206,7 +207,9 @@ static int import_marks_file_done;
static int relative_marks_paths;
/* Our last blob */
static struct last_object last_blob = { STRBUF_INIT, 0, 0, 0 };
static struct last_object last_blob = {
.data = STRBUF_INIT,
};
/* Tree management */
static unsigned int tree_entry_alloc = 1000;
@ -232,7 +235,10 @@ static struct tag *last_tag;
static whenspec_type whenspec = WHENSPEC_RAW;
static struct strbuf command_buf = STRBUF_INIT;
static int unread_command_buf;
static struct recent_command cmd_hist = {&cmd_hist, &cmd_hist, NULL};
static struct recent_command cmd_hist = {
.prev = &cmd_hist,
.next = &cmd_hist,
};
static struct recent_command *cmd_tail = &cmd_hist;
static struct recent_command *rc_free;
static unsigned int cmd_save = 100;

View File

@ -1574,12 +1574,12 @@ static void null_free_fn(struct stream_filter *filter)
}
static struct stream_filter_vtbl null_vtbl = {
null_filter_fn,
null_free_fn,
.filter = null_filter_fn,
.free = null_free_fn,
};
static struct stream_filter null_filter_singleton = {
&null_vtbl,
.vtbl = &null_vtbl,
};
int is_null_stream_filter(struct stream_filter *filter)
@ -1683,8 +1683,8 @@ static void lf_to_crlf_free_fn(struct stream_filter *filter)
}
static struct stream_filter_vtbl lf_to_crlf_vtbl = {
lf_to_crlf_filter_fn,
lf_to_crlf_free_fn,
.filter = lf_to_crlf_filter_fn,
.free = lf_to_crlf_free_fn,
};
static struct stream_filter *lf_to_crlf_filter(void)
@ -1779,8 +1779,8 @@ static void cascade_free_fn(struct stream_filter *filter)
}
static struct stream_filter_vtbl cascade_vtbl = {
cascade_filter_fn,
cascade_free_fn,
.filter = cascade_filter_fn,
.free = cascade_free_fn,
};
static struct stream_filter *cascade_filter(struct stream_filter *one,
@ -1931,8 +1931,8 @@ static void ident_free_fn(struct stream_filter *filter)
}
static struct stream_filter_vtbl ident_vtbl = {
ident_filter_fn,
ident_free_fn,
.filter = ident_filter_fn,
.free = ident_free_fn,
};
static struct stream_filter *ident_filter(const struct object_id *oid)

View File

@ -98,17 +98,7 @@ struct imap_server_conf {
};
static struct imap_server_conf server = {
NULL, /* name */
NULL, /* tunnel */
NULL, /* host */
0, /* port */
NULL, /* folder */
NULL, /* user */
NULL, /* pass */
0, /* use_ssl */
1, /* ssl_verify */
0, /* use_html */
NULL, /* auth_method */
.ssl_verify = 1,
};
struct imap_socket {

View File

@ -167,49 +167,49 @@ static void git_hash_unknown_final_oid(struct object_id *oid, git_hash_ctx *ctx)
const struct git_hash_algo hash_algos[GIT_HASH_NALGOS] = {
{
NULL,
0x00000000,
0,
0,
0,
git_hash_unknown_init,
git_hash_unknown_clone,
git_hash_unknown_update,
git_hash_unknown_final,
git_hash_unknown_final_oid,
NULL,
NULL,
NULL,
.name = NULL,
.format_id = 0x00000000,
.rawsz = 0,
.hexsz = 0,
.blksz = 0,
.init_fn = git_hash_unknown_init,
.clone_fn = git_hash_unknown_clone,
.update_fn = git_hash_unknown_update,
.final_fn = git_hash_unknown_final,
.final_oid_fn = git_hash_unknown_final_oid,
.empty_tree = NULL,
.empty_blob = NULL,
.null_oid = NULL,
},
{
"sha1",
GIT_SHA1_FORMAT_ID,
GIT_SHA1_RAWSZ,
GIT_SHA1_HEXSZ,
GIT_SHA1_BLKSZ,
git_hash_sha1_init,
git_hash_sha1_clone,
git_hash_sha1_update,
git_hash_sha1_final,
git_hash_sha1_final_oid,
&empty_tree_oid,
&empty_blob_oid,
&null_oid_sha1,
.name = "sha1",
.format_id = GIT_SHA1_FORMAT_ID,
.rawsz = GIT_SHA1_RAWSZ,
.hexsz = GIT_SHA1_HEXSZ,
.blksz = GIT_SHA1_BLKSZ,
.init_fn = git_hash_sha1_init,
.clone_fn = git_hash_sha1_clone,
.update_fn = git_hash_sha1_update,
.final_fn = git_hash_sha1_final,
.final_oid_fn = git_hash_sha1_final_oid,
.empty_tree = &empty_tree_oid,
.empty_blob = &empty_blob_oid,
.null_oid = &null_oid_sha1,
},
{
"sha256",
GIT_SHA256_FORMAT_ID,
GIT_SHA256_RAWSZ,
GIT_SHA256_HEXSZ,
GIT_SHA256_BLKSZ,
git_hash_sha256_init,
git_hash_sha256_clone,
git_hash_sha256_update,
git_hash_sha256_final,
git_hash_sha256_final_oid,
&empty_tree_oid_sha256,
&empty_blob_oid_sha256,
&null_oid_sha256,
.name = "sha256",
.format_id = GIT_SHA256_FORMAT_ID,
.rawsz = GIT_SHA256_RAWSZ,
.hexsz = GIT_SHA256_HEXSZ,
.blksz = GIT_SHA256_BLKSZ,
.init_fn = git_hash_sha256_init,
.clone_fn = git_hash_sha256_clone,
.update_fn = git_hash_sha256_update,
.final_fn = git_hash_sha256_final,
.final_oid_fn = git_hash_sha256_final_oid,
.empty_tree = &empty_tree_oid_sha256,
.empty_blob = &empty_blob_oid_sha256,
.null_oid = &null_oid_sha256,
}
};

View File

@ -4,13 +4,13 @@
#include "refspec.h"
static struct refspec_item s_tag_refspec = {
0,
1,
0,
0,
0,
"refs/tags/*",
"refs/tags/*"
.force = 0,
.pattern = 1,
.matching = 0,
.exact_sha1 = 0,
.negative = 0,
.src = "refs/tags/*",
.dst = "refs/tags/*",
};
/* See TAG_REFSPEC for the string version */

View File

@ -10,7 +10,9 @@
#include "trace2/tr2_tgt.h"
#include "trace2/tr2_tls.h"
static struct tr2_dst tr2dst_event = { TR2_SYSENV_EVENT, 0, 0, 0, 0 };
static struct tr2_dst tr2dst_event = {
.sysenv_var = TR2_SYSENV_EVENT,
};
/*
* The version number of the JSON data generated by the EVENT target in this
@ -613,34 +615,34 @@ static void fn_data_json_fl(const char *file, int line,
}
struct tr2_tgt tr2_tgt_event = {
&tr2dst_event,
.pdst = &tr2dst_event,
fn_init,
fn_term,
.pfn_init = fn_init,
.pfn_term = fn_term,
fn_version_fl,
fn_start_fl,
fn_exit_fl,
fn_signal,
fn_atexit,
fn_error_va_fl,
fn_command_path_fl,
fn_command_ancestry_fl,
fn_command_name_fl,
fn_command_mode_fl,
fn_alias_fl,
fn_child_start_fl,
fn_child_exit_fl,
fn_child_ready_fl,
fn_thread_start_fl,
fn_thread_exit_fl,
fn_exec_fl,
fn_exec_result_fl,
fn_param_fl,
fn_repo_fl,
fn_region_enter_printf_va_fl,
fn_region_leave_printf_va_fl,
fn_data_fl,
fn_data_json_fl,
NULL, /* printf */
.pfn_version_fl = fn_version_fl,
.pfn_start_fl = fn_start_fl,
.pfn_exit_fl = fn_exit_fl,
.pfn_signal = fn_signal,
.pfn_atexit = fn_atexit,
.pfn_error_va_fl = fn_error_va_fl,
.pfn_command_path_fl = fn_command_path_fl,
.pfn_command_ancestry_fl = fn_command_ancestry_fl,
.pfn_command_name_fl = fn_command_name_fl,
.pfn_command_mode_fl = fn_command_mode_fl,
.pfn_alias_fl = fn_alias_fl,
.pfn_child_start_fl = fn_child_start_fl,
.pfn_child_exit_fl = fn_child_exit_fl,
.pfn_child_ready_fl = fn_child_ready_fl,
.pfn_thread_start_fl = fn_thread_start_fl,
.pfn_thread_exit_fl = fn_thread_exit_fl,
.pfn_exec_fl = fn_exec_fl,
.pfn_exec_result_fl = fn_exec_result_fl,
.pfn_param_fl = fn_param_fl,
.pfn_repo_fl = fn_repo_fl,
.pfn_region_enter_printf_va_fl = fn_region_enter_printf_va_fl,
.pfn_region_leave_printf_va_fl = fn_region_leave_printf_va_fl,
.pfn_data_fl = fn_data_fl,
.pfn_data_json_fl = fn_data_json_fl,
.pfn_printf_va_fl = NULL,
};

View File

@ -9,7 +9,9 @@
#include "trace2/tr2_tgt.h"
#include "trace2/tr2_tls.h"
static struct tr2_dst tr2dst_normal = { TR2_SYSENV_NORMAL, 0, 0, 0, 0 };
static struct tr2_dst tr2dst_normal = {
.sysenv_var = TR2_SYSENV_NORMAL,
};
/*
* Use the TR2_SYSENV_NORMAL_BRIEF setting to omit the "<time> <file>:<line>"
@ -325,34 +327,34 @@ static void fn_printf_va_fl(const char *file, int line,
}
struct tr2_tgt tr2_tgt_normal = {
&tr2dst_normal,
.pdst = &tr2dst_normal,
fn_init,
fn_term,
.pfn_init = fn_init,
.pfn_term = fn_term,
fn_version_fl,
fn_start_fl,
fn_exit_fl,
fn_signal,
fn_atexit,
fn_error_va_fl,
fn_command_path_fl,
fn_command_ancestry_fl,
fn_command_name_fl,
fn_command_mode_fl,
fn_alias_fl,
fn_child_start_fl,
fn_child_exit_fl,
fn_child_ready_fl,
NULL, /* thread_start */
NULL, /* thread_exit */
fn_exec_fl,
fn_exec_result_fl,
fn_param_fl,
fn_repo_fl,
NULL, /* region_enter */
NULL, /* region_leave */
NULL, /* data */
NULL, /* data_json */
fn_printf_va_fl,
.pfn_version_fl = fn_version_fl,
.pfn_start_fl = fn_start_fl,
.pfn_exit_fl = fn_exit_fl,
.pfn_signal = fn_signal,
.pfn_atexit = fn_atexit,
.pfn_error_va_fl = fn_error_va_fl,
.pfn_command_path_fl = fn_command_path_fl,
.pfn_command_ancestry_fl = fn_command_ancestry_fl,
.pfn_command_name_fl = fn_command_name_fl,
.pfn_command_mode_fl = fn_command_mode_fl,
.pfn_alias_fl = fn_alias_fl,
.pfn_child_start_fl = fn_child_start_fl,
.pfn_child_exit_fl = fn_child_exit_fl,
.pfn_child_ready_fl = fn_child_ready_fl,
.pfn_thread_start_fl = NULL,
.pfn_thread_exit_fl = NULL,
.pfn_exec_fl = fn_exec_fl,
.pfn_exec_result_fl = fn_exec_result_fl,
.pfn_param_fl = fn_param_fl,
.pfn_repo_fl = fn_repo_fl,
.pfn_region_enter_printf_va_fl = NULL,
.pfn_region_leave_printf_va_fl = NULL,
.pfn_data_fl = NULL,
.pfn_data_json_fl = NULL,
.pfn_printf_va_fl = fn_printf_va_fl,
};

View File

@ -11,7 +11,9 @@
#include "trace2/tr2_tgt.h"
#include "trace2/tr2_tls.h"
static struct tr2_dst tr2dst_perf = { TR2_SYSENV_PERF, 0, 0, 0, 0 };
static struct tr2_dst tr2dst_perf = {
.sysenv_var = TR2_SYSENV_PERF,
};
/*
* Use TR2_SYSENV_PERF_BRIEF to omit the "<time> <file>:<line>"
@ -549,34 +551,34 @@ static void fn_printf_va_fl(const char *file, int line,
}
struct tr2_tgt tr2_tgt_perf = {
&tr2dst_perf,
.pdst = &tr2dst_perf,
fn_init,
fn_term,
.pfn_init = fn_init,
.pfn_term = fn_term,
fn_version_fl,
fn_start_fl,
fn_exit_fl,
fn_signal,
fn_atexit,
fn_error_va_fl,
fn_command_path_fl,
fn_command_ancestry_fl,
fn_command_name_fl,
fn_command_mode_fl,
fn_alias_fl,
fn_child_start_fl,
fn_child_exit_fl,
fn_child_ready_fl,
fn_thread_start_fl,
fn_thread_exit_fl,
fn_exec_fl,
fn_exec_result_fl,
fn_param_fl,
fn_repo_fl,
fn_region_enter_printf_va_fl,
fn_region_leave_printf_va_fl,
fn_data_fl,
fn_data_json_fl,
fn_printf_va_fl,
.pfn_version_fl = fn_version_fl,
.pfn_start_fl = fn_start_fl,
.pfn_exit_fl = fn_exit_fl,
.pfn_signal = fn_signal,
.pfn_atexit = fn_atexit,
.pfn_error_va_fl = fn_error_va_fl,
.pfn_command_path_fl = fn_command_path_fl,
.pfn_command_ancestry_fl = fn_command_ancestry_fl,
.pfn_command_name_fl = fn_command_name_fl,
.pfn_command_mode_fl = fn_command_mode_fl,
.pfn_alias_fl = fn_alias_fl,
.pfn_child_start_fl = fn_child_start_fl,
.pfn_child_exit_fl = fn_child_exit_fl,
.pfn_child_ready_fl = fn_child_ready_fl,
.pfn_thread_start_fl = fn_thread_start_fl,
.pfn_thread_exit_fl = fn_thread_exit_fl,
.pfn_exec_fl = fn_exec_fl,
.pfn_exec_result_fl = fn_exec_result_fl,
.pfn_param_fl = fn_param_fl,
.pfn_repo_fl = fn_repo_fl,
.pfn_region_enter_printf_va_fl = fn_region_enter_printf_va_fl,
.pfn_region_leave_printf_va_fl = fn_region_leave_printf_va_fl,
.pfn_data_fl = fn_data_fl,
.pfn_data_json_fl = fn_data_json_fl,
.pfn_printf_va_fl = fn_printf_va_fl,
};

View File

@ -7,12 +7,24 @@ static struct userdiff_driver *drivers;
static int ndrivers;
static int drivers_alloc;
#define PATTERNS(name, pattern, word_regex) \
{ name, NULL, -1, { pattern, REG_EXTENDED }, \
word_regex "|[^[:space:]]|[\xc0-\xff][\x80-\xbf]+" }
#define IPATTERN(name, pattern, word_regex) \
{ name, NULL, -1, { pattern, REG_EXTENDED | REG_ICASE }, \
word_regex "|[^[:space:]]|[\xc0-\xff][\x80-\xbf]+" }
#define PATTERNS(lang, rx, wrx) { \
.name = lang, \
.binary = -1, \
.funcname = { \
.pattern = rx, \
.cflags = REG_EXTENDED, \
}, \
.word_regex = wrx "|[^[:space:]]|[\xc0-\xff][\x80-\xbf]+", \
}
#define IPATTERN(lang, rx, wrx) { \
.name = lang, \
.binary = -1, \
.funcname = { \
.pattern = rx, \
.cflags = REG_EXTENDED | REG_ICASE, \
}, \
.word_regex = wrx "|[^[:space:]]|[\xc0-\xff][\x80-\xbf]+", \
}
/*
* Built-in drivers for various languages, sorted by their names
@ -275,17 +287,13 @@ PATTERNS("tex", "^(\\\\((sub)*section|chapter|part)\\*{0,1}\\{.*)$",
#undef IPATTERN
static struct userdiff_driver driver_true = {
"diff=true",
NULL,
0,
{ NULL, 0 }
.name = "diff=true",
.binary = 0,
};
static struct userdiff_driver driver_false = {
"!diff",
NULL,
1,
{ NULL, 0 }
.name = "!diff",
.binary = 1,
};
struct find_by_namelen_data {