Skip to content

Commit 9c52972

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 <joel@teichroeb.net> Signed-off-by: Paul-Sebastian Ungureanu <ungureanupaulsebastian@gmail.com>
1 parent 684ee99 commit 9c52972

File tree

2 files changed

+40
-46
lines changed

2 files changed

+40
-46
lines changed

builtin/stash--helper.c

+38-1
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313

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

27+
static const char * const git_stash_helper_pop_usage[] = {
28+
N_("git stash--helper pop [--index] [-q|--quiet] [<stash>]"),
29+
NULL
30+
};
31+
2732
static const char * const git_stash_helper_apply_usage[] = {
2833
N_("git stash--helper apply [--index] [-q|--quiet] [<stash>]"),
2934
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

+2-45
Original file line numberDiff line numberDiff line change
@@ -554,50 +554,6 @@ assert_stash_like() {
554554
}
555555
}
556556

557-
is_stash_ref() {
558-
is_stash_like "$@" && test -n "$IS_STASH_REF"
559-
}
560-
561-
assert_stash_ref() {
562-
is_stash_ref "$@" || {
563-
args="$*"
564-
die "$(eval_gettext "'\$args' is not a stash reference")"
565-
}
566-
}
567-
568-
apply_stash () {
569-
cd "$START_DIR"
570-
git stash--helper apply "$@"
571-
res=$?
572-
cd_to_toplevel
573-
return $res
574-
}
575-
576-
pop_stash() {
577-
assert_stash_ref "$@"
578-
579-
if apply_stash "$@"
580-
then
581-
drop_stash "$@"
582-
else
583-
status=$?
584-
say "$(gettext "The stash entry is kept in case you need it again.")"
585-
exit $status
586-
fi
587-
}
588-
589-
drop_stash () {
590-
assert_stash_ref "$@"
591-
592-
git reflog delete --updateref --rewrite "${REV}" &&
593-
say "$(eval_gettext "Dropped \${REV} (\$s)")" ||
594-
die "$(eval_gettext "\${REV}: Could not drop stash entry")"
595-
596-
# clear_stash if we just dropped the last stash entry
597-
git rev-parse --verify --quiet "$ref_stash@{0}" >/dev/null ||
598-
clear_stash
599-
}
600-
601557
test "$1" = "-p" && set "push" "$@"
602558

603559
PARSE_CACHE='--not-parsed'
@@ -655,7 +611,8 @@ drop)
655611
;;
656612
pop)
657613
shift
658-
pop_stash "$@"
614+
cd "$START_DIR"
615+
git stash--helper pop "$@"
659616
;;
660617
branch)
661618
shift

0 commit comments

Comments
 (0)