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> Signed-off-by: Thomas Gummerer <t.gummerer@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Joel Teichroeb committed
Feb 25, 2019 at 23:16 UTC
c4de61d7a95ebb7197191bc51475d19068b6d526
2 files changed
+40
-46
builtin/stash--helper.c
+38
-1
@@ -13,7 +13,7 @@
13
14
static const char * const git_stash_helper_usage[] = {
15
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>]"),
17
N_("git stash--helper branch <branchname> [<stash>]"),
18
N_("git stash--helper clear"),
19
NULL
@@ -24,6 +24,11 @@ static const char * const git_stash_helper_drop_usage[] = {
24
NULL
25
};
26
27
+static const char * const git_stash_helper_pop_usage[] = {
28
+ N_("git stash--helper pop [--index] [-q|--quiet] [<stash>]"),
29
+ NULL
30
+};
31
+
32
static const char * const git_stash_helper_apply_usage[] = {
33
N_("git stash--helper apply [--index] [-q|--quiet] [<stash>]"),
34
NULL
@@ -542,6 +547,36 @@ static int drop_stash(int argc, const char **argv, const char *prefix)
547
return ret;
548
}
549
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
+
580
static int branch_stash(int argc, const char **argv, const char *prefix)
581
{
582
int ret;
@@ -606,6 +641,8 @@ int cmd_stash__helper(int argc, const char **argv, const char *prefix)
641
return !!clear_stash(argc, argv, prefix);
642
else if (!strcmp(argv[0], "drop"))
643
return !!drop_stash(argc, argv, prefix);
644
+ else if (!strcmp(argv[0], "pop"))
645
+ return !!pop_stash(argc, argv, prefix);
646
else if (!strcmp(argv[0], "branch"))
647
return !!branch_stash(argc, argv, prefix);
648
git-stash.sh
+2
-45
@@ -571,50 +571,6 @@ assert_stash_like() {
571
}
572
}
573
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
-
574
test "$1" = "-p" && set "push" "$@"
575
576
PARSE_CACHE='--not-parsed'
@@ -672,7 +628,8 @@ drop)
628
;;
629
pop)
630
shift
675
- pop_stash "$@"
631
+ cd "$START_DIR"
632
+ git stash--helper pop "$@"
633
;;
634
branch)
635
shift