git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] send-email: fix bug breaking shallow threading if the first patch is edited
@ 2025-05-23 15:36 Aditya Garg
  2025-05-23 15:44 ` Aditya Garg
                   ` (3 more replies)
  0 siblings, 4 replies; 12+ messages in thread
From: Aditya Garg @ 2025-05-23 15:36 UTC (permalink / raw)
  To: Junio C Hamano, git@vger.kernel.org
  Cc: Eric Sunshine, brian m. carlson, Julian Swagemakers, Zi Yao,
	Jeff King

There is a bug in send-email that turns off shallow threading if
some special conditions are there. Those conditions are:

1. An --in-reply-to must be specified when sending the patch
2. When asked for confirmation before sending the first patch, the
  user must edit the patch (pressing e and enter).

If these two conditions are fulfilled, the threading will turn off
and all subsequent messages will become as replies to the
Message-ID set in --in-reply-to, rather than becoming replies to
the first patch.

The cause of this bug was very simple. There are many conditions
that determine whether threading should be done or not. The
relevant ones for this case are:

1. --in-reply-to is not defined
2. $message_num is 1

If ANY ONE of these is fulfilled, threading will occur. Now, in
our case, we have defined an --in-reply-to, so condition 1 is
not fulfilled, and thus is omitted out. The only condition that
can enable threading is $message_num being 1. As far as I
understand, this condition was based on the assumption that the
first message being send will have $message_num as 1, since in
case of shallow threads, we just set in-reply-to only for the
Message-ID of the first patch sent. But, in case we edit a patch,
its $message_num increases by one, and thus, our second condition
for threading is also not fulfilled, thus turning off threading.

Luckily, the script also keeps count of the number of messages
actually sent using the $num_sent variable. This was implemented
for people who have set a particular batch size for emails. This
is a more reliable indicator to track the actual first patch.

So, whenever the first patch is sent, $num_sent will become 1.
If we replace the condition to use threading from $message_num
to $num_sent=1, it will always be fulfilled irrespective of
whether the user edits the first patch or not, and thus threading
will turn on.

This bug will not be triggered if --in-reply-to is not set,
because the first condition (not having an --in-reply-to) gets
fulfilled, so the script doesn't care what $message_num is there.

Signed-off-by: Aditya Garg <gargaditya08@live.com>
---
git-send-email.perl | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/git-send-email.perl b/git-send-email.perl
index 55b7e00d29..2cfd61b4b9 100755
--- a/git-send-email.perl
+++ b/git-send-email.perl
@@ -2041,10 +2041,11 @@ sub process_file {
	}

	# set up for the next message
+	$num_sent++;
	if ($thread) {
		if ($message_was_sent &&
		  ($chain_reply_to || !defined $in_reply_to || length($in_reply_to) == 0 ||
-		  $message_num == 1)) {
+		  $num_sent == 1)) {
			$in_reply_to = $message_id;
			if (length $references > 0) {
				$references .= "\n $message_id";
@@ -2060,7 +2061,6 @@ sub process_file {
		$references = '';
	}
	$message_id = undef;
-	$num_sent++;
	if (defined $batch_size && $num_sent == $batch_size) {
		$num_sent = 0;
		$smtp->quit if defined $smtp;
-- 
2.43.0


^ permalink raw reply related	[flat|nested] 12+ messages in thread
* Re: [PATCH] send-email: fix bug breaking shallow threading if the first patch is edited
@ 2025-05-24  2:56 Aditya Garg
  0 siblings, 0 replies; 12+ messages in thread
From: Aditya Garg @ 2025-05-24  2:56 UTC (permalink / raw)
  To: Junio C Hamano
  Cc: git@vger.kernel.org, Eric Sunshine, brian m. carlson,
	Julian Swagemakers, Zi Yao, Jeff King



> On 24 May 2025, at 3:49 AM, Junio C Hamano <gitster@pobox.com> wrote:
> 
> Aditya Garg <gargaditya08@live.com> writes:
> 
>> So, whenever the first patch is sent, $num_sent will become 1.
> 
> The reverse is not always true, though.
> 
>>    # set up for the next message
>> +    $num_sent++;
>>    if ($thread) {
>>        if ($message_was_sent &&
>>          ($chain_reply_to || !defined $in_reply_to || length($in_reply_to) == 0 ||
>> -          $message_num == 1)) {
>> +          $num_sent == 1)) {
> 
> This sais "enter this block if we have sent a message and one of
> (num_set is 1, or we are told to chain-reply-to, or we do not have
> in-reply-to) holds true".
> 
> But is $num_set == 1 really limited to "the first message"?  Given
> that ...
> 
>>            $in_reply_to = $message_id;
>>            if (length $references > 0) {
>>                $references .= "\n $message_id";
>> @@ -2060,7 +2061,6 @@ sub process_file {
>>        $references = '';
>>    }
>>    $message_id = undef;
>> -    $num_sent++;
>>    if (defined $batch_size && $num_sent == $batch_size) {
>>        $num_sent = 0;
> 
> ... the counter is reset when we send out the batch_size message
> (and we sleep in this block, which is outside the post-context of
> this hunk).  So when you send the first message of the next batch,
> you'd do the same, no?  By that time, we have in_reply_to set, but
> that does not prevent from $num_sent, which was reset to 0 at the
> batch boundary and then incremented to 1, to reenter the block in
> the first hunk, no?
> 

Hmm, you are right, that's a problem. I think we need to fix message
number then.

^ permalink raw reply	[flat|nested] 12+ messages in thread
* Re: [PATCH] send-email: fix bug breaking shallow threading if the first patch is edited
@ 2025-05-24  2:57 Aditya Garg
  0 siblings, 0 replies; 12+ messages in thread
From: Aditya Garg @ 2025-05-24  2:57 UTC (permalink / raw)
  To: Jacob Keller
  Cc: Junio C Hamano, git@vger.kernel.org, Eric Sunshine,
	brian m. carlson, Julian Swagemakers, Zi Yao, Jeff King



> On 24 May 2025, at 5:08 AM, Jacob Keller <jacob.e.keller@intel.com> wrote:
> 
> 
> 
>> On 5/23/2025 8:36 AM, Aditya Garg wrote:
>> There is a bug in send-email that turns off shallow threading if
>> some special conditions are there. Those conditions are:
>> 
>> 1. An --in-reply-to must be specified when sending the patch
>> 2. When asked for confirmation before sending the first patch, the
>>  user must edit the patch (pressing e and enter).
>> 
>> If these two conditions are fulfilled, the threading will turn off
>> and all subsequent messages will become as replies to the
>> Message-ID set in --in-reply-to, rather than becoming replies to
>> the first patch.
>> 
>> The cause of this bug was very simple. There are many conditions
>> that determine whether threading should be done or not. The
>> relevant ones for this case are:
>> 
>> 1. --in-reply-to is not defined
>> 2. $message_num is 1
>> 
>> If ANY ONE of these is fulfilled, threading will occur. Now, in
>> our case, we have defined an --in-reply-to, so condition 1 is
>> not fulfilled, and thus is omitted out. The only condition that
>> can enable threading is $message_num being 1. As far as I
>> understand, this condition was based on the assumption that the
>> first message being send will have $message_num as 1, since in
>> case of shallow threads, we just set in-reply-to only for the
>> Message-ID of the first patch sent. But, in case we edit a patch,
>> its $message_num increases by one, and thus, our second condition
>> for threading is also not fulfilled, thus turning off threading.
>> 
> 
> Why does editing a message change the message_num??? That feels like the
> real bug to me..

I thought that was intended, not it doesn't seem like that to me.

^ permalink raw reply	[flat|nested] 12+ messages in thread

end of thread, other threads:[~2025-05-26 15:54 UTC | newest]

Thread overview: 12+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2025-05-23 15:36 [PATCH] send-email: fix bug breaking shallow threading if the first patch is edited Aditya Garg
2025-05-23 15:44 ` Aditya Garg
2025-05-23 22:19 ` Junio C Hamano
2025-05-23 23:37 ` Jacob Keller
2025-05-24 12:39 ` [PATCH v2] send-email: fix bug resulting in increased message number if a message " Aditya Garg
2025-05-25 17:12   ` [PATCH v3 0/2] send-email: fix threads breaking in case user edits emails and improvements to outlook ID fix Aditya Garg
2025-05-25 17:12     ` [PATCH v3 1/2] send-email: fix bug resulting in increased message number if a message is edited Aditya Garg
2025-05-25 18:49       ` Kristoffer Haugsbakk
2025-05-26 15:54         ` Aditya Garg
2025-05-25 17:12     ` [PATCH v3 2/2] send-email: show the new message id assigned by outlook in the logs Aditya Garg
  -- strict thread matches above, loose matches on Subject: below --
2025-05-24  2:56 [PATCH] send-email: fix bug breaking shallow threading if the first patch is edited Aditya Garg
2025-05-24  2:57 Aditya Garg

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).