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: [PATCH 1/2] git-am foreign patch support: format autodetection
Date: Mon, 25 May 2009 21:14:05 +0200 [thread overview]
Message-ID: <1243278846-14120-2-git-send-email-giuseppe.bilotta@gmail.com> (raw)
In-Reply-To: <1243278846-14120-1-git-send-email-giuseppe.bilotta@gmail.com>
This patch is the first step towards the introduction of a framework to
allow git-am to import patches not in mailbox format.
Currently detected formats are
* the mailbox format itself, which is assumed by default if input is
form stdin
* Mercurial's output from 'hg export'
* Stacked Git's output from 'stg export' with the default export
template; StGIT patch series are also detected and expanded.
Signed-off-by: Giuseppe Bilotta <giuseppe.bilotta@gmail.com>
---
git-am.sh | 108 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--
1 files changed, 105 insertions(+), 3 deletions(-)
diff --git a/git-am.sh b/git-am.sh
index 578780b..3508b7e 100755
--- a/git-am.sh
+++ b/git-am.sh
@@ -274,10 +274,112 @@ else
done
shift
fi
- git mailsplit -d"$prec" -o"$dotest" -b -- "$@" > "$dotest/last" || {
- rm -fr "$dotest"
+
+ # format of the patch(es) to be processed. we assume they are all
+ # of the same kind
+ patch_format=none
+
+ # from stdin we only accept mboxes, because peeking at stdin
+ # to detect the format is destructive
+ case $# in
+ 0)
+ patch_format=mbox
+ ;;
+ 1)
+ if test x"$1" = x"-"
+ then
+ # stdin, so assume mbox
+ patch_format=mbox
+ else
+# a single non-stdin argument was passed, check if it's a StGit patch series
+# index by checking if the first line begins with '# This series'
+ {
+ read l1
+ case "$l1" in
+ '# This series '*)
+# replace the argument list with the files listed in the series index,
+# prefixing them with the series index dirname, skipping comment lines
+ series_dir=`dirname "$1"`
+ while read filename
+ do
+ set "$@" "$series_dir/$filename"
+ done
+ # remove the series index name
+ shift
+ # set the patch format appropriately
+ patch_format=stgit
+ ;;
+ *)
+ ;;
+ esac
+ } < "$1"
+ fi
+ ;;
+ *)
+ ;;
+ esac
+
+ # if the format is not defined yet, we can look at the first patch
+ # (which is not stdin) to try to understand the format.
+ if test $patch_format = none
+ then
+ echo "$patch_format"
+ # if it's a directory, assume mbox format
+ # TODO we could suppot StGIT patch series here too
+ if test -d "$1"
+ then
+ patch_format=mbox
+ else
+ # read the first four lines
+ {
+ read l1
+ read l2
+ read l3
+ read l4
+ } < "$1"
+ case "$l1" in
+ "# HG changeset patch")
+ patch_format=hg
+ ;;
+ From\ *)
+ patch_format=mbox
+ ;;
+ From:\ *)
+ patch_format=mbox
+ ;;
+ *)
+ # if the second and fourth lines are empty,
+ # this might be an StGIT patch
+ if test x"$l2$l4" = x
+ then
+ case "$l3" in
+ From:\ *)
+ patch_format=stgit
+ ;;
+ Author:\ *)
+ patch_format=stgit
+ ;;
+ *)
+ ;;
+ esac
+ fi
+ ;;
+ esac
+ fi
+ fi
+
+ case "$patch_format" in
+ mbox)
+ git mailsplit -d"$prec" -o"$dotest" -b -- "$@" > "$dotest/last" || {
+ rm -fr "$dotest"
+ exit 1
+ }
+ ;;
+ *)
+ echo "Patch format $patch_format is not currently handled, sorry"
exit 1
- }
+ ;;
+ esac
# -s, -u, -k, --whitespace, -3, -C and -p flags are kept
# for the resuming session after a patch failure.
--
1.6.3.1.245.g4529.dirty
next prev parent reply other threads:[~2009-05-25 19:14 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2009-05-25 19:14 [PATCH 0/2] git-am foreign patch support Giuseppe Bilotta
2009-05-25 19:14 ` Giuseppe Bilotta [this message]
2009-05-25 19:14 ` [PATCH 2/2] git-am foreign patch support: StGIT Giuseppe Bilotta
2009-05-25 22:23 ` [PATCH 1/2] git-am foreign patch support: format autodetection Junio C Hamano
2009-05-25 22:49 ` Giuseppe Bilotta
2009-05-25 19:19 ` [PATCH 0/2] git-am foreign patch support Sverre Rabbelier
2009-05-25 19:24 ` Giuseppe Bilotta
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=1243278846-14120-2-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.
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).