git/list[1] front-page[2] threads[3] people[4] search[5] about
 

Re: [PATCH v2] git-am: fix maildir support regression for unordered headers in emails

From
Junio C Hamano <gitster@pobox.com>
Date
Jul 15, 2009, 07:27 UTC
Message-ID
<7vljmqflti.fsf@alter.siamese.dyndns.org>
In-Reply-To
<2433101adeafddeab78815083446552ff3ea9f49.1247636959.git.nicolas.s.dev@gmx.fr>
Nicolas Sebrecht <nicolas.s.dev@gmx.fr> writes:
> Patch format detection introduced by a5a6755a1d4707bf2fab7752e5c974ebf63d086a
> may refuse valid patches from verbatim emails.

It is unclear what you meant by "verbatim email". A verbatim e-mail in mbox begins with "From " header that is already covered in the existing code long before support for stgit/hg was added.

> +		# Keep maildir workflows support.
> +		# Verbatim emails may have header fields in random order.
> +		is_verbatim_email='true'
We do not fold lines like this,
> +		for line in "$l1" "$l2" "$l3"; do
Instead, we write like this:
	for x in a b c
	do
		cmd ...
> +			printf "$line" | grep --quiet --extended-regexp '^([^\ ])+: +.*' ||

We use GNUism spelling --extended-regexp nowhere in scripted Porcelains; just say -E here, and do not omit -e before the pattern.

Likewise for --quiet. Just say -q. When in doubt, be conservative and stick to POSIX for portability.

    http://www.opengroup.org/onlinepubs/9699919799/utilities/grep.html#tag_20_55
Your regexp has too many issues.
 - It is too loose and too strict at the same time.  RFC 2822 section 2.2
   and 3.6.8 specify that a field name must be composed of printable
   US-ASCII characters except colon and space, so if you really want to be
   lenient, it should instead begin with [^: ]+: (and you do not need any
   capture).
 - I think however starting the regexp with "^[A-Za-z]+(-[A-Za-z]+)*:"
   would be more appropriate in practice, though.
 - You do not need to end the expression with ".*"; omitting that would
   match the same set of lines anyway.
 - I thought you were advocating for not requiring SP after the colon?
 - What happens if $l2 or $l3 is a subsequent folded line?  For example,
   in my MUA edit buffer, this message begins with:
       To: Nicolas Sebrecht <nicolas.s.dev@gmx.fr>
       Cc: <git@vger.kernel.org>,
           Giuseppe Bilotta <giuseppe.bilotta@gmail.com>,
           Johannes Sixt <j.sixt@viscovery.net>
       Subject: Re: [PATCH v2] git-am: fix maildir support ...
   The third line would not match your regexp.
> +				is_verbatim_email='false'
> +		done
> +		# next treatments don't differ from mailbox format
> +		[[ $is_verbatim_email == 'true' ]] && patch_format=mbox
We do not use non-portable [[ ]] anywhere in our shell script.  Write
	if test true = "$is_verbatim_email"
        then
        	patch_format=mbox
	fi
if you really want to keep this code structure.

I actually do not think you would even need an extra is_verbatim_email variable, though. Assuming that I understand what you are trying to do, this is probably how I would write it:

	sed -e '/^$/q' -e '/^[ 	]/d' "$1" |
        grep -v -E -e '^[A-Za-z]+(-[A-Za-z]+)*:' >/dev/null ||
        patch_format=mbox

But I am not convinced that I understand what _problem_ you are trying to solve in the first place.

Previous: Nicolas SebrechtNext: Derek Fawcus
Message 8 of 10 in “git-am: less strong format "mbox" detection”
  1. git-am: less strong format "mbox" detectionNicolas Sebrecht, Jul 14, 2009
  2. Giuseppe BilottaJul 14, 2009
  3. Re: git-am: less strong format "mbox" detectionNicolas Sebrecht, Jul 14, 2009
  4. Johannes SixtJul 14, 2009
  5. Junio C HamanoJul 14, 2009
  6. Re: git-am: less strong format "mbox" detectionNicolas Sebrecht, Jul 14, 2009
  7. git-am: fix maildir support regression for unordered headers in emailsNicolas Sebrecht, Jul 15, 2009
  8. Junio C HamanoJul 15, 2009
  9. Derek FawcusJul 15, 2009
  10. Re: git-am: fix maildir support regression for unordered headers in emailsNicolas Sebrecht, Jul 15, 2009

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.