Skip to content

Commit

Permalink
stash: convert list to builtin
Browse files Browse the repository at this point in the history
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>
  • Loading branch information
ungps authored and gitster committed Mar 7, 2019
1 parent c4de61d commit 130f269
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 6 deletions.
31 changes: 31 additions & 0 deletions builtin/stash--helper.c
Expand Up @@ -12,13 +12,19 @@
#include "rerere.h"

static const char * const git_stash_helper_usage[] = {
N_("git stash--helper list [<options>]"),
N_("git stash--helper drop [-q|--quiet] [<stash>]"),
N_("git stash--helper ( pop | apply ) [--index] [-q|--quiet] [<stash>]"),
N_("git stash--helper branch <branchname> [<stash>]"),
N_("git stash--helper clear"),
NULL
};

static const char * const git_stash_helper_list_usage[] = {
N_("git stash--helper list [<options>]"),
NULL
};

static const char * const git_stash_helper_drop_usage[] = {
N_("git stash--helper drop [-q|--quiet] [<stash>]"),
NULL
Expand Down Expand Up @@ -615,6 +621,29 @@ static int branch_stash(int argc, const char **argv, const char *prefix)
return ret;
}

static int list_stash(int argc, const char **argv, const char *prefix)
{
struct child_process cp = CHILD_PROCESS_INIT;
struct option options[] = {
OPT_END()
};

argc = parse_options(argc, argv, prefix, options,
git_stash_helper_list_usage,
PARSE_OPT_KEEP_UNKNOWN);

if (!ref_exists(ref_stash))
return 0;

cp.git_cmd = 1;
argv_array_pushl(&cp.args, "log", "--format=%gd: %gs", "-g",
"--first-parent", "-m", NULL);
argv_array_pushv(&cp.args, argv);
argv_array_push(&cp.args, ref_stash);
argv_array_push(&cp.args, "--");
return run_command(&cp);
}

int cmd_stash__helper(int argc, const char **argv, const char *prefix)
{
pid_t pid = getpid();
Expand Down Expand Up @@ -645,6 +674,8 @@ int cmd_stash__helper(int argc, const char **argv, const char *prefix)
return !!pop_stash(argc, argv, prefix);
else if (!strcmp(argv[0], "branch"))
return !!branch_stash(argc, argv, prefix);
else if (!strcmp(argv[0], "list"))
return !!list_stash(argc, argv, prefix);

usage_msg_opt(xstrfmt(_("unknown subcommand: %s"), argv[0]),
git_stash_helper_usage, options);
Expand Down
7 changes: 1 addition & 6 deletions git-stash.sh
Expand Up @@ -399,11 +399,6 @@ have_stash () {
git rev-parse --verify --quiet $ref_stash >/dev/null
}

list_stash () {
have_stash || return 0
git log --format="%gd: %gs" -g --first-parent -m "$@" $ref_stash --
}

show_stash () {
ALLOW_UNKNOWN_FLAGS=t
assert_stash_like "$@"
Expand Down Expand Up @@ -591,7 +586,7 @@ test -n "$seen_non_option" || set "push" "$@"
case "$1" in
list)
shift
list_stash "$@"
git stash--helper list "$@"
;;
show)
shift
Expand Down

0 comments on commit 130f269

Please sign in to comment.