@matheusbsbs / matheus-bagliano / commits / 15ced753ac
Fork 0

git-am foreign patch support: autodetect some patch formats

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. Signed-off-by: Junio C Hamano <gitster@pobox.com>

Giuseppe Bilotta committed May 27, 2009 at 23:20 UTC 15ced753ac091314941abb28302f7109a9e86b81
1 file changed +39 -1
git-am.sh
+39 -1
@@ -142,7 +142,45 @@ check_patch_format () {
142 then
143 return 0
144 fi
145 - patch_format=mbox
145 +
146 + # we default to mbox format if input is from stdin and for
147 + # directories
148 + if test $# = 0 || test "x$1" = "x-" || test -d "$1"
149 + then
150 + patch_format=mbox
151 + return 0
152 + fi
153 +
154 + # otherwise, check the first few lines of the first patch to try
155 + # to detect its format
156 + {
157 + read l1
158 + read l2
159 + read l3
160 + case "$l1" in
161 + "From "* | "From: "*)
162 + patch_format=mbox
163 + ;;
164 + '# This series applies on GIT commit'*)
165 + patch_format=stgit-series
166 + ;;
167 + "# HG changeset patch")
168 + patch_format=hg
169 + ;;
170 + *)
171 + # if the second line is empty and the third is
172 + # a From, Author or Date entry, this is very
173 + # likely an StGIT patch
174 + case "$l2,$l3" in
175 + ,"From: "* | ,"Author: "* | ,"Date: "*)
176 + patch_format=stgit
177 + ;;
178 + *)
179 + ;;
180 + esac
181 + ;;
182 + esac
183 + } < "$1"
184 }
185
186 split_patches () {