{"thread":{"id":"59264","subject":"[PATCH] format.attach: allow empty value to disable multi-part messages","startedAt":"2023-02-17T23:33:43Z","lastAt":"2023-02-18T17:34:16Z","messageCount":3,"participants":["Junio C Hamano","Brian Inglis"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"472283","messageId":"xmqqwn4fkgtq.fsf@gitster.g","threadId":"59264","inReplyTo":null,"subject":"[PATCH] format.attach: allow empty value to disable multi-part messages","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-02-17T23:33:37Z","receivedAt":"2023-02-17T23:33:43Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"When a lower precedence configuration file (e.g. /etc/gitconfig)\ndefines format.attach in any way, there was no way to disable it in\na more specific configuration file (e.g. $HOME/.gitconfig).\n\nChange the behaviour of setting it to an empty string.  It used to\nmean that the result is still a multipart message with only dashes\nused as a multi-part separator, but now it resets the setting to\nthe default (which would be to give an inline patch, unless other\ncommand line options are in effect).\n\nSigned-off-by: Junio C Hamano <gitster@pobox.com>\n---\n\n * This is a backward incompatible change, so we may not take it in the\n   end.  We'll see.\n\n Documentation/config/format.txt |  3 ++-\n builtin/log.c                   |  2 ++\n t/t4014-format-patch.sh         | 18 ++++++++++++++++++\n 3 files changed, 22 insertions(+), 1 deletion(-)\n\ndiff --git a/Documentation/config/format.txt b/Documentation/config/format.txt\nindex 3bd78269e2..73678d88a1 100644\n--- a/Documentation/config/format.txt\n+++ b/Documentation/config/format.txt\n@@ -3,7 +3,8 @@ format.attach::\n \t'format-patch'.  The value can also be a double quoted string\n \twhich will enable attachments as the default and set the\n \tvalue as the boundary.  See the --attach option in\n-\tlinkgit:git-format-patch[1].\n+\tlinkgit:git-format-patch[1].  To countermand an earlier\n+\tvalue, set it to an empty string.\n \n format.from::\n \tProvides the default value for the `--from` option to format-patch.\ndiff --git a/builtin/log.c b/builtin/log.c\nindex 04412dd9c9..a70fba198f 100644\n--- a/builtin/log.c\n+++ b/builtin/log.c\n@@ -1007,6 +1007,8 @@ static int git_format_config(const char *var, const char *value, void *cb)\n \tif (!strcmp(var, \"format.attach\")) {\n \t\tif (value && *value)\n \t\t\tdefault_attach = xstrdup(value);\n+\t\telse if (value && !*value)\n+\t\t\tFREE_AND_NULL(default_attach);\n \t\telse\n \t\t\tdefault_attach = xstrdup(git_version_string);\n \t\treturn 0;\ndiff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh\nindex 012f155e10..f3313b8c58 100755\n--- a/t/t4014-format-patch.sh\n+++ b/t/t4014-format-patch.sh\n@@ -2281,6 +2281,24 @@ test_expect_success 'format-patch --attach cover-letter only is non-multipart' '\n \ttest_line_count = 1 output\n '\n \n+test_expect_success 'format-patch with format.attach' '\n+\ttest_when_finished \"rm -fr patches\" &&\n+\tseparator=attachment-separator &&\n+\ttest_config format.attach \"$separator\" &&\n+\tfilename=$(git format-patch -o patches -1) &&\n+\tgrep \"^Content-Type: multipart/.*$separator\" \"$filename\"\n+'\n+\n+test_expect_success 'format-patch with format.attach=disabled' '\n+\ttest_when_finished \"rm -fr patches\" &&\n+\tseparator=attachment-separator &&\n+\ttest_config_global format.attach \"$separator\" &&\n+\ttest_config format.attach \"\" &&\n+\tfilename=$(git format-patch -o patches -1) &&\n+\t# The output should not even declare content type for text/plain.\n+\t! grep \"^Content-Type: multipart/\" \"$filename\"\n+'\n+\n test_expect_success '-c format.mboxrd format-patch' '\n \tsp=\" \" &&\n \tcat >msg <<-INPUT_END &&\n-- \n2.39.2-501-gd9d677b2d8\n\n"},{"id":"472305","messageId":"b2866322-5654-15d0-df83-a87926a01815@Shaw.ca","threadId":"59264","inReplyTo":"xmqqwn4fkgtq.fsf@gitster.g","subject":"Re: [PATCH] format.attach: allow empty value to disable multi-part messages","fromName":"Brian Inglis","fromEmail":"brian.inglis@shaw.ca","sentAt":"2023-02-18T17:11:02Z","receivedAt":"2023-02-18T17:11:13Z","isPatch":true,"sender":{"key":"brian.inglis@shaw.ca","avatar":null},"body":"Thanks Junio,\n\nI'll hope and watch for it to get added, and test if/when released.\n\n-- \nTake care. Thanks, Brian Inglis\t\t\tCalgary, Alberta, Canada\n\nLa perfection est atteinte\t\t\tPerfection is achieved\nnon pas lorsqu'il n'y a plus rien à ajouter\tnot when there is no more to add\nmais lorsqu'il n'y a plus rien à retirer\tbut when there is no more to cut\n\t\t\t-- Antoine de Saint-Exupéry\n\n\nOn 2023-02-17 16:33, Junio C Hamano wrote:\n> When a lower precedence configuration file (e.g. /etc/gitconfig)\n> defines format.attach in any way, there was no way to disable it in\n> a more specific configuration file (e.g. $HOME/.gitconfig).\n> \n> Change the behaviour of setting it to an empty string.  It used to\n> mean that the result is still a multipart message with only dashes\n> used as a multi-part separator, but now it resets the setting to\n> the default (which would be to give an inline patch, unless other\n> command line options are in effect).\n> \n> Signed-off-by: Junio C Hamano <gitster@pobox.com>\n> ---\n> \n>   * This is a backward incompatible change, so we may not take it in the\n>     end.  We'll see.\n> \n>   Documentation/config/format.txt |  3 ++-\n>   builtin/log.c                   |  2 ++\n>   t/t4014-format-patch.sh         | 18 ++++++++++++++++++\n>   3 files changed, 22 insertions(+), 1 deletion(-)\n> \n> diff --git a/Documentation/config/format.txt b/Documentation/config/format.txt\n> index 3bd78269e2..73678d88a1 100644\n> --- a/Documentation/config/format.txt\n> +++ b/Documentation/config/format.txt\n> @@ -3,7 +3,8 @@ format.attach::\n>   \t'format-patch'.  The value can also be a double quoted string\n>   \twhich will enable attachments as the default and set the\n>   \tvalue as the boundary.  See the --attach option in\n> -\tlinkgit:git-format-patch[1].\n> +\tlinkgit:git-format-patch[1].  To countermand an earlier\n> +\tvalue, set it to an empty string.\n>   \n>   format.from::\n>   \tProvides the default value for the `--from` option to format-patch.\n> diff --git a/builtin/log.c b/builtin/log.c\n> index 04412dd9c9..a70fba198f 100644\n> --- a/builtin/log.c\n> +++ b/builtin/log.c\n> @@ -1007,6 +1007,8 @@ static int git_format_config(const char *var, const char *value, void *cb)\n>   \tif (!strcmp(var, \"format.attach\")) {\n>   \t\tif (value && *value)\n>   \t\t\tdefault_attach = xstrdup(value);\n> +\t\telse if (value && !*value)\n> +\t\t\tFREE_AND_NULL(default_attach);\n>   \t\telse\n>   \t\t\tdefault_attach = xstrdup(git_version_string);\n>   \t\treturn 0;\n> diff --git a/t/t4014-format-patch.sh b/t/t4014-format-patch.sh\n> index 012f155e10..f3313b8c58 100755\n> --- a/t/t4014-format-patch.sh\n> +++ b/t/t4014-format-patch.sh\n> @@ -2281,6 +2281,24 @@ test_expect_success 'format-patch --attach cover-letter only is non-multipart' '\n>   \ttest_line_count = 1 output\n>   '\n>   \n> +test_expect_success 'format-patch with format.attach' '\n> +\ttest_when_finished \"rm -fr patches\" &&\n> +\tseparator=attachment-separator &&\n> +\ttest_config format.attach \"$separator\" &&\n> +\tfilename=$(git format-patch -o patches -1) &&\n> +\tgrep \"^Content-Type: multipart/.*$separator\" \"$filename\"\n> +'\n> +\n> +test_expect_success 'format-patch with format.attach=disabled' '\n> +\ttest_when_finished \"rm -fr patches\" &&\n> +\tseparator=attachment-separator &&\n> +\ttest_config_global format.attach \"$separator\" &&\n> +\ttest_config format.attach \"\" &&\n> +\tfilename=$(git format-patch -o patches -1) &&\n> +\t# The output should not even declare content type for text/plain.\n> +\t! grep \"^Content-Type: multipart/\" \"$filename\"\n> +'\n> +\n>   test_expect_success '-c format.mboxrd format-patch' '\n>   \tsp=\" \" &&\n>   \tcat >msg <<-INPUT_END &&\n"},{"id":"472307","messageId":"xmqqedqmkhd7.fsf@gitster.g","threadId":"59264","inReplyTo":"b2866322-5654-15d0-df83-a87926a01815@Shaw.ca","subject":"Re: [PATCH] format.attach: allow empty value to disable multi-part messages","fromName":"Junio C Hamano","fromEmail":"gitster@pobox.com","sentAt":"2023-02-18T17:34:12Z","receivedAt":"2023-02-18T17:34:16Z","isPatch":true,"sender":{"key":"gitster@pobox.com","avatar":"https://avatars.githubusercontent.com/u/54884?v=4"},"body":"Brian Inglis <Brian.Inglis@Shaw.ca> writes:\n\n> Thanks Junio,\n>\n> I'll hope and watch for it to get added, and test if/when released.\n\nThat won't be very helpful as reviewing and testing is to prevent\nnonsense patches to be added to the released version.  Once it is\nreleased, testing becomes much less valuable, as it is too late to\ncatch nonsense bugs in the added code.\n\nThanks.\n"}]}