git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Phillip Wood <phillip.wood123@gmail.com>
To: Robin Jarry <robin@jarry.cc>, git@vger.kernel.org
Cc: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>,
	"Tim Culverhouse" <tim@timculverhouse.com>,
	"Nicolas Dichtel" <nicolas.dichtel@6wind.com>,
	"Bagas Sanjaya" <bagasdotme@gmail.com>,
	"Junio C Hamano" <gitster@pobox.com>,
	"Eric Sunshine" <sunshine@sunshineco.com>,
	"Michael Strawbridge" <michael.strawbridge@amd.com>
Subject: Re: [PATCH] send-email: export patch counters in validate environment
Date: Tue, 11 Apr 2023 14:23:14 +0100	[thread overview]
Message-ID: <79a7c59f-6644-1dad-3b85-fe0ca8beb968@gmail.com> (raw)
In-Reply-To: <20230411114723.89029-1-robin@jarry.cc>

Hi Robin

On 11/04/2023 12:47, Robin Jarry wrote:
> 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_DIR/SENDEMAIL_VALIDATE file.
> 
> Suggested-by: Phillip Wood <phillip.wood123@gmail.com>
> Signed-off-by: Robin Jarry <robin@jarry.cc>
> ---
> 
> Notes:
>      Follow up on:
>      https://lore.kernel.org/git/9b8d6cc4-741a-5081-d5de-df0972efec37@gmail.com/
>      
>      As suggested by Phillip, this is a less intrusive change which allows
>      validating whole series. Let me know what you think.

This is certainly less intrusive, if it does what you need and is 
efficient enough for your needs then I'd be inclined to go with this 
approach.

>   Documentation/githooks.txt | 10 ++++++++++
>   git-send-email.perl        |  7 +++++++
>   2 files changed, 17 insertions(+)
> 
> diff --git a/Documentation/githooks.txt b/Documentation/githooks.txt
> index 62908602e7be..55f00e0f6f8c 100644
> --- a/Documentation/githooks.txt
> +++ b/Documentation/githooks.txt
> @@ -600,6 +600,16 @@ the name of the file that holds the e-mail to be sent.  Exiting with a
>   non-zero status causes `git send-email` to abort before sending any
>   e-mails.
>   
> +The following environment variables are set when executing the hook.
> +
> +`GIT_SENDEMAIL_PATCH_COUNTER`::
> +	A 1-based counter incremented by one for every file.
> +
> +`GIT_SENDEMAIL_PATCH_TOTAL`::
> +	The total number of files.
> +
> +These variables can be used to validate patch series.
> +
>   fsmonitor-watchman
>   ~~~~~~~~~~~~~~~~~~
>   
> diff --git a/git-send-email.perl b/git-send-email.perl
> index 07f2a0cbeaad..e962d5e15983 100755
> --- a/git-send-email.perl
> +++ b/git-send-email.perl
> @@ -795,10 +795,17 @@ sub is_format_patch_arg {
>   @files = handle_backup_files(@files);
>   
>   if ($validate) {
> +	my $num = 1;
> +	my $num_patches = @files;
>   	foreach my $f (@files) {
>   		unless (-p $f) {
> +			$ENV{GIT_SENDEMAIL_PATCH_COUNTER} = "$num";
> +			$ENV{GIT_SENDEMAIL_PATCH_TOTAL} = "$num_patches";

We only need to set this once outside the loop

>   			validate_patch($f, $target_xfer_encoding);
> +			delete $ENV{GIT_SENDEMAIL_PATCH_COUNTER};
> +			delete $ENV{GIT_SENDEMAIL_PATCH_TOTAL};

Do we really need to clear these? Certainly not in each iteration of the 
loop I would think.

Best Wishes

Phillip
>   		}
> +		$num += 1;
>   	}
>   }
>   


  reply	other threads:[~2023-04-11 13:23 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-11 11:47 [PATCH] send-email: export patch counters in validate environment Robin Jarry
2023-04-11 13:23 ` Phillip Wood [this message]
2023-04-11 16:28   ` Junio C Hamano
2023-04-11 17:13     ` Robin Jarry
2023-04-11 19:14       ` Junio C Hamano
2023-04-11 16:47   ` Robin Jarry
2023-04-12  9:54 ` [PATCH v2] " Robin Jarry
2023-04-12 17:53   ` Junio C Hamano
2023-04-12 18:33     ` Robin Jarry
2023-04-12 20:37       ` Junio C Hamano
2023-04-12 20:39         ` Robin Jarry
2023-04-12 21:48     ` Junio C Hamano
2023-04-12 21:45   ` [PATCH v3] " Robin Jarry
2023-04-13 13:52     ` Phillip Wood
2023-04-13 14:01       ` Robin Jarry
2023-04-14 12:58         ` Phillip Wood
2023-04-14 15:28     ` [PATCH v4] " Robin Jarry
2023-04-14 15:50       ` Robin Jarry
2023-04-14 15:52       ` [PATCH v5] " Robin Jarry
2023-04-20 19:16         ` Robin Jarry
2023-04-20 19:25           ` Junio C Hamano

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=79a7c59f-6644-1dad-3b85-fe0ca8beb968@gmail.com \
    --to=phillip.wood123@gmail.com \
    --cc=avarab@gmail.com \
    --cc=bagasdotme@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.com \
    --cc=michael.strawbridge@amd.com \
    --cc=nicolas.dichtel@6wind.com \
    --cc=phillip.wood@dunelm.org.uk \
    --cc=robin@jarry.cc \
    --cc=sunshine@sunshineco.com \
    --cc=tim@timculverhouse.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).