Skip to content

Commit 990f3d5

Browse files
klusarkdscho
authored andcommitted
stash: convert pop to builtin
Add stash pop to the helper and delete the pop_stash, drop_stash, assert_stash_ref functions from the shell script now that they are no longer needed. Signed-off-by: Joel Teichroeb <[email protected]> Signed-off-by: Paul-Sebastian Ungureanu <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 9384306 commit 990f3d5

File tree

2 files changed

+40
-46
lines changed

2 files changed

+40
-46
lines changed

builtin/stash--helper.c

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414

1515
static const char * const git_stash_helper_usage[] = {
1616
N_("git stash--helper drop [-q|--quiet] [<stash>]"),
17-
N_("git stash--helper apply [--index] [-q|--quiet] [<stash>]"),
17+
N_("git stash--helper ( pop | apply ) [--index] [-q|--quiet] [<stash>]"),
1818
N_("git stash--helper branch <branchname> [<stash>]"),
1919
N_("git stash--helper clear"),
2020
NULL
@@ -25,6 +25,11 @@ static const char * const git_stash_helper_drop_usage[] = {
2525
NULL
2626
};
2727

28+
static const char * const git_stash_helper_pop_usage[] = {
29+
N_("git stash--helper pop [--index] [-q|--quiet] [<stash>]"),
30+
NULL
31+
};
32+
2833
static const char * const git_stash_helper_apply_usage[] = {
2934
N_("git stash--helper apply [--index] [-q|--quiet] [<stash>]"),
3035
NULL
@@ -544,6 +549,36 @@ static int drop_stash(int argc, const char **argv, const char *prefix)
544549
return ret;
545550
}
546551

552+
static int pop_stash(int argc, const char **argv, const char *prefix)
553+
{
554+
int ret;
555+
int index = 0;
556+
int quiet = 0;
557+
struct stash_info info;
558+
struct option options[] = {
559+
OPT__QUIET(&quiet, N_("be quiet, only report errors")),
560+
OPT_BOOL(0, "index", &index,
561+
N_("attempt to recreate the index")),
562+
OPT_END()
563+
};
564+
565+
argc = parse_options(argc, argv, prefix, options,
566+
git_stash_helper_pop_usage, 0);
567+
568+
if (get_stash_info(&info, argc, argv))
569+
return -1;
570+
571+
assert_stash_ref(&info);
572+
if ((ret = do_apply_stash(prefix, &info, index, quiet)))
573+
printf_ln(_("The stash entry is kept in case "
574+
"you need it again."));
575+
else
576+
ret = do_drop_stash(prefix, &info, quiet);
577+
578+
free_stash_info(&info);
579+
return ret;
580+
}
581+
547582
static int branch_stash(int argc, const char **argv, const char *prefix)
548583
{
549584
int ret;
@@ -608,6 +643,8 @@ int cmd_stash__helper(int argc, const char **argv, const char *prefix)
608643
return !!clear_stash(argc, argv, prefix);
609644
else if (!strcmp(argv[0], "drop"))
610645
return !!drop_stash(argc, argv, prefix);
646+
else if (!strcmp(argv[0], "pop"))
647+
return !!pop_stash(argc, argv, prefix);
611648
else if (!strcmp(argv[0], "branch"))
612649
return !!branch_stash(argc, argv, prefix);
613650

git-stash.sh

Lines changed: 2 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -571,50 +571,6 @@ assert_stash_like() {
571571
}
572572
}
573573

574-
is_stash_ref() {
575-
is_stash_like "$@" && test -n "$IS_STASH_REF"
576-
}
577-
578-
assert_stash_ref() {
579-
is_stash_ref "$@" || {
580-
args="$*"
581-
die "$(eval_gettext "'\$args' is not a stash reference")"
582-
}
583-
}
584-
585-
apply_stash () {
586-
cd "$START_DIR"
587-
git stash--helper apply "$@"
588-
res=$?
589-
cd_to_toplevel
590-
return $res
591-
}
592-
593-
pop_stash() {
594-
assert_stash_ref "$@"
595-
596-
if apply_stash "$@"
597-
then
598-
drop_stash "$@"
599-
else
600-
status=$?
601-
say "$(gettext "The stash entry is kept in case you need it again.")"
602-
exit $status
603-
fi
604-
}
605-
606-
drop_stash () {
607-
assert_stash_ref "$@"
608-
609-
git reflog delete --updateref --rewrite "${REV}" &&
610-
say "$(eval_gettext "Dropped \${REV} (\$s)")" ||
611-
die "$(eval_gettext "\${REV}: Could not drop stash entry")"
612-
613-
# clear_stash if we just dropped the last stash entry
614-
git rev-parse --verify --quiet "$ref_stash@{0}" >/dev/null ||
615-
clear_stash
616-
}
617-
618574
test "$1" = "-p" && set "push" "$@"
619575

620576
PARSE_CACHE='--not-parsed'
@@ -672,7 +628,8 @@ drop)
672628
;;
673629
pop)
674630
shift
675-
pop_stash "$@"
631+
cd "$START_DIR"
632+
git stash--helper pop "$@"
676633
;;
677634
branch)
678635
shift

0 commit comments

Comments
 (0)