{"thread":{"id":"58778","subject":"[PATCH] Change git-send-email's sendemail-validate hook to use header information","startedAt":"2022-11-09T18:23:13Z","lastAt":"2022-11-09T23:17:25Z","messageCount":3,"participants":["Strawbridge, Michael","Taylor Blau","brian m. carlson"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"466973","messageId":"20221109182254.71967-1-michael.strawbridge@amd.com","threadId":"58778","inReplyTo":null,"subject":"[PATCH] Change git-send-email's sendemail-validate hook to use header information","fromName":"Strawbridge, Michael","fromEmail":"michael.strawbridge@amd.com","sentAt":"2022-11-09T18:23:06Z","receivedAt":"2022-11-09T18:23:13Z","isPatch":true,"sender":{"key":"michael.strawbridge@amd.com","avatar":null},"body":"Since commit-msg and pre-commit git hooks already expose commit\ncontents, switch sendemail-validate to use the header information\nof the email that git-send-email intends to send.\n\nCc: Luben Tuikov <luben.tuikov@amd.com>\nCc: brian m. carlson <sandals@crustytoothpaste.net>\n---\n git-send-email.perl | 57 +++++++++++++++++++++++++++++----------------\n 1 file changed, 37 insertions(+), 20 deletions(-)\n\ndiff --git a/git-send-email.perl b/git-send-email.perl\nindex 5861e99a6e..3ea6fda48e 100755\n--- a/git-send-email.perl\n+++ b/git-send-email.perl\n@@ -787,14 +787,6 @@ sub is_format_patch_arg {\n \n @files = handle_backup_files(@files);\n \n-if ($validate) {\n-\tforeach my $f (@files) {\n-\t\tunless (-p $f) {\n-\t\t\tvalidate_patch($f, $target_xfer_encoding);\n-\t\t}\n-\t}\n-}\n-\n if (@files) {\n \tunless ($quiet) {\n \t\tprint $_,\"\\n\" for (@files);\n@@ -1495,16 +1487,7 @@ sub file_name_is_absolute {\n \treturn File::Spec::Functions::file_name_is_absolute($path);\n }\n \n-# Prepares the email, then asks the user what to do.\n-#\n-# If the user chooses to send the email, it's sent and 1 is returned.\n-# If the user chooses not to send the email, 0 is returned.\n-# If the user decides they want to make further edits, -1 is returned and the\n-# caller is expected to call send_message again after the edits are performed.\n-#\n-# If an error occurs sending the email, this just dies.\n-\n-sub send_message {\n+sub gen_header {\n \tmy @recipients = unique_email_list(@to);\n \t@cc = (grep { my $cc = extract_valid_address_or_die($_);\n \t\t      not grep { $cc eq $_ || $_ =~ /<\\Q${cc}\\E>$/ } @recipients\n@@ -1546,6 +1529,22 @@ sub send_message {\n \tif (@xh) {\n \t\t$header .= join(\"\\n\", @xh) . \"\\n\";\n \t}\n+\treturn $header;\n+}\n+\n+# Prepares the email, then asks the user what to do.\n+#\n+# If the user chooses to send the email, it's sent and 1 is returned.\n+# If the user chooses not to send the email, 0 is returned.\n+# If the user decides they want to make further edits, -1 is returned and the\n+# caller is expected to call send_message again after the edits are performed.\n+#\n+# If an error occurs sending the email, this just dies.\n+\n+sub send_message {\n+\tmy @recipients = unique_email_list(@to);\n+\n+        my $header = gen_header();\n \n \tmy @sendmail_parameters = ('-i', @recipients);\n \tmy $raw_from = $sender;\n@@ -1955,6 +1954,15 @@ sub process_file {\n \t\t}\n \t}\n \n+\n+\tif ($validate) {\n+\t\tforeach my $f (@files) {\n+\t\t\tunless (-p $f) {\n+\t\t\t\tvalidate_patch($f, $target_xfer_encoding);\n+\t\t\t}\n+\t\t}\n+\t}\n+\n \tmy $message_was_sent = send_message();\n \tif ($message_was_sent == -1) {\n \t\tdo_edit($t);\n@@ -2088,11 +2096,20 @@ sub validate_patch {\n \t\t\tchdir($repo->wc_path() or $repo->repo_path())\n \t\t\t\tor die(\"chdir: $!\");\n \t\t\tlocal $ENV{\"GIT_DIR\"} = $repo->repo_path();\n+\n+\t\t\tmy $header = gen_header();\n+\n+\t\t\trequire File::Temp;\n+\t\t\tmy ($header_filehandle, $header_filename) = File::Temp::tempfile(\n+                            \".gitsendemail.header.XXXXXX\", DIR => $repo->repo_path());\n+\t\t\tprint $header_filehandle $header;\n+\n \t\t\tmy @cmd = (\"git\", \"hook\", \"run\", \"--ignore-missing\",\n \t\t\t\t    $hook_name, \"--\");\n-\t\t\tmy @cmd_msg = (@cmd, \"<patch>\");\n-\t\t\tmy @cmd_run = (@cmd, $target);\n+\t\t\tmy @cmd_msg = (@cmd, \"<header>\");\n+\t\t\tmy @cmd_run = (@cmd, $header_filename);\n \t\t\t$hook_error = system_or_msg(\\@cmd_run, undef, \"@cmd_msg\");\n+\t\t\tunlink($header_filehandle);\n \t\t\tchdir($cwd_save) or die(\"chdir: $!\");\n \t\t}\n \t\tif ($hook_error) {\n-- \n2.34.1\n"},{"id":"467002","messageId":"Y2w0EjE5iuiUCEby@nand.local","threadId":"58778","inReplyTo":"20221109182254.71967-1-michael.strawbridge@amd.com","subject":"Re: [PATCH] Change git-send-email's sendemail-validate hook to use header information","fromName":"Taylor Blau","fromEmail":"me@ttaylorr.com","sentAt":"2022-11-09T23:13:22Z","receivedAt":"2022-11-09T23:13:29Z","isPatch":true,"sender":{"key":"me@ttaylorr.com","avatar":"https://avatars.githubusercontent.com/u/301000140?v=4"},"body":"Hi Michael,\n\nOn Wed, Nov 09, 2022 at 06:23:06PM +0000, Strawbridge, Michael wrote:\n> Since commit-msg and pre-commit git hooks already expose commit\n> contents, switch sendemail-validate to use the header information\n> of the email that git-send-email intends to send.\n>\n> Cc: Luben Tuikov <luben.tuikov@amd.com>\n> Cc: brian m. carlson <sandals@crustytoothpaste.net>\n\nWithout having looked at the patch below, would you mind re-submitting\nit with your Signed-off-by? Please see Documentation/SubmittingPatches\nfor more.\n\n\nThanks,\nTaylor\n"},{"id":"467004","messageId":"Y2w023Vi3Wt4J7se@tapette.crustytoothpaste.net","threadId":"58778","inReplyTo":"20221109182254.71967-1-michael.strawbridge@amd.com","subject":"Re: [PATCH] Change git-send-email's sendemail-validate hook to use header information","fromName":"brian m. carlson","fromEmail":"sandals@crustytoothpaste.net","sentAt":"2022-11-09T23:16:43Z","receivedAt":"2022-11-09T23:17:25Z","isPatch":true,"sender":{"key":"sandals@crustytoothpaste.net","avatar":"https://avatars.githubusercontent.com/u/497054?v=4"},"body":"On 2022-11-09 at 18:23:06, Strawbridge, Michael wrote:\n> Since commit-msg and pre-commit git hooks already expose commit\n> contents, switch sendemail-validate to use the header information\n> of the email that git-send-email intends to send.\n\nI have a couple of thoughts here, and maybe you can explain them a bit\nbetter in the commit message for v2.  First, I'm not sure why this is\nvaluable.  What do we gain from this that we don't have now?  Why is the\ncurrent state inadequate?\n\nAlso, how does this handle encoded headers?  I'd like to see some tests\nbefore and after here, especially some including non-ASCII user.name\nvalues so that we can test that we do the right thing here.  If there's\nsome beneficial improvement here that results in a behaviour change,\nthen of course we'd want to test that as well.\n\nFinally, since we move the validation code farther down instead of first\nthing, is there any place that this would result in a different\nbehaviour?  For example, --dry-run mode?  Is there any way we could send\ndata that isn't validated but should be?\n-- \nbrian m. carlson (he/him or they/them)\nToronto, Ontario, CA\n"}]}