stash: convert list to builtin
Add stash list to the helper and delete the list_stash function from the shell script. 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>
Paul-Sebastian Ungureanu committed
Feb 25, 2019 at 23:16 UTC
130f2697daf60f09a15884a4510b4fa0230eee98
2 files changed
+32
-6
builtin/stash--helper.c
+31
@@ -12,6 +12,7 @@
12
#include "rerere.h"
13
14
static const char * const git_stash_helper_usage[] = {
15
+ N_("git stash--helper list [<options>]"),
16
N_("git stash--helper drop [-q|--quiet] [<stash>]"),
17
N_("git stash--helper ( pop | apply ) [--index] [-q|--quiet] [<stash>]"),
18
N_("git stash--helper branch <branchname> [<stash>]"),
@@ -19,6 +20,11 @@ static const char * const git_stash_helper_usage[] = {
20
NULL
21
};
22
23
+static const char * const git_stash_helper_list_usage[] = {
24
+ N_("git stash--helper list [<options>]"),
25
+ NULL
26
+};
27
+
28
static const char * const git_stash_helper_drop_usage[] = {
29
N_("git stash--helper drop [-q|--quiet] [<stash>]"),
30
NULL
@@ -615,6 +621,29 @@ static int branch_stash(int argc, const char **argv, const char *prefix)
621
return ret;
622
}
623
624
+static int list_stash(int argc, const char **argv, const char *prefix)
625
+{
626
+ struct child_process cp = CHILD_PROCESS_INIT;
627
+ struct option options[] = {
628
+ OPT_END()
629
+ };
630
+
631
+ argc = parse_options(argc, argv, prefix, options,
632
+ git_stash_helper_list_usage,
633
+ PARSE_OPT_KEEP_UNKNOWN);
634
+
635
+ if (!ref_exists(ref_stash))
636
+ return 0;
637
+
638
+ cp.git_cmd = 1;
639
+ argv_array_pushl(&cp.args, "log", "--format=%gd: %gs", "-g",
640
+ "--first-parent", "-m", NULL);
641
+ argv_array_pushv(&cp.args, argv);
642
+ argv_array_push(&cp.args, ref_stash);
643
+ argv_array_push(&cp.args, "--");
644
+ return run_command(&cp);
645
+}
646
+
647
int cmd_stash__helper(int argc, const char **argv, const char *prefix)
648
{
649
pid_t pid = getpid();
@@ -645,6 +674,8 @@ int cmd_stash__helper(int argc, const char **argv, const char *prefix)
674
return !!pop_stash(argc, argv, prefix);
675
else if (!strcmp(argv[0], "branch"))
676
return !!branch_stash(argc, argv, prefix);
677
+ else if (!strcmp(argv[0], "list"))
678
+ return !!list_stash(argc, argv, prefix);
679
680
usage_msg_opt(xstrfmt(_("unknown subcommand: %s"), argv[0]),
681
git_stash_helper_usage, options);
git-stash.sh
+1
-6
@@ -399,11 +399,6 @@ have_stash () {
399
git rev-parse --verify --quiet $ref_stash >/dev/null
400
}
401
402
-list_stash () {
403
- have_stash || return 0
404
- git log --format="%gd: %gs" -g --first-parent -m "$@" $ref_stash --
405
-}
406
-
402
show_stash () {
403
ALLOW_UNKNOWN_FLAGS=t
404
assert_stash_like "$@"
@@ -591,7 +586,7 @@ test -n "$seen_non_option" || set "push" "$@"
586
case "$1" in
587
list)
588
shift
594
- list_stash "$@"
589
+ git stash--helper list "$@"
590
;;
591
show)
592
shift