Skip to content

Commit

Permalink
stash: convert save to builtin
Browse files Browse the repository at this point in the history
Add stash save to the helper and delete functions which are no
longer needed (`show_help()`, `save_stash()`, `push_stash()`,
`create_stash()`, `clear_stash()`, `untracked_files()` and
`no_changes()`).

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 1ac528c commit 64fe9c2
Show file tree
Hide file tree
Showing 2 changed files with 52 additions and 326 deletions.
50 changes: 50 additions & 0 deletions builtin/stash--helper.c
Expand Up @@ -26,6 +26,8 @@ static const char * const git_stash_helper_usage[] = {
N_("git stash--helper [push [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n"
" [-u|--include-untracked] [-a|--all] [-m|--message <message>]\n"
" [--] [<pathspec>...]]"),
N_("git stash--helper save [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n"
" [-u|--include-untracked] [-a|--all] [<message>]"),
NULL
};

Expand Down Expand Up @@ -81,6 +83,12 @@ static const char * const git_stash_helper_push_usage[] = {
NULL
};

static const char * const git_stash_helper_save_usage[] = {
N_("git stash--helper save [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n"
" [-u|--include-untracked] [-a|--all] [<message>]"),
NULL
};

static const char *ref_stash = "refs/stash";
static struct strbuf stash_index_path = STRBUF_INIT;

Expand Down Expand Up @@ -1486,6 +1494,46 @@ static int push_stash(int argc, const char **argv, const char *prefix)
include_untracked);
}

static int save_stash(int argc, const char **argv, const char *prefix)
{
int keep_index = -1;
int patch_mode = 0;
int include_untracked = 0;
int quiet = 0;
int ret = 0;
const char *stash_msg = NULL;
struct pathspec ps;
struct strbuf stash_msg_buf = STRBUF_INIT;
struct option options[] = {
OPT_BOOL('k', "keep-index", &keep_index,
N_("keep index")),
OPT_BOOL('p', "patch", &patch_mode,
N_("stash in patch mode")),
OPT__QUIET(&quiet, N_("quiet mode")),
OPT_BOOL('u', "include-untracked", &include_untracked,
N_("include untracked files in stash")),
OPT_SET_INT('a', "all", &include_untracked,
N_("include ignore files"), 2),
OPT_STRING('m', "message", &stash_msg, "message",
N_("stash message")),
OPT_END()
};

argc = parse_options(argc, argv, prefix, options,
git_stash_helper_save_usage,
PARSE_OPT_KEEP_DASHDASH);

if (argc)
stash_msg = strbuf_join_argv(&stash_msg_buf, argc, argv, ' ');

memset(&ps, 0, sizeof(ps));
ret = do_push_stash(ps, stash_msg, quiet, keep_index,
patch_mode, include_untracked);

strbuf_release(&stash_msg_buf);
return ret;
}

int cmd_stash__helper(int argc, const char **argv, const char *prefix)
{
pid_t pid = getpid();
Expand Down Expand Up @@ -1526,6 +1574,8 @@ int cmd_stash__helper(int argc, const char **argv, const char *prefix)
return !!create_stash(argc, argv, prefix);
else if (!strcmp(argv[0], "push"))
return !!push_stash(argc, argv, prefix);
else if (!strcmp(argv[0], "save"))
return !!save_stash(argc, argv, prefix);

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

0 comments on commit 64fe9c2

Please sign in to comment.