{"thread":{"id":"66788","subject":"[PATCH] repo: zero-initialize configuration values","startedAt":"2026-11-06T11:59:28Z","lastAt":"2026-11-09T19:05:43Z","messageCount":6,"participants":["Joy via GitGitGadget","Patrick Steinhardt","Joie Joie","Junio C Hamano"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"557668","messageId":"pull.2298.git.1793966368860.gitgitgadget@gmail.com","threadId":"66788","inReplyTo":null,"subject":"[PATCH] repo: zero-initialize configuration values","fromName":"Joy via GitGitGadget","fromEmail":"gitgitgadget@gmail.com","sentAt":"2026-11-06T11:59:28Z","receivedAt":"2026-11-06T11:59:28Z","isPatch":true,"sender":{"key":"cryptocurrencydiva@gmail.com","avatar":null},"body":"From: Joy Gundu <soniqjjj@gmail.com>\n\nUse memset() to initialize repository configuration values to\nzero, removing the need for explicit zero and NULL assignments.\nKeep non-zero defaults initialized separately.\n\nSigned-off-by: Joy Gundu <soniqjjj@gmail.com>\n---\n    [Outreachy] repo: zero-initialize configuration values\n\nPublished-As: https://github.com/gitgitgadget/git/releases/tag/pr-2298%2FJoiejoie1%2Frepo-zero-initialize-config-values-v1\nFetch-It-Via: git fetch https://github.com/gitgitgadget/git pr-2298/Joiejoie1/repo-zero-initialize-config-values-v1\nPull-Request: https://github.com/gitgitgadget/git/pull/2298\n\n environment.c | 16 ++--------------\n 1 file changed, 2 insertions(+), 14 deletions(-)\n\ndiff --git a/environment.c b/environment.c\nindex c83cf44839..afe35cff99 100644\n--- a/environment.c\n+++ b/environment.c\n@@ -752,34 +752,22 @@ int git_default_config(const char *var, const char *value,\n \n void repo_config_values_init(struct repo_config_values *cfg)\n {\n+\tmemset(cfg, 0, sizeof(*cfg));\n+\n \t/* section \"core\" config values */\n-\tcfg->attributes_file = NULL;\n-\tcfg->excludes_file = NULL;\n-\tcfg->editor_program = NULL;\n-\tcfg->pager_program = NULL;\n-\tcfg->askpass_program = NULL;\n-\tcfg->apply_default_whitespace = NULL;\n-\tcfg->apply_default_ignorewhitespace = NULL;\n \tcfg->push_default = PUSH_DEFAULT_UNSPECIFIED;\n \tcfg->autorebase = AUTOREBASE_NEVER;\n \tcfg->object_creation_mode = OBJECT_CREATION_MODE;\n-\tcfg->apply_sparse_checkout = 0;\n \tcfg->trust_ctime = 1;\n \tcfg->check_stat = 1;\n \tcfg->zlib_compression_level = Z_BEST_SPEED;\n \tcfg->pack_compression_level = Z_DEFAULT_COMPRESSION;\n \tcfg->precomposed_unicode = -1; /* see probe_utf8_pathname_composition() */\n-\tcfg->core_sparse_checkout_cone = 0;\n \tcfg->warn_on_object_refname_ambiguity = 1;\n \tcfg->protect_hfs = PROTECT_HFS_DEFAULT;\n \tcfg->protect_ntfs = PROTECT_NTFS_DEFAULT;\n-\tcfg->ignore_case = 0;\n \tcfg->trust_executable_bit = 1;\n \tcfg->has_symlinks = platform_has_symlinks();\n-\tcfg->use_nanosec = 0;\n-\n-\t/* section \"sparse\" config values */\n-\tcfg->sparse_expect_files_outside_of_patterns = 0;\n \n \t/* section \"branch\" config values */\n \tcfg->branch_track = BRANCH_TRACK_REMOTE;\n\nbase-commit: 3de8ebe6c8cfcd312cdbfa675635810140f84c8a\n-- \ngitgitgadget\n\n"},{"id":"557685","messageId":"au3hVGPuDyGVwOw8@pks.im","threadId":"66788","inReplyTo":"pull.2298.git.1793966368860.gitgitgadget@gmail.com","subject":"Re: [PATCH] repo: zero-initialize configuration values","fromName":"Patrick Steinhardt","fromEmail":"ps@pks.im","sentAt":"2026-11-06T14:16:52Z","receivedAt":"2026-11-06T14:16:52Z","isPatch":true,"sender":{"key":"ps@pks.im","avatar":"https://avatars.githubusercontent.com/u/4056630?v=4"},"body":"On Fri, Nov 06, 2026 at 11:59:28AM +0000, Joy via GitGitGadget wrote:\n> From: Joy Gundu <soniqjjj@gmail.com>\n> \n> Use memset() to initialize repository configuration values to\n> zero, removing the need for explicit zero and NULL assignments.\n> Keep non-zero defaults initialized separately.\n> \n> Signed-off-by: Joy Gundu <soniqjjj@gmail.com>\n> ---\n>     [Outreachy] repo: zero-initialize configuration values\n\nSo I guess this patch was split out because of our recent push to not\nmake further changes to `repo_config_values()`? If so, it would have\nmade sense to point that out explicitly both here, and in the original\nthread that you've sent.\n\nIn any case, the patch is obviously correct and is a good improvement in\nmy opinion. So this looks good to me, thanks.\n\nPatrick\n\n"},{"id":"557709","messageId":"CAH=d44eGRgHOF1NX0t6+OJP4GVhTqnvQi+sgnM86CC4FE_4LsA@mail.gmail.com","threadId":"66788","inReplyTo":"au3hVGPuDyGVwOw8@pks.im","subject":"Re: [PATCH] repo: zero-initialize configuration values","fromName":"Joie Joie","fromEmail":"soniqjjj@gmail.com","sentAt":"2026-11-06T16:19:59Z","receivedAt":"2026-11-06T16:19:59Z","isPatch":true,"sender":{"key":"soniqjjj@gmail.com","avatar":null},"body":"Thanks, Patrick.\n\nYes, that was my reason for splitting the patch. It only changes how\nthe existing configuration values are initialized and doesn't add a\nnew struct member, so I felt it could be reviewed separately from the\nchanges affected by the recent direction.\n\nYou're right, though. I should have explained that more clearly in the\npatch description and the original thread. I'll make sure to include\nthat context in future submissions.\n\nThanks for taking the time to review it!\n\nOn Fri, Nov 6, 2026 at 3:16 PM Patrick Steinhardt <ps@pks.im> wrote:\n>\n> On Fri, Nov 06, 2026 at 11:59:28AM +0000, Joy via GitGitGadget wrote:\n> > From: Joy Gundu <soniqjjj@gmail.com>\n> >\n> > Use memset() to initialize repository configuration values to\n> > zero, removing the need for explicit zero and NULL assignments.\n> > Keep non-zero defaults initialized separately.\n> >\n> > Signed-off-by: Joy Gundu <soniqjjj@gmail.com>\n> > ---\n> >     [Outreachy] repo: zero-initialize configuration values\n>\n> So I guess this patch was split out because of our recent push to not\n> make further changes to `repo_config_values()`? If so, it would have\n> made sense to point that out explicitly both here, and in the original\n> thread that you've sent.\n>\n> In any case, the patch is obviously correct and is a good improvement in\n> my opinion. So this looks good to me, thanks.\n>\n> Patrick\n\n"},{"id":"557729","messageId":"xmqq7bipiwgt.fsf@gitster.g","threadId":"66788","inReplyTo":"au3hVGPuDyGVwOw8@pks.im","subject":"Re: [PATCH] repo: zero-initialize configuration values","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-06T19:36:02Z","receivedAt":"2026-11-06T19:36:02Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Patrick Steinhardt <ps@pks.im> writes:\n\n> In any case, the patch is obviously correct and is a good improvement in\n> my opinion. So this looks good to me, thanks.\n\nIt however does not look good to me.  I would prefer to see\n\n\tstruct foo foo = {0};\n\nif everything is zero initialized, or if there are some members\ninitialized to specific values, C99 designated initializers to be\nused:\n\n\tstruct foo foo = {\n\t\t/* Comment on this stuff */\n\t\t.object_creation_mode = OBJECT_CREATION_MODE,\n\n                /* Comment on this other stuff */\n\t\t.branch_track = BRANCH_TRACK_REMOTE,\n\t};\n\nNow this is overwriting the passed in structure members, so how we\nwrite the initialization is not the whole story.\n\nSince we have avoided assuming the universal availability of the\nmore recent \"compound literals\" syntax, which is:\n\n\t*cfg = (struct foo) {\n\t\t... an initialization with designated initializers ...\n\t};\n\nwe seem to (ab)use struct assignment, e.g.,\n\n\tstatic struct foo foo_template = {\n\t\t... an initialization with designated initializers ...\n\t};\n\n\t*cfg = foo_template;\n\nin a few places as a fallback in the existing code (DI is C99,\nstruct assignment is C89, so it has been a safer assumption than\nassuming compound literals).\n\nBut I do recall we made this update to our CodingGuidelines document.\n\n   . since late 2024 with v2.48.0-rc0~20, we have been using compound\n     literals, e.g., (struct foo){ .member = value };\n\nSo perhaps it is time to switch this to assign a compound literal?\n\n"},{"id":"557943","messageId":"CAH=d44fX-LN10TU0ZsuJ_RcxE=6QnKsHrLS4dJorAj3T55TZzA@mail.gmail.com","threadId":"66788","inReplyTo":"xmqq7bipiwgt.fsf@gitster.g","subject":"Re: [PATCH] repo: zero-initialize configuration values","fromName":"Joie Joie","fromEmail":"soniqjjj@gmail.com","sentAt":"2026-11-09T14:26:22Z","receivedAt":"2026-11-09T14:26:22Z","isPatch":true,"sender":{"key":"soniqjjj@gmail.com","avatar":null},"body":"Thanks, Junio.\n\nI hadn't considered using a compound literal here. I was following the\nexisting initialization approach, but your suggestion makes sense,\nespecially given the update to the CodingGuidelines.\n\nI'll look into changing the initialization to use a compound literal\nwhile preserving the existing defaults and behavior.\n\nOn Fri, Nov 6, 2026 at 8:36 PM Junio C Hamano <gitster@pobox.com> wrote:\n>\n> Patrick Steinhardt <ps@pks.im> writes:\n>\n> > In any case, the patch is obviously correct and is a good improvement in\n> > my opinion. So this looks good to me, thanks.\n>\n> It however does not look good to me.  I would prefer to see\n>\n>         struct foo foo = {0};\n>\n> if everything is zero initialized, or if there are some members\n> initialized to specific values, C99 designated initializers to be\n> used:\n>\n>         struct foo foo = {\n>                 /* Comment on this stuff */\n>                 .object_creation_mode = OBJECT_CREATION_MODE,\n>\n>                 /* Comment on this other stuff */\n>                 .branch_track = BRANCH_TRACK_REMOTE,\n>         };\n>\n> Now this is overwriting the passed in structure members, so how we\n> write the initialization is not the whole story.\n>\n> Since we have avoided assuming the universal availability of the\n> more recent \"compound literals\" syntax, which is:\n>\n>         *cfg = (struct foo) {\n>                 ... an initialization with designated initializers ...\n>         };\n>\n> we seem to (ab)use struct assignment, e.g.,\n>\n>         static struct foo foo_template = {\n>                 ... an initialization with designated initializers ...\n>         };\n>\n>         *cfg = foo_template;\n>\n> in a few places as a fallback in the existing code (DI is C99,\n> struct assignment is C89, so it has been a safer assumption than\n> assuming compound literals).\n>\n> But I do recall we made this update to our CodingGuidelines document.\n>\n>    . since late 2024 with v2.48.0-rc0~20, we have been using compound\n>      literals, e.g., (struct foo){ .member = value };\n>\n> So perhaps it is time to switch this to assign a compound literal?\n\n"},{"id":"557977","messageId":"xmqqo6bxzuyg.fsf@gitster.g","threadId":"66788","inReplyTo":"CAH=d44fX-LN10TU0ZsuJ_RcxE=6QnKsHrLS4dJorAj3T55TZzA@mail.gmail.com","subject":"Re: [PATCH] repo: zero-initialize configuration values","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2026-11-09T19:05:43Z","receivedAt":"2026-11-09T19:05:43Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Joie Joie <soniqjjj@gmail.com> writes:\n\n> Thanks, Junio.\n>\n> I hadn't considered using a compound literal here. I was following the\n> existing initialization approach, but your suggestion makes sense,\n> especially given the update to the CodingGuidelines.\n>\n> I'll look into changing the initialization to use a compound literal\n> while preserving the existing defaults and behavior.\n\nSounds good, but do not top post ;-)\n\n>\n> On Fri, Nov 6, 2026 at 8:36 PM Junio C Hamano <gitster@pobox.com> wrote:\n>>\n>> Patrick Steinhardt <ps@pks.im> writes:\n>>\n>> > In any case, the patch is obviously correct and is a good improvement in\n>> > my opinion. So this looks good to me, thanks.\n>>\n>> It however does not look good to me.  I would prefer to see\n>>\n>>         struct foo foo = {0};\n>>\n>> if everything is zero initialized, or if there are some members\n>> initialized to specific values, C99 designated initializers to be\n>> used:\n>>\n>>         struct foo foo = {\n>>                 /* Comment on this stuff */\n>>                 .object_creation_mode = OBJECT_CREATION_MODE,\n>>\n>>                 /* Comment on this other stuff */\n>>                 .branch_track = BRANCH_TRACK_REMOTE,\n>>         };\n>>\n>> Now this is overwriting the passed in structure members, so how we\n>> write the initialization is not the whole story.\n>>\n>> Since we have avoided assuming the universal availability of the\n>> more recent \"compound literals\" syntax, which is:\n>>\n>>         *cfg = (struct foo) {\n>>                 ... an initialization with designated initializers ...\n>>         };\n>>\n>> we seem to (ab)use struct assignment, e.g.,\n>>\n>>         static struct foo foo_template = {\n>>                 ... an initialization with designated initializers ...\n>>         };\n>>\n>>         *cfg = foo_template;\n>>\n>> in a few places as a fallback in the existing code (DI is C99,\n>> struct assignment is C89, so it has been a safer assumption than\n>> assuming compound literals).\n>>\n>> But I do recall we made this update to our CodingGuidelines document.\n>>\n>>    . since late 2024 with v2.48.0-rc0~20, we have been using compound\n>>      literals, e.g., (struct foo){ .member = value };\n>>\n>> So perhaps it is time to switch this to assign a compound literal?\n\n"}]}