Skip to content

Commit

Permalink
Merge branch 'ab/c99-designated-initializers'
Browse files Browse the repository at this point in the history
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"
  • Loading branch information
gitster committed Mar 7, 2022
2 parents 283e4e7 + c829f5f commit 20d34c0
Show file tree
Hide file tree
Showing 11 changed files with 193 additions and 183 deletions.
6 changes: 3 additions & 3 deletions archive-tar.c
Expand Up @@ -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)
Expand Down
6 changes: 3 additions & 3 deletions archive-zip.c
Expand Up @@ -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)
Expand Down
14 changes: 10 additions & 4 deletions builtin/fast-import.c
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand All @@ -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;
Expand Down
18 changes: 9 additions & 9 deletions convert.c
Expand Up @@ -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)
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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,
Expand Down Expand Up @@ -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)
Expand Down
12 changes: 1 addition & 11 deletions imap-send.c
Expand Up @@ -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 {
Expand Down
78 changes: 39 additions & 39 deletions object-file.c
Expand Up @@ -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,
}
};

Expand Down
14 changes: 7 additions & 7 deletions refspec.c
Expand Up @@ -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 */
Expand Down
64 changes: 33 additions & 31 deletions trace2/tr2_tgt_event.c
Expand Up @@ -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
Expand Down Expand Up @@ -613,34 +615,34 @@ static void fn_data_json_fl(const char *file, int line,
}

struct tr2_tgt tr2_tgt_event = {
&tr2dst_event,

fn_init,
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 */
.pdst = &tr2dst_event,

.pfn_init = fn_init,
.pfn_term = fn_term,

.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,
};
64 changes: 33 additions & 31 deletions trace2/tr2_tgt_normal.c
Expand Up @@ -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>"
Expand Down Expand Up @@ -325,34 +327,34 @@ static void fn_printf_va_fl(const char *file, int line,
}

struct tr2_tgt tr2_tgt_normal = {
&tr2dst_normal,

fn_init,
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,
.pdst = &tr2dst_normal,

.pfn_init = fn_init,
.pfn_term = fn_term,

.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,
};

0 comments on commit 20d34c0

Please sign in to comment.