applypatch: use "index" lines not "applies-to".
This matches the 3-way fallback used by applypatch to use per-blob "index" lines, not "applies-to" tree object name, to match what git-am does. Signed-off-by: Junio C Hamano <junkio@cox.net>
Junio C Hamano committed
Nov 29, 2005 at 13:53 UTC
bf3e274873e56d7df25d60800c8d59a309e0d8c6
1 file changed
+24
-13
git-applypatch.sh
+24
-13
@@ -120,26 +120,36 @@ git-apply --index "$PATCHFILE" || {
120
O_OBJECT=`cd "$GIT_OBJECT_DIRECTORY" && pwd`
121
rm -fr .patch-merge-*
122
123
+ if git-apply -z --index-info "$PATCHFILE" \
124
+ >.patch-merge-index-info 2>/dev/null &&
125
+ GIT_INDEX_FILE=.patch-merge-tmp-index \
126
+ git-update-index -z --index-info <.patch-merge-index-info &&
127
+ GIT_INDEX_FILE=.patch-merge-tmp-index \
128
+ git-write-tree >.patch-merge-tmp-base &&
129
+ (
130
+ mkdir .patch-merge-tmp-dir &&
131
+ cd .patch-merge-tmp-dir &&
132
+ GIT_INDEX_FILE="../.patch-merge-tmp-index" \
133
+ GIT_OBJECT_DIRECTORY="$O_OBJECT" \
134
+ git-apply $binary --index
135
+ ) <"$PATCHFILE"
136
+ then
137
+ echo Using index info to reconstruct a base tree...
138
+ mv .patch-merge-tmp-base .patch-merge-base
139
+ mv .patch-merge-tmp-index .patch-merge-index
140
+ else
141
(
142
N=10
143
126
- # if the patch records the base tree...
127
- sed -ne '
128
- /^diff /q
129
- /^applies-to: \([0-9a-f]*\)$/{
130
- s//\1/p
131
- q
132
- }
133
- ' "$PATCHFILE"
134
-
135
- # or hoping the patch is against our recent commits...
144
+ # Otherwise, try nearby trees that can be used to apply the
145
+ # patch.
146
git-rev-list --max-count=$N HEAD
147
148
# or hoping the patch is against known tags...
149
git-ls-remote --tags .
150
) |
141
- while read base junk
142
- do
151
+ while read base junk
152
+ do
153
# Try it if we have it as a tree.
154
git-cat-file tree "$base" >/dev/null 2>&1 || continue
155
@@ -155,7 +165,8 @@ git-apply --index "$PATCHFILE" || {
165
mv ../.patch-merge-tmp-index ../.patch-merge-index &&
166
echo "$base" >../.patch-merge-base
167
) <"$PATCHFILE" 2>/dev/null && break
158
- done
168
+ done
169
+ fi
170
171
test -f .patch-merge-index &&
172
his_tree=$(GIT_INDEX_FILE=.patch-merge-index git-write-tree) &&