git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Phillip Wood <phillip.wood123@gmail.com>
To: Robin Jarry <robin@jarry.cc>, git@vger.kernel.org
Cc: 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>
Subject: Re: [PATCH RESEND] hooks: add sendemail-validate-series
Date: Mon, 3 Apr 2023 16:20:30 +0100	[thread overview]
Message-ID: <9429a246-4921-c9f6-0318-834c86b35898@dunelm.org.uk> (raw)
In-Reply-To: <CRN7096DENCQ.1HF4OQ0ZD4HFP@ringo>

Hi Robin

On 03/04/2023 15:32, Robin Jarry wrote:
> Hi Phillip,
> 
> Phillip Wood, Apr 03, 2023 at 16:09:
>>> +  <patch-file> LF
>>
>> Usually git commands that produce or consume paths either use quoted
>> paths terminated by LF or unquoted paths terminated by NUL. That way
>> there is no ambiguity when a path contains LF.
> 
> I had never imagined that some twisted mind would insert LF in path
> names but since nothing will forbid it, I agree that it is
> a possibility.
> 
> I'm not sure what you mean by quoted paths, you mean adding literal
> double quotes before printing them to the hook stdin? That means the
> hook needs to handle de-quoting after reading, right?

I meant quoted in the same way that diff and ls-files etc quote paths 
that contain control characters - see quote_c_style() in quote.c if 
you're interested in the details. It looks like Git.pm can unquote paths 
but has no code to quote them. It is probably easiest to use NUL 
termination here - bash and zsh can read NUL terminated lines and so can 
any scripting language.

>>> diff --git a/git-send-email.perl b/git-send-email.perl
>>> index 07f2a0cbeaad..bec4d0f4ab47 100755
>>> --- a/git-send-email.perl
>>> +++ b/git-send-email.perl
>>> @@ -800,6 +800,7 @@ sub is_format_patch_arg {
>>>    			validate_patch($f, $target_xfer_encoding);
>>>    		}
>>>    	}
>>> +	validate_patch_series(@files)
>>
>> This happens fairly early, before the user has had a chance to edit the
>> patches and before we have added all the recipient and in-reply-to
>> headers to the patch files. Would it be more useful to validate what
>> will actually be sent?
> 
> I agree that it would be better. I added the check here to be in line
> with the existing sendemail-validate hook. I could move it after edition
> and header finalization but then we would need to move
> sendemail-validate as well for consistency. What do you think?

That would be my inclination but I'm only an occasional send-email user. 
The downside is that the user may edit a patch only for it to be 
rejected but we could offer for them to edit it again rather than just 
throwing their work away.

>>> +	# The hook needs a correct cwd and GIT_DIR.
>>> +	require Cwd;
>>> +	my $cwd_save = Cwd::getcwd();
>>> +	chdir($repo->wc_path() or $repo->repo_path()) or die("chdir: $!");
>>> +	local $ENV{"GIT_DIR"} = $repo->repo_path();
>>
>> This looks like it is copied from the existing code but why do we need
>> to do this? I'm struggling to come up with a scenario where "git
>> send-email" can find the repository but the hook cannot.
> 
> Again, for consistency I assumed it would be best to keep the code
> similar in both hooks. If you think it is safe to skip that check, I'll
> remove it gladly.

I suspect it is safe, hopefully someone will speak up if I'm mistaken. A 
while ago rebase stopped setting these variables when running an "exec" 
command as they were causing problems (see 434e0636db (sequencer: do not 
export GIT_DIR and GIT_WORK_TREE for 'exec', 2021-12-04))

>>> +	# cannot use git hook run, it closes stdin before forking the hook
>>> +	open(my $stdin, "|-", $validate_hook) or die("fork: $!");
>>
>> This passes $validate_hook to the shell to execute which is not what we
>> want as it will split the hook path on whitespace etc. I think it would
>> be better to use "git hook run --to-stdin" (see 0414b3891c (hook:
>> support a --to-stdin=<path> option, 2023-02-08))
> 
> Ah that's a nice addition. I'll add that in v2.

That's great, Best Wishes

Phillip

> Thanks for reviewing!

  reply	other threads:[~2023-04-03 15:20 UTC|newest]

Thread overview: 18+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2023-04-02 18:56 [PATCH RESEND] hooks: add sendemail-validate-series Robin Jarry
2023-04-03  0:17 ` Eric Sunshine
2023-04-03 14:09 ` Phillip Wood
2023-04-03 14:32   ` Robin Jarry
2023-04-03 15:20     ` Phillip Wood [this message]
2023-04-03 15:42   ` Junio C Hamano
2023-04-03 17:25     ` Robin Jarry
2023-04-03 22:29   ` Robin Jarry
2023-04-03 22:52     ` Junio C Hamano
2023-04-03 22:59       ` Robin Jarry
2023-04-04 20:14         ` Junio C Hamano
2023-04-05  8:31           ` Robin Jarry
2023-04-05 21:49             ` Junio C Hamano
2023-04-05 23:13 ` [PATCH v2] " Robin Jarry
2023-04-06  8:56   ` Ævar Arnfjörð Bjarmason
2023-04-11  9:58     ` Phillip Wood
2023-04-11 10:39       ` Robin Jarry
2023-04-11 15:58       ` 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

  List information: http://vger.kernel.org/majordomo-info.html

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

  git send-email \
    --in-reply-to=9429a246-4921-c9f6-0318-834c86b35898@dunelm.org.uk \
    --to=phillip.wood123@gmail.com \
    --cc=bagasdotme@gmail.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).