send-email: export patch counters in validate environment
When sending patch series (with a cover-letter or not) sendemail-validate is called with every email/patch file independently from the others. When one of the patches depends on a previous one, it may not be possible to use this hook in a meaningful way. A hook that wants to check some property of the whole series needs to know which patch is the final one. Expose the current and total number of patches to the hook via the GIT_SENDEMAIL_PATCH_COUNTER and GIT_SENDEMAIL_PATCH_TOTAL environment variables so that both incremental and global validation is possible. Sharing any other state between successive invocations of the validate hook must be done via external means. For example, by storing it in a git config sendemail.validateWorktree entry. Add a sample script with placeholder validations and update tests to check that the counters are properly exported. Suggested-by: Phillip Wood <phillip.wood123@gmail.com> Signed-off-by: Robin Jarry <robin@jarry.cc> Signed-off-by: Junio C Hamano <gitster@pobox.com>
This commit is contained in:

committed by
Junio C Hamano

parent
9857273be0
commit
3c8d3adeae
@ -795,11 +795,26 @@ if (@rev_list_opts) {
|
||||
@files = handle_backup_files(@files);
|
||||
|
||||
if ($validate) {
|
||||
# FIFOs can only be read once, exclude them from validation.
|
||||
my @real_files = ();
|
||||
foreach my $f (@files) {
|
||||
unless (-p $f) {
|
||||
validate_patch($f, $target_xfer_encoding);
|
||||
push(@real_files, $f);
|
||||
}
|
||||
}
|
||||
|
||||
# Run the loop once again to avoid gaps in the counter due to FIFO
|
||||
# arguments provided by the user.
|
||||
my $num = 1;
|
||||
my $num_files = scalar @real_files;
|
||||
$ENV{GIT_SENDEMAIL_FILE_TOTAL} = "$num_files";
|
||||
foreach my $r (@real_files) {
|
||||
$ENV{GIT_SENDEMAIL_FILE_COUNTER} = "$num";
|
||||
validate_patch($r, $target_xfer_encoding);
|
||||
$num += 1;
|
||||
}
|
||||
delete $ENV{GIT_SENDEMAIL_FILE_COUNTER};
|
||||
delete $ENV{GIT_SENDEMAIL_FILE_TOTAL};
|
||||
}
|
||||
|
||||
if (@files) {
|
||||
|
Reference in New Issue
Block a user