Skip to content

Commit 1a1b0a2

Browse files
ungpsGit for Windows Build Agent
authored andcommitted
stash: convert stash--helper.c into stash.c
The old shell script `git-stash.sh` was removed and replaced entirely by `builtin/stash.c`. In order to do that, `create` and `push` were adapted to work without `stash.sh`. For example, before this commit, `git stash create` called `git stash--helper create --message "$*"`. If it called `git stash--helper create "$@"`, then some of these changes wouldn't have been necessary. This commit also removes the word `helper` since now stash is called directly and not by a 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 7f30688 commit 1a1b0a2

File tree

6 files changed

+92
-225
lines changed

6 files changed

+92
-225
lines changed

.gitignore

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -162,7 +162,6 @@
162162
/git-show-ref
163163
/git-stage
164164
/git-stash
165-
/git-stash--helper
166165
/git-status
167166
/git-stripspace
168167
/git-submodule

Makefile

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -635,7 +635,6 @@ SCRIPT_SH += git-quiltimport.sh
635635
SCRIPT_SH += git-legacy-rebase.sh
636636
SCRIPT_SH += git-remote-testgit.sh
637637
SCRIPT_SH += git-request-pull.sh
638-
SCRIPT_SH += git-stash.sh
639638
SCRIPT_SH += git-submodule.sh
640639
SCRIPT_SH += git-web--browse.sh
641640

@@ -1138,7 +1137,7 @@ BUILTIN_OBJS += builtin/shortlog.o
11381137
BUILTIN_OBJS += builtin/show-branch.o
11391138
BUILTIN_OBJS += builtin/show-index.o
11401139
BUILTIN_OBJS += builtin/show-ref.o
1141-
BUILTIN_OBJS += builtin/stash--helper.o
1140+
BUILTIN_OBJS += builtin/stash.o
11421141
BUILTIN_OBJS += builtin/stripspace.o
11431142
BUILTIN_OBJS += builtin/submodule--helper.o
11441143
BUILTIN_OBJS += builtin/symbolic-ref.o

builtin.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ extern int cmd_show(int argc, const char **argv, const char *prefix);
225225
extern int cmd_show_branch(int argc, const char **argv, const char *prefix);
226226
extern int cmd_show_index(int argc, const char **argv, const char *prefix);
227227
extern int cmd_status(int argc, const char **argv, const char *prefix);
228-
extern int cmd_stash__helper(int argc, const char **argv, const char *prefix);
228+
extern int cmd_stash(int argc, const char **argv, const char *prefix);
229229
extern int cmd_stripspace(int argc, const char **argv, const char *prefix);
230230
extern int cmd_submodule__helper(int argc, const char **argv, const char *prefix);
231231
extern int cmd_symbolic_ref(int argc, const char **argv, const char *prefix);

builtin/stash--helper.c renamed to builtin/stash.c

Lines changed: 89 additions & 67 deletions
Original file line numberDiff line numberDiff line change
@@ -17,75 +17,70 @@
1717

1818
#define INCLUDE_ALL_FILES 2
1919

20-
static const char * const git_stash_helper_usage[] = {
21-
N_("git stash--helper list [<options>]"),
22-
N_("git stash--helper show [<options>] [<stash>]"),
23-
N_("git stash--helper drop [-q|--quiet] [<stash>]"),
24-
N_("git stash--helper ( pop | apply ) [--index] [-q|--quiet] [<stash>]"),
25-
N_("git stash--helper branch <branchname> [<stash>]"),
26-
N_("git stash--helper clear"),
27-
N_("git stash--helper [push [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n"
20+
static const char * const git_stash_usage[] = {
21+
N_("git stash list [<options>]"),
22+
N_("git stash show [<options>] [<stash>]"),
23+
N_("git stash drop [-q|--quiet] [<stash>]"),
24+
N_("git stash ( pop | apply ) [--index] [-q|--quiet] [<stash>]"),
25+
N_("git stash branch <branchname> [<stash>]"),
26+
N_("git stash clear"),
27+
N_("git stash [push [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n"
2828
" [-u|--include-untracked] [-a|--all] [-m|--message <message>]\n"
2929
" [--] [<pathspec>...]]"),
30-
N_("git stash--helper save [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n"
30+
N_("git stash save [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n"
3131
" [-u|--include-untracked] [-a|--all] [<message>]"),
3232
NULL
3333
};
3434

35-
static const char * const git_stash_helper_list_usage[] = {
36-
N_("git stash--helper list [<options>]"),
35+
static const char * const git_stash_list_usage[] = {
36+
N_("git stash list [<options>]"),
3737
NULL
3838
};
3939

40-
static const char * const git_stash_helper_show_usage[] = {
41-
N_("git stash--helper show [<options>] [<stash>]"),
40+
static const char * const git_stash_show_usage[] = {
41+
N_("git stash show [<options>] [<stash>]"),
4242
NULL
4343
};
4444

45-
static const char * const git_stash_helper_drop_usage[] = {
46-
N_("git stash--helper drop [-q|--quiet] [<stash>]"),
45+
static const char * const git_stash_drop_usage[] = {
46+
N_("git stash drop [-q|--quiet] [<stash>]"),
4747
NULL
4848
};
4949

50-
static const char * const git_stash_helper_pop_usage[] = {
51-
N_("git stash--helper pop [--index] [-q|--quiet] [<stash>]"),
50+
static const char * const git_stash_pop_usage[] = {
51+
N_("git stash pop [--index] [-q|--quiet] [<stash>]"),
5252
NULL
5353
};
5454

55-
static const char * const git_stash_helper_apply_usage[] = {
56-
N_("git stash--helper apply [--index] [-q|--quiet] [<stash>]"),
55+
static const char * const git_stash_apply_usage[] = {
56+
N_("git stash apply [--index] [-q|--quiet] [<stash>]"),
5757
NULL
5858
};
5959

60-
static const char * const git_stash_helper_branch_usage[] = {
61-
N_("git stash--helper branch <branchname> [<stash>]"),
60+
static const char * const git_stash_branch_usage[] = {
61+
N_("git stash branch <branchname> [<stash>]"),
6262
NULL
6363
};
6464

65-
static const char * const git_stash_helper_clear_usage[] = {
66-
N_("git stash--helper clear"),
65+
static const char * const git_stash_clear_usage[] = {
66+
N_("git stash clear"),
6767
NULL
6868
};
6969

70-
static const char * const git_stash_helper_store_usage[] = {
71-
N_("git stash--helper store [-m|--message <message>] [-q|--quiet] <commit>"),
70+
static const char * const git_stash_store_usage[] = {
71+
N_("git stash store [-m|--message <message>] [-q|--quiet] <commit>"),
7272
NULL
7373
};
7474

75-
static const char * const git_stash_helper_create_usage[] = {
76-
N_("git stash--helper create [<message>]"),
77-
NULL
78-
};
79-
80-
static const char * const git_stash_helper_push_usage[] = {
81-
N_("git stash--helper [push [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n"
75+
static const char * const git_stash_push_usage[] = {
76+
N_("git stash [push [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n"
8277
" [-u|--include-untracked] [-a|--all] [-m|--message <message>]\n"
8378
" [--] [<pathspec>...]]"),
8479
NULL
8580
};
8681

87-
static const char * const git_stash_helper_save_usage[] = {
88-
N_("git stash--helper save [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n"
82+
static const char * const git_stash_save_usage[] = {
83+
N_("git stash save [-p|--patch] [-k|--[no-]keep-index] [-q|--quiet]\n"
8984
" [-u|--include-untracked] [-a|--all] [<message>]"),
9085
NULL
9186
};
@@ -221,7 +216,7 @@ static int clear_stash(int argc, const char **argv, const char *prefix)
221216
};
222217

223218
argc = parse_options(argc, argv, prefix, options,
224-
git_stash_helper_clear_usage,
219+
git_stash_clear_usage,
225220
PARSE_OPT_STOP_AT_NON_OPTION);
226221

227222
if (argc)
@@ -522,7 +517,7 @@ static int apply_stash(int argc, const char **argv, const char *prefix)
522517
};
523518

524519
argc = parse_options(argc, argv, prefix, options,
525-
git_stash_helper_apply_usage, 0);
520+
git_stash_apply_usage, 0);
526521

527522
if (get_stash_info(&info, argc, argv))
528523
return -1;
@@ -595,7 +590,7 @@ static int drop_stash(int argc, const char **argv, const char *prefix)
595590
};
596591

597592
argc = parse_options(argc, argv, prefix, options,
598-
git_stash_helper_drop_usage, 0);
593+
git_stash_drop_usage, 0);
599594

600595
if (get_stash_info(&info, argc, argv))
601596
return -1;
@@ -621,7 +616,7 @@ static int pop_stash(int argc, const char **argv, const char *prefix)
621616
};
622617

623618
argc = parse_options(argc, argv, prefix, options,
624-
git_stash_helper_pop_usage, 0);
619+
git_stash_pop_usage, 0);
625620

626621
if (get_stash_info(&info, argc, argv))
627622
return -1;
@@ -648,7 +643,7 @@ static int branch_stash(int argc, const char **argv, const char *prefix)
648643
};
649644

650645
argc = parse_options(argc, argv, prefix, options,
651-
git_stash_helper_branch_usage, 0);
646+
git_stash_branch_usage, 0);
652647

653648
if (!argc) {
654649
fprintf_ln(stderr, _("No branch name specified"));
@@ -683,7 +678,7 @@ static int list_stash(int argc, const char **argv, const char *prefix)
683678
};
684679

685680
argc = parse_options(argc, argv, prefix, options,
686-
git_stash_helper_list_usage,
681+
git_stash_list_usage,
687682
PARSE_OPT_KEEP_UNKNOWN);
688683

689684
if (!ref_exists(ref_stash))
@@ -763,7 +758,7 @@ static int show_stash(int argc, const char **argv, const char *prefix)
763758
argc = setup_revisions(argc, argv, &rev, NULL);
764759
if (argc > 1) {
765760
free_stash_info(&info);
766-
usage_with_options(git_stash_helper_show_usage, options);
761+
usage_with_options(git_stash_show_usage, options);
767762
}
768763

769764
rev.diffopt.flags.recursive = 1;
@@ -809,7 +804,7 @@ static int store_stash(int argc, const char **argv, const char *prefix)
809804
};
810805

811806
argc = parse_options(argc, argv, prefix, options,
812-
git_stash_helper_store_usage,
807+
git_stash_store_usage,
813808
PARSE_OPT_KEEP_UNKNOWN);
814809

815810
if (argc != 1) {
@@ -1223,30 +1218,19 @@ static int do_create_stash(struct pathspec ps, struct strbuf *stash_msg_buf,
12231218

12241219
static int create_stash(int argc, const char **argv, const char *prefix)
12251220
{
1226-
int include_untracked = 0;
12271221
int ret = 0;
1228-
const char *stash_msg = NULL;
12291222
struct strbuf stash_msg_buf = STRBUF_INIT;
12301223
struct stash_info info;
12311224
struct pathspec ps;
1232-
struct option options[] = {
1233-
OPT_BOOL('u', "include-untracked", &include_untracked,
1234-
N_("include untracked files in stash")),
1235-
OPT_STRING('m', "message", &stash_msg, N_("message"),
1236-
N_("stash message")),
1237-
OPT_END()
1238-
};
12391225

1240-
argc = parse_options(argc, argv, prefix, options,
1241-
git_stash_helper_create_usage,
1242-
0);
1226+
/* Starting with argv[1], since argv[0] is "create" */
1227+
strbuf_join_argv(&stash_msg_buf, argc - 1, ++argv, ' ');
12431228

12441229
memset(&ps, 0, sizeof(ps));
12451230
if (!check_changes_tracked_files(ps))
12461231
return 0;
12471232

1248-
strbuf_addstr(&stash_msg_buf, stash_msg);
1249-
ret = do_create_stash(ps, &stash_msg_buf, include_untracked, 0, &info,
1233+
ret = do_create_stash(ps, &stash_msg_buf, 0, 0, &info,
12501234
NULL, 0);
12511235
if (!ret)
12521236
printf_ln("%s", oid_to_hex(&info.w_commit));
@@ -1478,9 +1462,10 @@ static int push_stash(int argc, const char **argv, const char *prefix)
14781462
OPT_END()
14791463
};
14801464

1481-
argc = parse_options(argc, argv, prefix, options,
1482-
git_stash_helper_push_usage,
1483-
0);
1465+
if (argc)
1466+
argc = parse_options(argc, argv, prefix, options,
1467+
git_stash_push_usage,
1468+
0);
14841469

14851470
parse_pathspec(&ps, 0, PATHSPEC_PREFER_FULL, prefix, argv);
14861471
return do_push_stash(ps, stash_msg, quiet, keep_index, patch_mode,
@@ -1513,7 +1498,7 @@ static int save_stash(int argc, const char **argv, const char *prefix)
15131498
};
15141499

15151500
argc = parse_options(argc, argv, prefix, options,
1516-
git_stash_helper_save_usage,
1501+
git_stash_save_usage,
15171502
PARSE_OPT_KEEP_DASHDASH);
15181503

15191504
if (argc)
@@ -1527,27 +1512,29 @@ static int save_stash(int argc, const char **argv, const char *prefix)
15271512
return ret;
15281513
}
15291514

1530-
int cmd_stash__helper(int argc, const char **argv, const char *prefix)
1515+
int cmd_stash(int argc, const char **argv, const char *prefix)
15311516
{
1517+
int i = -1;
15321518
pid_t pid = getpid();
15331519
const char *index_file;
1520+
struct argv_array args = ARGV_ARRAY_INIT;
15341521

15351522
struct option options[] = {
15361523
OPT_END()
15371524
};
15381525

15391526
git_config(git_diff_basic_config, NULL);
15401527

1541-
argc = parse_options(argc, argv, prefix, options, git_stash_helper_usage,
1528+
argc = parse_options(argc, argv, prefix, options, git_stash_usage,
15421529
PARSE_OPT_KEEP_UNKNOWN | PARSE_OPT_KEEP_DASHDASH);
15431530

15441531
index_file = get_index_file();
15451532
strbuf_addf(&stash_index_path, "%s.stash.%" PRIuMAX, index_file,
15461533
(uintmax_t)pid);
15471534

1548-
if (argc < 1)
1549-
usage_with_options(git_stash_helper_usage, options);
1550-
if (!strcmp(argv[0], "apply"))
1535+
if (!argc)
1536+
return !!push_stash(0, NULL, prefix);
1537+
else if (!strcmp(argv[0], "apply"))
15511538
return !!apply_stash(argc, argv, prefix);
15521539
else if (!strcmp(argv[0], "clear"))
15531540
return !!clear_stash(argc, argv, prefix);
@@ -1569,7 +1556,42 @@ int cmd_stash__helper(int argc, const char **argv, const char *prefix)
15691556
return !!push_stash(argc, argv, prefix);
15701557
else if (!strcmp(argv[0], "save"))
15711558
return !!save_stash(argc, argv, prefix);
1559+
else if (*argv[0] != '-')
1560+
usage_msg_opt(xstrfmt(_("unknown subcommand: %s"), argv[0]),
1561+
git_stash_usage, options);
1562+
1563+
if (strcmp(argv[0], "-p")) {
1564+
while (++i < argc && strcmp(argv[i], "--")) {
1565+
/*
1566+
* `akpqu` is a string which contains all short options,
1567+
* except `-m` which is verified separately.
1568+
*/
1569+
if ((strlen(argv[i]) == 2) && *argv[i] == '-' &&
1570+
strchr("akpqu", argv[i][1]))
1571+
continue;
1572+
1573+
if (!strcmp(argv[i], "--all") ||
1574+
!strcmp(argv[i], "--keep-index") ||
1575+
!strcmp(argv[i], "--no-keep-index") ||
1576+
!strcmp(argv[i], "--patch") ||
1577+
!strcmp(argv[i], "--quiet") ||
1578+
!strcmp(argv[i], "--include-untracked"))
1579+
continue;
1580+
1581+
/*
1582+
* `-m` and `--message=` are verified separately because
1583+
* they need to be immediately followed by a string
1584+
* (i.e.`-m"foobar"` or `--message="foobar"`).
1585+
*/
1586+
if (starts_with(argv[i], "-m") ||
1587+
starts_with(argv[i], "--message="))
1588+
continue;
1589+
1590+
usage_with_options(git_stash_usage, options);
1591+
}
1592+
}
15721593

1573-
usage_msg_opt(xstrfmt(_("unknown subcommand: %s"), argv[0]),
1574-
git_stash_helper_usage, options);
1594+
argv_array_push(&args, "push");
1595+
argv_array_pushv(&args, argv);
1596+
return !!push_stash(args.argc, args.argv, prefix);
15751597
}

0 commit comments

Comments
 (0)