diff options
author | Michael Strawbridge <michael.strawbridge@amd.com> | 2023-04-19 22:27:03 +0200 |
---|---|---|
committer | Junio C Hamano <gitster@pobox.com> | 2023-04-19 23:19:09 +0200 |
commit | a8022c5f7b678189135b6caa3fadb3d8ec0c0d48 (patch) | |
tree | 3d2d5787217c3096e3dcfb21e44ebccd715d2362 /git-send-email.perl | |
parent | send-email: refactor header generation functions (diff) | |
download | git-a8022c5f7b678189135b6caa3fadb3d8ec0c0d48.tar.xz git-a8022c5f7b678189135b6caa3fadb3d8ec0c0d48.zip |
send-email: expose header information to git-send-email's sendemail-validate hook
To allow further flexibility in the Git hook, the SMTP header
information of the email which git-send-email intends to send, is now
passed as the 2nd argument to the sendemail-validate hook.
As an example, this can be useful for acting upon keywords in the
subject or specific email addresses.
Cc: Luben Tuikov <luben.tuikov@amd.com>
Cc: Junio C Hamano <gitster@pobox.com>
Cc: Ævar Arnfjörð Bjarmason <avarab@gmail.com>
Acked-by: Luben Tuikov <luben.tuikov@amd.com>
Signed-off-by: Michael Strawbridge <michael.strawbridge@amd.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'git-send-email.perl')
-rwxr-xr-x | git-send-email.perl | 48 |
1 files changed, 29 insertions, 19 deletions
diff --git a/git-send-email.perl b/git-send-email.perl index e114efe323..10c450ef68 100755 --- a/git-send-email.perl +++ b/git-send-email.perl @@ -792,16 +792,31 @@ if (@rev_list_opts) { @rev_list_opts); } -@files = handle_backup_files(@files); +if (defined $sender) { + $sender =~ s/^\s+|\s+$//g; + ($sender) = expand_aliases($sender); +} else { + $sender = $repoauthor->() || $repocommitter->() || ''; +} + +# $sender could be an already sanitized address +# (e.g. sendemail.from could be manually sanitized by user). +# But it's a no-op to run sanitize_address on an already sanitized address. +$sender = sanitize_address($sender); + +$time = time - scalar $#files; if ($validate) { foreach my $f (@files) { unless (-p $f) { + pre_process_file($f, 1); validate_patch($f, $target_xfer_encoding); } } } +@files = handle_backup_files(@files); + if (@files) { unless ($quiet) { print $_,"\n" for (@files); @@ -1050,18 +1065,6 @@ if (!$force) { } } -if (defined $sender) { - $sender =~ s/^\s+|\s+$//g; - ($sender) = expand_aliases($sender); -} else { - $sender = $repoauthor->() || $repocommitter->() || ''; -} - -# $sender could be an already sanitized address -# (e.g. sendemail.from could be manually sanitized by user). -# But it's a no-op to run sanitize_address on an already sanitized address. -$sender = sanitize_address($sender); - my $to_whom = __("To whom should the emails be sent (if anyone)?"); my $prompting = 0; if (!@initial_to && !defined $to_cmd) { @@ -1221,10 +1224,6 @@ sub make_message_id { #print "new message id = $message_id\n"; # Was useful for debugging } - - -$time = time - scalar $#files; - sub unquote_rfc2047 { local ($_) = @_; my $charset; @@ -2108,10 +2107,21 @@ sub validate_patch { chdir($repo->wc_path() or $repo->repo_path()) or die("chdir: $!"); local $ENV{"GIT_DIR"} = $repo->repo_path(); + + my ($recipients_ref, $to, $date, $gitversion, $cc, $ccline, $header) = gen_header(); + + require File::Temp; + my ($header_filehandle, $header_filename) = File::Temp::tempfile( + TEMPLATE => ".gitsendemail.header.XXXXXX", + DIR => $repo->repo_path(), + UNLINK => 1, + ); + print $header_filehandle $header; + my @cmd = ("git", "hook", "run", "--ignore-missing", $hook_name, "--"); - my @cmd_msg = (@cmd, "<patch>"); - my @cmd_run = (@cmd, $target); + my @cmd_msg = (@cmd, "<patch>", "<header>"); + my @cmd_run = (@cmd, $target, $header_filename); $hook_error = system_or_msg(\@cmd_run, undef, "@cmd_msg"); chdir($cwd_save) or die("chdir: $!"); } |