Re: [PATCH v2 1/2] repo: zero-initialize configuration values
flat view
From: Patrick Steinhardt <hidden>
Date: 2026-10-22 11:30:35
On Thu, Oct 22, 2026 at 09:47:11AM +0000, Joy Gundu via GitGitGadget wrote:
From: Joy Gundu <redacted>
Even though the patch speaks for itself, we typically still like to a
sentence or two in the commit message itself. E.g.:
When initializing `struct repo_config_values` we manually zero out a
lot of its members, which is tedious. Reduce the boilerplate by first
zeroing out the whole structure so that we only have to set those
members that have a non-zero default value.
quoted hunk ↗ jump to hunk
Signed-off-by: Joy Gundu <redacted> --- environment.c | 14 ++------------ 1 file changed, 2 insertions(+), 12 deletions(-)diff --git a/environment.c b/environment.c index c83cf44839..89af09aa40 100644 --- a/environment.c +++ b/environment.c@@ -752,34 +752,24 @@ int git_default_config(const char *var, const char *value, void repo_config_values_init(struct repo_config_values *cfg) { + memset(cfg, 0, sizeof(*cfg)); + /* section "core" config values */ - cfg->attributes_file = NULL; - cfg->excludes_file = NULL; - cfg->editor_program = NULL; - cfg->pager_program = NULL; - cfg->askpass_program = NULL; - cfg->apply_default_whitespace = NULL; - cfg->apply_default_ignorewhitespace = NULL; cfg->push_default = PUSH_DEFAULT_UNSPECIFIED; cfg->autorebase = AUTOREBASE_NEVER; cfg->object_creation_mode = OBJECT_CREATION_MODE; - cfg->apply_sparse_checkout = 0; cfg->trust_ctime = 1; cfg->check_stat = 1; cfg->zlib_compression_level = Z_BEST_SPEED; cfg->pack_compression_level = Z_DEFAULT_COMPRESSION; cfg->precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */ - cfg->core_sparse_checkout_cone = 0; cfg->warn_on_object_refname_ambiguity = 1; cfg->protect_hfs = PROTECT_HFS_DEFAULT; cfg->protect_ntfs = PROTECT_NTFS_DEFAULT; - cfg->ignore_case = 0; cfg->trust_executable_bit = 1; cfg->has_symlinks = platform_has_symlinks(); - cfg->use_nanosec = 0; /* section "sparse" config values */ - cfg->sparse_expect_files_outside_of_patterns = 0;
We should probably drop this comment together with the code.
/* section "branch" config values */ cfg->branch_track = BRANCH_TRACK_REMOTE;
Other than that this looks good to me. Patrick