From mboxrd@z Thu Jan 1 00:00:00 1970 From: Peter Jones Subject: [PATCH] git-am: Handle "git show" output correctly Date: Wed, 12 Sep 2012 17:03:07 -0400 Message-ID: <1347483787-25623-1-git-send-email-pjones@redhat.com> References: <1347482918.21933.5.camel@eddie.install.bos.redhat.com> Cc: Peter Jones To: git@vger.kernel.org X-From: git-owner@vger.kernel.org Wed Sep 12 23:03:42 2012 Return-path: Envelope-to: gcvg-git-2@plane.gmane.org Received: from vger.kernel.org ([209.132.180.67]) by plane.gmane.org with esmtp (Exim 4.69) (envelope-from ) id 1TBu5z-0008Nj-Uq for gcvg-git-2@plane.gmane.org; Wed, 12 Sep 2012 23:03:40 +0200 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1753332Ab2ILVDc (ORCPT ); Wed, 12 Sep 2012 17:03:32 -0400 Received: from mx1.redhat.com ([209.132.183.28]:29364 "EHLO mx1.redhat.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1751901Ab2ILVDb (ORCPT ); Wed, 12 Sep 2012 17:03:31 -0400 Received: from int-mx10.intmail.prod.int.phx2.redhat.com (int-mx10.intmail.prod.int.phx2.redhat.com [10.5.11.23]) by mx1.redhat.com (8.14.4/8.14.4) with ESMTP id q8CL3Vsw027011 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=OK) for ; Wed, 12 Sep 2012 17:03:31 -0400 Received: from eddie.install.bos.redhat.com (ovpn-112-24.phx2.redhat.com [10.3.112.24]) by int-mx10.intmail.prod.int.phx2.redhat.com (8.14.4/8.14.4) with ESMTP id q8CL3TxJ026784; Wed, 12 Sep 2012 17:03:30 -0400 In-Reply-To: <1347482918.21933.5.camel@eddie.install.bos.redhat.com> X-Scanned-By: MIMEDefang 2.68 on 10.5.11.23 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Archived-At: 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 --- git-am.sh | 57 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 57 insertions(+) diff --git a/git-am.sh b/git-am.sh index c682d34..d20f249 100755 --- a/git-am.sh +++ b/git-am.sh @@ -216,6 +216,18 @@ check_patch_format () { read l2 read l3 case "$l1" in + "commit "*) + case "$l2,,$l3" in + "Author: "*,,"Date: "*) + if expr "$l1" : 'commit [0-9a-f]\{40\}$' \ + >/dev/null ; then + patch_format=gitshow + fi + ;; + *) + ;; + esac + ;; "From "* | "From: "*) patch_format=mbox ;; @@ -321,6 +333,51 @@ split_patches () { this= msgnum= ;; + gitshow) + this=0 + for patch in "$@" + do + 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 (/^Date:/) { print ; } + elsif (/^commit/) { next ; } + else { + s/^ // ; + $subjtext = $_; + $subject = 1; + } + ' < "$patch" > "$dotest/$msgnum" || clean_abort + done + echo "$this" > "$dotest/last" + this= + msgnum= + ;; hg) this=0 for hg in "$@" -- 1.7.11.4