Skip to content

Commit c85d792

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: Thomas Gummerer <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 6fe783f commit c85d792

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
@@ -543,6 +548,36 @@ static int drop_stash(int argc, const char **argv, const char *prefix)
543548
return ret;
544549
}
545550

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

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)