Skip to content

Commit 064ed10

Browse files
jonseymourgitster
authored andcommitted
detached-stash: simplify stash_apply
The implementation of stash_apply() is simplified to take advantage of the common parsing function parse_flags_and_rev(). Signed-off-by: Jon Seymour <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent b0f0ecd commit 064ed10

File tree

1 file changed

+3
-35
lines changed

1 file changed

+3
-35
lines changed

git-stash.sh

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -358,40 +358,8 @@ assert_stash_ref() {
358358
}
359359

360360
apply_stash () {
361-
applied_stash=
362-
unstash_index=
363361

364-
while test $# != 0
365-
do
366-
case "$1" in
367-
--index)
368-
unstash_index=t
369-
;;
370-
-q|--quiet)
371-
GIT_QUIET=t
372-
;;
373-
*)
374-
break
375-
;;
376-
esac
377-
shift
378-
done
379-
380-
if test $# = 0
381-
then
382-
have_stash || die 'Nothing to apply'
383-
applied_stash="$ref_stash@{0}"
384-
else
385-
applied_stash="$*"
386-
fi
387-
388-
# stash records the work tree, and is a merge between the
389-
# base commit (first parent) and the index tree (second parent).
390-
s=$(git rev-parse --quiet --verify --default $ref_stash "$@") &&
391-
w_tree=$(git rev-parse --quiet --verify "$s:") &&
392-
b_tree=$(git rev-parse --quiet --verify "$s^1:") &&
393-
i_tree=$(git rev-parse --quiet --verify "$s^2:") ||
394-
die "$*: no valid stashed state found"
362+
assert_stash_like "$@"
395363

396364
git update-index -q --refresh &&
397365
git diff-files --quiet --ignore-submodules ||
@@ -402,7 +370,7 @@ apply_stash () {
402370
die 'Cannot apply a stash in the middle of a merge'
403371

404372
unstashed_index_tree=
405-
if test -n "$unstash_index" && test "$b_tree" != "$i_tree" &&
373+
if test -n "$INDEX_OPTION" && test "$b_tree" != "$i_tree" &&
406374
test "$c_tree" != "$i_tree"
407375
then
408376
git diff-tree --binary $s^2^..$s^2 | git apply --cached
@@ -447,7 +415,7 @@ apply_stash () {
447415
else
448416
# Merge conflict; keep the exit status from merge-recursive
449417
status=$?
450-
if test -n "$unstash_index"
418+
if test -n "$INDEX_OPTION"
451419
then
452420
echo >&2 'Index was not unstashed.'
453421
fi

0 commit comments

Comments
 (0)