Skip to content

Commit 87ca7a9

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 350bfb7 commit 87ca7a9

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

@@ -1494,6 +1502,46 @@ static int push_stash(int argc, const char **argv, const char *prefix)
14941502
include_untracked);
14951503
}
14961504

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

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

0 commit comments

Comments
 (0)