#
# Copyright (c) 2005, 2006 Junio C Hamano
-USAGE='[--signoff] [--dotest=<dir>] [--utf8] [--binary] [--3way]
- [--interactive] [--whitespace=<option>] <mbox>...
+USAGE='[--signoff] [--dotest=<dir>] [--utf8 | --no-utf8] [--binary] [--3way]
+ [--interactive] [--whitespace=<option>] [-C<n>] [-p<n>] <mbox>...
or, when resuming [--skip | --resolved]'
. git-sh-setup
+set_reflog_action am
+require_work_tree
git var GIT_COMMITTER_IDENT >/dev/null || exit
stop_here_user_resolve () {
if [ -n "$resolvemsg" ]; then
- echo "$resolvemsg"
+ printf '%s\n' "$resolvemsg"
stop_here $1
fi
cmdline=$(basename $0)
mkdir "$dotest/patch-merge-tmp-dir"
# First see if the patch records the index info that we can use.
- git-apply -z --index-info "$dotest/patch" \
+ git apply -z --index-info "$dotest/patch" \
>"$dotest/patch-merge-index-info" &&
GIT_INDEX_FILE="$dotest/patch-merge-tmp-index" \
- git-update-index -z --index-info <"$dotest/patch-merge-index-info" &&
+ git update-index -z --index-info <"$dotest/patch-merge-index-info" &&
GIT_INDEX_FILE="$dotest/patch-merge-tmp-index" \
- git-write-tree >"$dotest/patch-merge-base+" ||
- cannot_fallback "Patch does not record usable index information."
+ git write-tree >"$dotest/patch-merge-base+" ||
+ cannot_fallback "Repository lacks necessary blobs to fall back on 3-way merge."
echo Using index info to reconstruct a base tree...
if GIT_INDEX_FILE="$dotest/patch-merge-tmp-index" \
- git-apply $binary --cached <"$dotest/patch"
+ git apply $binary --cached <"$dotest/patch"
then
mv "$dotest/patch-merge-base+" "$dotest/patch-merge-base"
mv "$dotest/patch-merge-tmp-index" "$dotest/patch-merge-index"
fi
test -f "$dotest/patch-merge-index" &&
- his_tree=$(GIT_INDEX_FILE="$dotest/patch-merge-index" git-write-tree) &&
+ his_tree=$(GIT_INDEX_FILE="$dotest/patch-merge-index" git write-tree) &&
orig_tree=$(cat "$dotest/patch-merge-base") &&
rm -fr "$dotest"/patch-merge-* || exit 1
# This is not so wrong. Depending on which base we picked,
# orig_tree may be wildly different from ours, but his_tree
# has the same set of wildly different changes in parts the
- # patch did not touch, so resolve ends up canceling them,
+ # patch did not touch, so recursive ends up canceling them,
# saying that we reverted all those changes.
- git-merge-resolve $orig_tree -- HEAD $his_tree || {
- if test -d "$GIT_DIR/rr-cache"
- then
- git-rerere
- fi
+ eval GITHEAD_$his_tree='"$SUBJECT"'
+ export GITHEAD_$his_tree
+ git-merge-recursive $orig_tree -- HEAD $his_tree || {
+ git rerere
echo Failed to merge in the changes.
exit 1
}
+ unset GITHEAD_$his_tree
}
prec=4
-rloga=am
-dotest=.dotest sign= utf8= keep= skip= interactive= resolved= binary= ws= resolvemsg=
+dotest=.dotest sign= utf8=t keep= skip= interactive= resolved= binary= resolvemsg=
+git_apply_opt=
while case "$#" in 0) break;; esac
do
-s|--s|--si|--sig|--sign|--signo|--signof|--signoff)
sign=t; shift ;;
-u|--u|--ut|--utf|--utf8)
- utf8=t; shift ;;
+ utf8=t; shift ;; # this is now default
+ --no-u|--no-ut|--no-utf|--no-utf8)
+ utf8=; shift ;;
-k|--k|--ke|--kee|--keep)
keep=t; shift ;;
--sk|--ski|--skip)
skip=t; shift ;;
- --whitespace=*)
- ws=$1; shift ;;
+ --whitespace=*|-C*|-p*)
+ git_apply_opt="$git_apply_opt $1"; shift ;;
--resolvemsg=*)
- resolvemsg=$(echo "$1" | sed -e "s/^--resolvemsg=//"); shift ;;
-
- --reflog-action=*)
- rloga=`expr "z$1" : 'z-[^=]*=\(.*\)'`; shift ;;
+ resolvemsg=${1#--resolvemsg=}; shift ;;
--)
shift; break ;;
# Start afresh.
mkdir -p "$dotest" || exit
- git-mailsplit -d"$prec" -o"$dotest" -b -- "$@" > "$dotest/last" || {
+ git mailsplit -d"$prec" -o"$dotest" -b -- "$@" > "$dotest/last" || {
rm -fr "$dotest"
exit 1
}
case "$resolved" in
'')
- files=$(git-diff-index --cached --name-only HEAD) || exit
+ files=$(git diff-index --cached --name-only HEAD) || exit
if [ "$files" ]; then
echo "Dirty index: cannot apply patches (dirty: $files)" >&2
exit 1
if test "$(cat "$dotest/utf8")" = t
then
utf8=-u
+else
+ utf8=-n
fi
if test "$(cat "$dotest/keep")" = t
then
this=`cat "$dotest/next"`
if test "$skip" = t
then
- if test -d "$GIT_DIR/rr-cache"
- then
- git-rerere clear
- fi
+ git rerere clear
this=`expr "$this" + 1`
resume=
fi
# by the user, or the user can tell us to do so by --resolved flag.
case "$resume" in
'')
- git-mailinfo $keep $utf8 "$dotest/msg" "$dotest/patch" \
+ git mailinfo $keep $utf8 "$dotest/msg" "$dotest/patch" \
<"$dotest/$msgnum" >"$dotest/info" ||
stop_here $this
- git-stripspace < "$dotest/msg" > "$dotest/msg-clean"
+
+ # skip pine's internal folder data
+ grep '^Author: Mail System Internal Data$' \
+ <"$dotest"/info >/dev/null &&
+ go_next && continue
+
+ test -s $dotest/patch || {
+ echo "Patch is empty. Was it split wrong?"
+ stop_here $this
+ }
+ git stripspace < "$dotest/msg" > "$dotest/msg-clean"
;;
esac
ADD_SIGNOFF=
fi
{
- echo "$SUBJECT"
+ printf '%s\n' "$SUBJECT"
if test -s "$dotest/msg-clean"
then
echo
case "$resolved$interactive" in
tt)
# This is used only for interactive view option.
- git-diff-index -p --cached HEAD >"$dotest/patch"
+ git diff-index -p --cached HEAD >"$dotest/patch"
;;
esac
esac
[yY]*) action=yes ;;
[aA]*) action=yes interactive= ;;
[nN]*) action=skip ;;
- [eE]*) "${VISUAL:-${EDITOR:-vi}}" "$dotest/final-commit"
+ [eE]*) git_editor "$dotest/final-commit"
action=again ;;
[vV]*) action=again
LESS=-S ${PAGER:-less} "$dotest/patch" ;;
fi
echo
- echo "Applying '$SUBJECT'"
+ printf 'Applying %s\n' "$SUBJECT"
echo
case "$resolved" in
'')
- git-apply $binary --index $ws "$dotest/patch"
+ git apply $git_apply_opt $binary --index "$dotest/patch"
apply_status=$?
;;
t)
# trust what the user has in the index file and the
# working tree.
resolved=
- changed="$(git-diff-index --cached --name-only HEAD)"
- if test '' = "$changed"
- then
- echo "No changes - did you forget update-index?"
+ git diff-index --quiet --cached HEAD && {
+ echo "No changes - did you forget to use 'git add'?"
stop_here_user_resolve $this
- fi
- unmerged=$(git-ls-files -u)
+ }
+ unmerged=$(git ls-files -u)
if test -n "$unmerged"
then
echo "You still have unmerged paths in your index"
- echo "did you forget update-index?"
+ echo "did you forget to use 'git add'?"
stop_here_user_resolve $this
fi
apply_status=0
- if test -d "$GIT_DIR/rr-cache"
- then
- git rerere
- fi
+ git rerere
;;
esac
then
# Applying the patch to an earlier tree and merging the
# result may have produced the same tree as ours.
- changed="$(git-diff-index --cached --name-only HEAD)"
- if test '' = "$changed"
- then
- echo No changes -- Patch already applied.
- go_next
- continue
- fi
+ git diff-index --quiet --cached HEAD && {
+ echo No changes -- Patch already applied.
+ go_next
+ continue
+ }
# clear apply_status -- we have successfully merged.
apply_status=0
fi
"$GIT_DIR"/hooks/pre-applypatch || stop_here $this
fi
- tree=$(git-write-tree) &&
+ tree=$(git write-tree) &&
echo Wrote tree $tree &&
- parent=$(git-rev-parse --verify HEAD) &&
- commit=$(git-commit-tree $tree -p $parent <"$dotest/final-commit") &&
+ parent=$(git rev-parse --verify HEAD) &&
+ commit=$(git commit-tree $tree -p $parent <"$dotest/final-commit") &&
echo Committed: $commit &&
- git-update-ref -m "$rloga: $SUBJECT" HEAD $commit $parent ||
+ git update-ref -m "$GIT_REFLOG_ACTION: $SUBJECT" HEAD $commit $parent ||
stop_here $this
if test -x "$GIT_DIR"/hooks/post-applypatch