aboutsummaryrefslogtreecommitdiffstats
path: root/git-send-email.perl
diff options
context:
space:
mode:
authorRobin Jarry <robin@jarry.cc>2023-04-14 17:52:49 +0200
committerJunio C Hamano <gitster@pobox.com>2023-04-14 10:41:15 -0700
commit3c8d3adeae8326d3b73fee0b134abd68d55f7c67 (patch)
tree09a635bd9b2dd026784d0d68cfe3eb5d2eff85e1 /git-send-email.perl
parent9857273be005833c71e2d16ba48e193113e12276 (diff)
downloadgit-3c8d3adeae8326d3b73fee0b134abd68d55f7c67.tar.gz
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>
Diffstat (limited to 'git-send-email.perl')
-rwxr-xr-xgit-send-email.perl17
1 files changed, 16 insertions, 1 deletions
diff --git a/git-send-email.perl b/git-send-email.perl
index fd8cd0d46f..66c9171109 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -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) {