Skip to content

Commit fb83953

Browse files
ungpsdscho
authored andcommitted
stash: convert save to builtin
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 <[email protected]>
1 parent ccc0582 commit fb83953

File tree

2 files changed

+52
-309
lines changed

2 files changed

+52
-309
lines changed

builtin/stash--helper.c

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ static const char * const git_stash_helper_usage[] = {
2626
N_("git stash--helper [push [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n"
2727
" [-u|--include-untracked] [-a|--all] [-m|--message <message>]\n"
2828
" [--] [<pathspec>...]]"),
29+
N_("git stash--helper save [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n"
30+
" [-u|--include-untracked] [-a|--all] [<message>]"),
2931
NULL
3032
};
3133

@@ -81,6 +83,12 @@ static const char * const git_stash_helper_push_usage[] = {
8183
NULL
8284
};
8385

86+
static const char * const git_stash_helper_save_usage[] = {
87+
N_("git stash--helper save [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n"
88+
" [-u|--include-untracked] [-a|--all] [<message>]"),
89+
NULL
90+
};
91+
8492
static const char *ref_stash = "refs/stash";
8593
static struct strbuf stash_index_path = STRBUF_INIT;
8694

@@ -1490,6 +1498,46 @@ static int push_stash(int argc, const char **argv, const char *prefix)
14901498
include_untracked);
14911499
}
14921500

1501+
static int save_stash(int argc, const char **argv, const char *prefix)
1502+
{
1503+
int keep_index = -1;
1504+
int patch_mode = 0;
1505+
int include_untracked = 0;
1506+
int quiet = 0;
1507+
int ret = 0;
1508+
const char *stash_msg = NULL;
1509+
struct pathspec ps;
1510+
struct strbuf stash_msg_buf = STRBUF_INIT;
1511+
struct option options[] = {
1512+
OPT_BOOL('k', "keep-index", &keep_index,
1513+
N_("keep index")),
1514+
OPT_BOOL('p', "patch", &patch_mode,
1515+
N_("stash in patch mode")),
1516+
OPT__QUIET(&quiet, N_("quiet mode")),
1517+
OPT_BOOL('u', "include-untracked", &include_untracked,
1518+
N_("include untracked files in stash")),
1519+
OPT_SET_INT('a', "all", &include_untracked,
1520+
N_("include ignore files"), 2),
1521+
OPT_STRING('m', "message", &stash_msg, "message",
1522+
N_("stash message")),
1523+
OPT_END()
1524+
};
1525+
1526+
argc = parse_options(argc, argv, prefix, options,
1527+
git_stash_helper_save_usage,
1528+
PARSE_OPT_KEEP_DASHDASH);
1529+
1530+
if (argc)
1531+
stash_msg = strbuf_join_argv(&stash_msg_buf, argc, argv, ' ');
1532+
1533+
memset(&ps, 0, sizeof(ps));
1534+
ret = do_push_stash(ps, stash_msg, quiet, keep_index,
1535+
patch_mode, include_untracked);
1536+
1537+
strbuf_release(&stash_msg_buf);
1538+
return ret;
1539+
}
1540+
14931541
int cmd_stash__helper(int argc, const char **argv, const char *prefix)
14941542
{
14951543
pid_t pid = getpid();
@@ -1530,6 +1578,8 @@ int cmd_stash__helper(int argc, const char **argv, const char *prefix)
15301578
return !!create_stash(argc, argv, prefix);
15311579
else if (!strcmp(argv[0], "push"))
15321580
return !!push_stash(argc, argv, prefix);
1581+
else if (!strcmp(argv[0], "save"))
1582+
return !!save_stash(argc, argv, prefix);
15331583

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

0 commit comments

Comments
 (0)