Re: [PATCH v2 3/4] add-patch: respect diff.context configuration
- From
Junio C Hamano <gitster@pobox.com>
- Date
- May 13, 2025, 15:47 UTC
- Message-ID
- <xmqqzffgh5rf.fsf@gitster.g>
- In-Reply-To
- <f00cdfa1-343a-4fa0-bce5-e06d1ed62c22@gmail.com>
Phillip Wood <phillip.wood123@gmail.com> writes:
Show 35 quoted lines
> Hi Leon
>
> On 10/05/2025 14:46, Leon Michalak via GitGitGadget wrote:
>> From: Leon Michalak <leonmichalak6@gmail.com>
>> Various builtins that use add-patch infrastructure do not respect
>> the user's diff.context and diff.interHunkContext file configurations.
>
> We could expand this slightly by adding
>
> This is because the plumbing commands used by "git add -p" to generate
> the diff do not read those config settings. Fix this by reading the
> config before generating the patch and passing it along to the diff
> command with the "-U" and "--inter-hunk-context" command-line options.
>
>> This patch fixes this inconsistency.
>> Signed-off-by: Leon Michalak <leonmichalak6@gmail.com>
>> ---
>
>> @@ -78,6 +82,19 @@ void init_add_i_state(struct add_i_state *s, struct repository *r)
>> repo_config_get_string(r, "diff.algorithm",
>> &s->interactive_diff_algorithm);
>> + if (!repo_config_get_int(r, "diff.context", &context)) {
>> + if (context < 0)
>> + die(_("%s cannot be negative"), "diff.context");
>> + else
>> + s->context = context;
>> + };
>> + if (!repo_config_get_int(r, "diff.interHunkContext", &interhunkcontext)) {
>> + if (interhunkcontext < 0)
>> + die(_("%s cannot be negative"), "diff.interHunkContext");
>> + else
>> + s->interhunkcontext = interhunkcontext;
>> + };
>
> Thanks for changing this. This iteration of the code changes looks goodLose the ';' (semicolon) after closing {brace}s. This is C; you do not need an empty statement after a {block}.
Everything in your review I am very happy to see. Thanks for giving a great review.