Skip to content

Commit a5a6755

Browse files
Oblomovgitster
authored andcommitted
git-am foreign patch support: introduce patch_format
Set up a framework to allow git-am to support patches which are not in mailbox format. Introduce a patch_format variable that presently can only be set from the command line, defaulting to 'mbox' (the only supported format) if not specified. Signed-off-by: Junio C Hamano <[email protected]>
1 parent 33fd716 commit a5a6755

File tree

1 file changed

+33
-4
lines changed

1 file changed

+33
-4
lines changed

git-am.sh

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ whitespace= pass it through git-apply
1818
directory= pass it through git-apply
1919
C= pass it through git-apply
2020
p= pass it through git-apply
21+
patch-format= format the patch(es) are in
2122
reject pass it through git-apply
2223
resolvemsg= override error message when patch failure occurs
2324
r,resolved to be used after a patch failure
@@ -133,6 +134,32 @@ It does not apply to blobs recorded in its index."
133134
unset GITHEAD_$his_tree
134135
}
135136

137+
patch_format=
138+
139+
check_patch_format () {
140+
# early return if patch_format was set from the command line
141+
if test -n "$patch_format"
142+
then
143+
return 0
144+
fi
145+
patch_format=mbox
146+
}
147+
148+
split_patches () {
149+
case "$patch_format" in
150+
mbox)
151+
git mailsplit -d"$prec" -o"$dotest" -b -- "$@" > "$dotest/last" || {
152+
rm -fr "$dotest"
153+
exit 1
154+
}
155+
;;
156+
*)
157+
echo "Patch format $patch_format is not supported."
158+
exit 1
159+
;;
160+
esac
161+
}
162+
136163
prec=4
137164
dotest="$GIT_DIR/rebase-apply"
138165
sign= utf8=t keep= skip= interactive= resolved= rebasing= abort=
@@ -175,6 +202,8 @@ do
175202
git_apply_opt="$git_apply_opt $(sq "$1=$2")"; shift ;;
176203
-C|-p)
177204
git_apply_opt="$git_apply_opt $(sq "$1$2")"; shift ;;
205+
--patch-format)
206+
shift ; patch_format="$1" ;;
178207
--reject)
179208
git_apply_opt="$git_apply_opt $1" ;;
180209
--committer-date-is-author-date)
@@ -274,10 +303,10 @@ else
274303
done
275304
shift
276305
fi
277-
git mailsplit -d"$prec" -o"$dotest" -b -- "$@" > "$dotest/last" || {
278-
rm -fr "$dotest"
279-
exit 1
280-
}
306+
307+
check_patch_format "$@"
308+
309+
split_patches "$@"
281310

282311
# -s, -u, -k, --whitespace, -3, -C and -p flags are kept
283312
# for the resuming session after a patch failure.

0 commit comments

Comments
 (0)