Skip to content

Commit 130f269

Browse files
ungpsgitster
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 c4de61d commit 130f269

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
@@ -12,13 +12,19 @@
1212
#include "rerere.h"
1313

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

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

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+
618647
int cmd_stash__helper(int argc, const char **argv, const char *prefix)
619648
{
620649
pid_t pid = getpid();
@@ -645,6 +674,8 @@ int cmd_stash__helper(int argc, const char **argv, const char *prefix)
645674
return !!pop_stash(argc, argv, prefix);
646675
else if (!strcmp(argv[0], "branch"))
647676
return !!branch_stash(argc, argv, prefix);
677+
else if (!strcmp(argv[0], "list"))
678+
return !!list_stash(argc, argv, prefix);
648679

649680
usage_msg_opt(xstrfmt(_("unknown subcommand: %s"), argv[0]),
650681
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)