git@vger.kernel.org mailing list mirror (one of many)
 help / color / mirror / code / Atom feed
From: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
To: git@vger.kernel.org
Cc: Junio C Hamano <gitster@pobox.com>,
	Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
Subject: [PATCHv3 (resend) 2/4] git-am foreign patch support: autodetect some patch formats
Date: Tue,  2 Jun 2009 01:10:39 +0200	[thread overview]
Message-ID: <1243897841-8923-3-git-send-email-giuseppe.bilotta@gmail.com> (raw)
In-Reply-To: <1243897841-8923-2-git-send-email-giuseppe.bilotta@gmail.com>

Default to mbox format if input is from stdin. Otherwise, look at the
first few lines of the first patch to try to guess its format.

Include checks for mailboxes, stgit patch series, stgit single patches
and hg patches.
---
 git-am.sh |   40 +++++++++++++++++++++++++++++++++++++++-
 1 files changed, 39 insertions(+), 1 deletions(-)

diff --git a/git-am.sh b/git-am.sh
index da160de..8519701 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -142,7 +142,45 @@ check_patch_format () {
 	then
 		return 0
 	fi
-	patch_format=mbox
+
+	# we default to mbox format if input is from stdin and for
+	# directories
+	if test $# = 0 || test "x$1" = "x-" || test -d "$1"
+	then
+		patch_format=mbox
+		return 0
+	fi
+
+	# otherwise, check the first few lines of the first patch to try
+	# to detect its format
+	{
+		read l1
+		read l2
+		read l3
+		case "$l1" in
+		"From "*|"From: "*)
+			patch_format=mbox
+			;;
+		'# This series applies on GIT commit'*)
+			patch_format=stgit-series
+			;;
+		"# HG changeset patch")
+			patch_format=hg
+			;;
+		*)
+			# if the second line is empty and the third is
+			# a From, Author or Date entry, this is very
+			# likely an StGIT patch
+			case "$l2,$l3" in
+			,"From: "*|,"Author: "*|,"Date: "*)
+				patch_format=stgit
+				;;
+			*)
+				;;
+			esac
+			;;
+		esac
+	} < "$1"
 }
 
 split_patches () {
-- 
1.6.3.1.282.g9f93

  reply	other threads:[~2009-06-01 23:11 UTC|newest]

Thread overview: 7+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2009-06-01 23:10 [PATCHv3 (resend) 0/4] git-am foreign patch support Giuseppe Bilotta
2009-06-01 23:10 ` [PATCHv3 (resend) 1/4] git-am foreign patch support: introduce patch_format Giuseppe Bilotta
2009-06-01 23:10   ` Giuseppe Bilotta [this message]
2009-06-01 23:10     ` [PATCHv3 (resend) 3/4] git-am foreign patch support: StGIT support Giuseppe Bilotta
2009-06-01 23:10       ` [PATCHv3 (resend) 4/4] git-am: refactor 'cleaning up and aborting' Giuseppe Bilotta
2009-06-02 10:56 ` [PATCHv3 (resend) 0/4] git-am foreign patch support Nanako Shiraishi
2009-06-02 15:21   ` Junio C Hamano

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

  List information: http://vger.kernel.org/majordomo-info.html

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1243897841-8923-3-git-send-email-giuseppe.bilotta@gmail.com \
    --to=giuseppe.bilotta@gmail.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.
Code repositories for project(s) associated with this public inbox

	https://80x24.org/mirrors/git.git

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 read-only IMAP folder(s) and NNTP newsgroup(s).