git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
From: Peter Jones <pjones@redhat.com>
To: Junio C Hamano <gitster@pobox.com>
Cc: git@vger.kernel.org
Subject: Re: [PATCH] git-am: Handle "git show" output correctly
Date: Wed, 12 Sep 2012 16:48:38 -0400	[thread overview]
Message-ID: <1347482918.21933.5.camel@eddie.install.bos.redhat.com> (raw)
In-Reply-To: <7vtxv3atvu.fsf@alter.siamese.dyndns.org>

On Wed, 2012-09-12 at 13:06 -0700, Junio C Hamano wrote:
> Peter Jones <pjones@redhat.com> writes:
> 
> > This patch adds the ability for "git am" to accept patches in the format
> > generated by "git show".  Some people erroneously use "git show" instead
> > of "git format-patch", and it's nice as a maintainer to be able to
> > easily take their patch rather than going back and forth with them to
> > get a "correctly" formatted patch containing exactly the same actual
> > information.
> >
> > Signed-off-by: Peter Jones <pjones@redhat.com>
> > ---
> >  git-am.sh | 60 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> >  1 file changed, 60 insertions(+)
> >
> > diff --git a/git-am.sh b/git-am.sh
> > index c682d34..210e9fe 100755
> > --- a/git-am.sh
> > +++ b/git-am.sh
> > @@ -216,6 +216,21 @@ check_patch_format () {
> >  		read l2
> >  		read l3
> >  		case "$l1" in
> > +		"commit "*)
> > +			case "$l2" in
> > +			"Author: "*)
> > +				case "$l3" in
> > +				"Date: "*)
> > +					patch_format=gitshow
> > +					;;
> > +				*)
> > +					;;
> > +				esac
> > +				;;
> > +			*)
> > +				;;
> > +			esac
> > +			;;
> 
> At least the inner one could become easier to read by losing one
> level of nesting, e.g.
> 
> 	case "$l2,,$l3" in
>         "Author: *",,"Date: ")
> 		found it
>                 ;;
> 	esac

Yeah, I can do that.

> I wonder what the severity of the damage if we misidentify the patch
> format in this function would be?  If it is severe enough, the check
> for the first line may want to become a bit more strict to avoid
> misidentification (e.g. expr "$l1" : 'commit [0-9a-f]\{40\}$').
> Perhaps we don't care.  I dunno.

I hadn't really even considered it - are there other formats that use
commit and author which git-am.sh is supposed to support? It seems as
though if we get something wrong you'll wind up in clean_abort at some
point anyway.  At worst your patch will still be there and you'll need
to do "git am --abort".

> > @@ -321,6 +336,51 @@ split_patches () {
> >  		this=
> >  		msgnum=
> >  		;;
> > +	gitshow)
> > +		this=0
> > +		for patch in "$@"
> > +		do
> 
> So each input file is expected to be nothing but an output from "git
> show" for a single commit; in other words, not concatenation of
> them, nor just an e-mail message that has "git show" output
> copy&pasted in the body with some other cruft, but plausibly was
> delibered as a separate attachment file.
> 
> I somehow was visualizing that you were trying to accept mails I
> sometimes see here like:
> 
> 	From: somebody
>         Date: someday
> 
>         Hi, a long winded discussion that talks about the motivation
>         behind the patch comes here.
> 
> 	commit 4d8c4db13c8c4c79b6fc0a38ff52d85d3543aa7a
>         Author: A U Thor <author@example.com>
>         Date: Tue Sep 11 12:34:56 2012 +0900
> 
> 	    a one liner that just says "bugfix" and nothing else
> 
> 	diff --git ....
> 
> and that was one of the reasons I thought (but didn't say in my
> responses) "Why bother?  When running 'am' on such a message you
> will have to edit the message to move things around anyway".

Yeah, that sounds like madness.

> If the target is a stand-alone "git show" output, at least we do not
> have to worry about such a case.

Right.

> 
> > +			this=`expr "$this" + 1`
> > +			msgnum=`printf "%0${prec}d" $this`
> > +			# The first nonemptyline after an empty line is the
> > +			# subject, and the body starts with the next nonempty
> > +			# line.
> > +			perl -ne 'BEGIN {
> > +					$diff = 0; $subject = 0; $subjtext="";
> > +				}
> > +				if ($diff == 1 || /^diff/ || /^---$/) {
> > +					$diff = 1 ;
> > +					print ;
> > +				} elsif ($subject > 1) {
> > +					s/^    // ;
> > +					print ;
> > +				} elsif ($subject == 1 && !/^\s+$/) {
> > +					s/^    // ;
> > +					$subjtext = "$subjtext $_";
> > +				} elsif ($subject == 1) {
> > +					$subject = 2 ;
> > +					print "Subject: ", $subjtext ;
> > +					s/^    // ;
> > +					print ;
> > +				} elsif ($subject) {
> > +					print "\n" ;
> > +					s/^    // ;
> > +					print ;
> > +				} elsif (/^\s+$/) { next ; }
> > +				elsif (/^Author:/) { s/Author/From/ ; print ;}
> > +				elsif (/^(From|Date)/) { print ; }
> 
> Where does "^From" come from? Should this be /^Date: / instead?

Entirely copy-paste error on my part.  I'll fix it for the next version.

> 
> > +				elsif (/^commit/) { next ; }
> > +				else {
> > +					s/^    // ;
> > +					$subjtext = $_;
> > +					$subject = 1;
> > +				}
> > +			' < "$patch" > "$dotest/$msgnum" || clean_abort
> > +		done
> 
> This reminds me of another reason why I am hesitant to make "am"
> take output from "git show".  Unlike format-patch output, "Author:"
> and "Date:" in its output, because it is meant for human
> consumption, might be a fair game for i18n/l10n (the first line
> "commit [0-9][a-f]{40}" is not likely to change, though).

Well, if that happens, maybe we could regexp match on
"[[:alnum:]_-]+: /someexprthatlookslikeanemailaddress/" ?  But we could
also just wait to cross that bridge until we get to it?  Even if that
does get translated later, the current patch would continue to work for
English, so even in that case it's not totally worthless.

-- 
  Peter

  reply	other threads:[~2012-09-12 20:48 UTC|newest]

Thread overview: 21+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-09-12 15:26 [PATCH] Handle "git show" output correctly Peter Jones
2012-09-12 15:30 ` Peter Jones
2012-09-12 15:41   ` Matthieu Moy
2012-09-12 15:49     ` [PATCH] [git-am] " Peter Jones
2012-09-12 15:57       ` Matthieu Moy
2012-09-12 17:32         ` Junio C Hamano
2012-09-12 18:05           ` Peter Jones
2012-09-12 19:07             ` Junio C Hamano
2012-09-12 15:42   ` [PATCH] " Peter Jones
2012-09-12 15:40 ` Matthieu Moy
2012-09-12 18:00   ` Peter Jones
2012-09-12 18:08     ` [PATCH] git-am: " Peter Jones
2012-09-12 20:06       ` Junio C Hamano
2012-09-12 20:48         ` Peter Jones [this message]
2012-09-12 21:03           ` Peter Jones
2012-09-12 21:18           ` Junio C Hamano
2012-09-12 21:26             ` Dan Johnson
2012-09-12 22:19               ` Junio C Hamano
2012-09-12 22:31                 ` Dan Johnson
2012-09-12 23:05                   ` Junio C Hamano
2012-09-12 22:41                 ` Andreas Ericsson

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=1347482918.21933.5.camel@eddie.install.bos.redhat.com \
    --to=pjones@redhat.com \
    --cc=git@vger.kernel.org \
    --cc=gitster@pobox.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).