From: Junio C Hamano <gitster@pobox.com>
To: Vitaly Mayatskikh <v.mayatskih@gmail.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] git-send-email: parse all messages in mbox
Date: Tue, 12 May 2009 16:27:21 -0700 [thread overview]
Message-ID: <7vpred7vhi.fsf@alter.siamese.dyndns.org> (raw)
In-Reply-To: 873abbeoqc.wl%vmayatsk@redhat.com
Vitaly Mayatskikh <v.mayatskih@gmail.com> writes:
> Currently git-send-email sends all mbox in one email. This seems to be wrong,
> because mbox can contain several messages. For example,
> `git format-patch --stdout' forms mbox file with all patches in it.
>
> This patch allows git send-email to send several messages from one mbox
> separately.
I suspect nobody would comment on it because with reindentation this was
extremely painful to review.
I _think_ the gist of your change is that (1) here you stop slurping the
body when you see a line that begins with "From "...
> + # Now parse the message body
> + while(<F>) {
> + last if /^From /; # Next message in file
... and (2) the "last unless (<F>)" at the end of the loop where you
attempt to see if there is any more lines to be read from the stream (and
if so go back and continue from the header parsing).
> - # set up for the next message
> - if ($chain_reply_to || !defined $reply_to || length($reply_to) == 0) {
> - $reply_to = $message_id;
> - if (length $references > 0) {
> - $references .= "\n $message_id";
> - } else {
> - $references = "$message_id";
> + # set up for the next message
> + if ($chain_reply_to || !defined $reply_to || length($reply_to) == 0) {
> + $reply_to = $message_id;
> + if (length $references > 0) {
> + $references .= "\n $message_id";
> + } else {
> + $references = "$message_id";
> + }
> }
> + $message_id = undef;
> + last unless (<F>);
> }
> - $message_id = undef;
> + close F;
But I think the code structure is wrong. When you said "last if /^From /"
earlier, you have already read that line (and you do not unread it), and
here with "unless (<F>)" you are reading yet another line (one line after
the UNIX-From line) and discarding it. The next round loses the real
RFC2822 header line you discarded with this unless (<F>), and begins from
the next line, and would break "First unfold multiline header fields"
logic among other things.
But this is only from reviewing a patch with reindentation noise so I
might have missed some subtle issues.
Can you make this into two patches for easier review? One to split out
the existing loop for a single input stream into a helper function without
changing any behaviour (i.e. the loop reads everything to the end), and
then as a follow-up patch introduce "when we see a UNIX-From line we are
at the beginning of the next message so return early" logic to the helper?
IOW, after the two-patch series, the current main-loop may look
something like:
my $unread_line = undef;
while (1) {
$unread_line = handle_one_stream(\*F, $unread_line);
last if (!defined $unread_line);
}
close(\*F);
and your new handle_one_stream() sub will look something like:
sub handle_one_stream {
my ($fh, $last_line) = @_;
local ($_);
my $author = undef;
my $author_encoding;
my $has_content_type;
my $body_encoding;
@cc = ();
@xh = ();
my $input_format = undef;
my @header = ();
$message = "";
$message_num++;
# First unfold multiline header fields
while (1) {
if (defined $last_line) {
$_ = $last_line;
$last_line = undef;
} else {
$_ = <F>;
}
...
}
# Now parse the header
...
# Now parse the message body
$last_line = undef;
while (1) {
$_ = <F>;
if (/^From /) {
# This is the beginning of the
# next message; unread it.
$last_line = $_;
last;
}
$message .= $_;
...
}
return $last_line;
}
next prev parent reply other threads:[~2009-05-12 23:29 UTC|newest]
Thread overview: 5+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-11 13:46 [PATCH] git-send-email: parse all messages in mbox Vitaly Mayatskikh
2009-05-12 23:27 ` Junio C Hamano [this message]
2009-05-14 9:47 ` Vitaly Mayatskikh
2009-05-14 14:48 ` Jay Soffian
2009-05-14 18:41 ` Vitaly Mayatskikh
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=7vpred7vhi.fsf@alter.siamese.dyndns.org \
--to=gitster@pobox.com \
--cc=git@vger.kernel.org \
--cc=v.mayatskih@gmail.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).