Skip to content

Commit 1e3b9c2

Browse files
ungpsdscho
authored andcommitted
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 <[email protected]> Signed-off-by: Thomas Gummerer <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent c85d792 commit 1e3b9c2

File tree

2 files changed

+32
-6
lines changed

2 files changed

+32
-6
lines changed

builtin/stash--helper.c

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,13 +13,19 @@
1313
#include "rerere.h"
1414

1515
static const char * const git_stash_helper_usage[] = {
16+
N_("git stash--helper list [<options>]"),
1617
N_("git stash--helper drop [-q|--quiet] [<stash>]"),
1718
N_("git stash--helper ( pop | apply ) [--index] [-q|--quiet] [<stash>]"),
1819
N_("git stash--helper branch <branchname> [<stash>]"),
1920
N_("git stash--helper clear"),
2021
NULL
2122
};
2223

24+
static const char * const git_stash_helper_list_usage[] = {
25+
N_("git stash--helper list [<options>]"),
26+
NULL
27+
};
28+
2329
static const char * const git_stash_helper_drop_usage[] = {
2430
N_("git stash--helper drop [-q|--quiet] [<stash>]"),
2531
NULL
@@ -616,6 +622,29 @@ static int branch_stash(int argc, const char **argv, const char *prefix)
616622
return ret;
617623
}
618624

625+
static int list_stash(int argc, const char **argv, const char *prefix)
626+
{
627+
struct child_process cp = CHILD_PROCESS_INIT;
628+
struct option options[] = {
629+
OPT_END()
630+
};
631+
632+
argc = parse_options(argc, argv, prefix, options,
633+
git_stash_helper_list_usage,
634+
PARSE_OPT_KEEP_UNKNOWN);
635+
636+
if (!ref_exists(ref_stash))
637+
return 0;
638+
639+
cp.git_cmd = 1;
640+
argv_array_pushl(&cp.args, "log", "--format=%gd: %gs", "-g",
641+
"--first-parent", "-m", NULL);
642+
argv_array_pushv(&cp.args, argv);
643+
argv_array_push(&cp.args, ref_stash);
644+
argv_array_push(&cp.args, "--");
645+
return run_command(&cp);
646+
}
647+
619648
int cmd_stash__helper(int argc, const char **argv, const char *prefix)
620649
{
621650
pid_t pid = getpid();
@@ -646,6 +675,8 @@ int cmd_stash__helper(int argc, const char **argv, const char *prefix)
646675
return !!pop_stash(argc, argv, prefix);
647676
else if (!strcmp(argv[0], "branch"))
648677
return !!branch_stash(argc, argv, prefix);
678+
else if (!strcmp(argv[0], "list"))
679+
return !!list_stash(argc, argv, prefix);
649680

650681
usage_msg_opt(xstrfmt(_("unknown subcommand: %s"), argv[0]),
651682
git_stash_helper_usage, options);

git-stash.sh

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -399,11 +399,6 @@ have_stash () {
399399
git rev-parse --verify --quiet $ref_stash >/dev/null
400400
}
401401

402-
list_stash () {
403-
have_stash || return 0
404-
git log --format="%gd: %gs" -g --first-parent -m "$@" $ref_stash --
405-
}
406-
407402
show_stash () {
408403
ALLOW_UNKNOWN_FLAGS=t
409404
assert_stash_like "$@"
@@ -591,7 +586,7 @@ test -n "$seen_non_option" || set "push" "$@"
591586
case "$1" in
592587
list)
593588
shift
594-
list_stash "$@"
589+
git stash--helper list "$@"
595590
;;
596591
show)
597592
shift

0 commit comments

Comments
 (0)