@matheusbsbs / matheus-bagliano / commits / 064ed100b2
Fork 0

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

Jon Seymour committed Aug 21, 2010 at 14:08 UTC 064ed100b2b3530c4b8c4534aa663d2455b735da
1 file changed +3 -35
git-stash.sh
+3 -35
@@ -358,40 +358,8 @@ assert_stash_ref() {
358 }
359
360 apply_stash () {
361 - applied_stash=
362 - unstash_index=
361
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 "$@"
363
364 git update-index -q --refresh &&
365 git diff-files --quiet --ignore-submodules ||
@@ -402,7 +370,7 @@ apply_stash () {
370 die 'Cannot apply a stash in the middle of a merge'
371
372 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" &&
374 test "$c_tree" != "$i_tree"
375 then
376 git diff-tree --binary $s^2^..$s^2 | git apply --cached
@@ -447,7 +415,7 @@ apply_stash () {
415 else
416 # Merge conflict; keep the exit status from merge-recursive
417 status=$?
450 - if test -n "$unstash_index"
418 + if test -n "$INDEX_OPTION"
419 then
420 echo >&2 'Index was not unstashed.'
421 fi