Re: [PATCH v3] import-tars: Allow per-tar author and commit message.
- From
Junio C Hamano <gitster@pobox.com>
- Date
- Aug 28, 2009, 01:38 UTC
- Message-ID
- <7vskfcd8ep.fsf@alter.siamese.dyndns.org>
- In-Reply-To
- <alpine.DEB.2.00.0908270741170.6459@perkele.intern.softwolves.pp.se>
Peter Krefting <peter@softwolves.pp.se> writes:
Show 9 quoted lines
> Junio C Hamano: > >> Do you really want to slurp Committer:/Author: lines from _anywhere_ >> in the file? Wouldn't it make more sense to vaguely emulate e-mail >> message format with headers, empty-line and then body that is free >> form? > > I just tried not to overdo it, and keep the parsing code as simple as > possible. I wasn't trying to implement an RFC 5322 compliant parser...
It is not about overdoing, but about not glossly underdoing.
Don't you at least want to avoid misparsing a msg file that looks like this?
Author: Peter Krefting <peter@softwolves.pp.se>
import-tars: Allow per-tar author and commit message
This version updates the import-tars program so that another
file next to the archive can be read for the log message and
other meta information. A line that begins with Committer: or
Author: is used as long as it consists of name and <email>
to override the corresponding metainformation. Remaining lines
are used as the commit log message.And I do not think you need a complex parser. Stop paying attention to a line that begins with Author:/Committer:, once you see a line that does not match the pattern; and you would be Ok.
IOW, something like...
my $reading_metainfo = 1;
my $squashing_empty = 0;
while (<>) {
if ($reading_metainfo) {
if (/^Committer:.../) {
...
next;
} elsif (/^Author:.../) {
...
next;
} else {
$reading_metainfo = 0;
}
}
if (/^$/) {
$squashing_empty = 1;
next;
}
if ($squashing_empty && $commit_msg ne '') {
$commit_msg .= "\n";
}
$commit_msg .= $_;
$squashing_empty = 0;
}