Skip to content

Commit c4de61d

Browse files
klusarkgitster
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 577c199 commit c4de61d

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

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

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)