Skip to content

Commit 2b8b36b

Browse files
committed
fixup! stash: convert drop and clear to builtin
In preparation for a newer patch series. Signed-off-by: Johannes Schindelin <[email protected]>
1 parent 35eac1e commit 2b8b36b

File tree

2 files changed

+2
-119
lines changed

2 files changed

+2
-119
lines changed

builtin/stash--helper.c

Lines changed: 0 additions & 117 deletions
Original file line numberDiff line numberDiff line change
@@ -13,14 +13,7 @@
1313
#include "rerere.h"
1414

1515
static const char * const git_stash_helper_usage[] = {
16-
N_("git stash--helper drop [-q|--quiet] [<stash>]"),
1716
N_("git stash--helper apply [--index] [-q|--quiet] [<stash>]"),
18-
N_("git stash--helper clear"),
19-
NULL
20-
};
21-
22-
static const char * const git_stash_helper_drop_usage[] = {
23-
N_("git stash--helper drop [-q|--quiet] [<stash>]"),
2417
NULL
2518
};
2619

@@ -29,11 +22,6 @@ static const char * const git_stash_helper_apply_usage[] = {
2922
NULL
3023
};
3124

32-
static const char * const git_stash_helper_clear_usage[] = {
33-
N_("git stash--helper clear"),
34-
NULL
35-
};
36-
3725
static const char *ref_stash = "refs/stash";
3826
static struct strbuf stash_index_path = STRBUF_INIT;
3927

@@ -150,32 +138,6 @@ static int get_stash_info(struct stash_info *info, int argc, const char **argv)
150138
return !(ret == 0 || ret == 1);
151139
}
152140

153-
static int do_clear_stash(void)
154-
{
155-
struct object_id obj;
156-
if (get_oid(ref_stash, &obj))
157-
return 0;
158-
159-
return delete_ref(NULL, ref_stash, &obj, 0);
160-
}
161-
162-
static int clear_stash(int argc, const char **argv, const char *prefix)
163-
{
164-
struct option options[] = {
165-
OPT_END()
166-
};
167-
168-
argc = parse_options(argc, argv, prefix, options,
169-
git_stash_helper_clear_usage,
170-
PARSE_OPT_STOP_AT_NON_OPTION);
171-
172-
if (argc)
173-
return error(_("git stash clear with parameters is "
174-
"unimplemented"));
175-
176-
return do_clear_stash();
177-
}
178-
179141
static int reset_tree(struct object_id *i_tree, int update, int reset)
180142
{
181143
int nr_trees = 1;
@@ -463,81 +425,6 @@ static int apply_stash(int argc, const char **argv, const char *prefix)
463425
return ret;
464426
}
465427

466-
static int do_drop_stash(const char *prefix, struct stash_info *info, int quiet)
467-
{
468-
int ret;
469-
struct child_process cp_reflog = CHILD_PROCESS_INIT;
470-
struct child_process cp = CHILD_PROCESS_INIT;
471-
472-
/*
473-
* reflog does not provide a simple function for deleting refs. One will
474-
* need to be added to avoid implementing too much reflog code here
475-
*/
476-
477-
cp_reflog.git_cmd = 1;
478-
argv_array_pushl(&cp_reflog.args, "reflog", "delete", "--updateref",
479-
"--rewrite", NULL);
480-
argv_array_push(&cp_reflog.args, info->revision.buf);
481-
ret = run_command(&cp_reflog);
482-
if (!ret) {
483-
if (!quiet)
484-
printf_ln(_("Dropped %s (%s)"), info->revision.buf,
485-
oid_to_hex(&info->w_commit));
486-
} else {
487-
return error(_("%s: Could not drop stash entry"),
488-
info->revision.buf);
489-
}
490-
491-
/*
492-
* This could easily be replaced by get_oid, but currently it will throw
493-
* a fatal error when a reflog is empty, which we can not recover from.
494-
*/
495-
cp.git_cmd = 1;
496-
/* Even though --quiet is specified, rev-parse still outputs the hash */
497-
cp.no_stdout = 1;
498-
argv_array_pushl(&cp.args, "rev-parse", "--verify", "--quiet", NULL);
499-
argv_array_pushf(&cp.args, "%s@{0}", ref_stash);
500-
ret = run_command(&cp);
501-
502-
/* do_clear_stash if we just dropped the last stash entry */
503-
if (ret)
504-
do_clear_stash();
505-
506-
return 0;
507-
}
508-
509-
static void assert_stash_ref(struct stash_info *info)
510-
{
511-
if (!info->is_stash_ref) {
512-
free_stash_info(info);
513-
error(_("'%s' is not a stash reference"), info->revision.buf);
514-
exit(128);
515-
}
516-
}
517-
518-
static int drop_stash(int argc, const char **argv, const char *prefix)
519-
{
520-
int ret;
521-
int quiet = 0;
522-
struct stash_info info;
523-
struct option options[] = {
524-
OPT__QUIET(&quiet, N_("be quiet, only report errors")),
525-
OPT_END()
526-
};
527-
528-
argc = parse_options(argc, argv, prefix, options,
529-
git_stash_helper_drop_usage, 0);
530-
531-
if (get_stash_info(&info, argc, argv))
532-
return -1;
533-
534-
assert_stash_ref(&info);
535-
536-
ret = do_drop_stash(prefix, &info, quiet);
537-
free_stash_info(&info);
538-
return ret;
539-
}
540-
541428
int cmd_stash__helper(int argc, const char **argv, const char *prefix)
542429
{
543430
pid_t pid = getpid();
@@ -560,10 +447,6 @@ int cmd_stash__helper(int argc, const char **argv, const char *prefix)
560447
usage_with_options(git_stash_helper_usage, options);
561448
if (!strcmp(argv[0], "apply"))
562449
return !!apply_stash(argc, argv, prefix);
563-
else if (!strcmp(argv[0], "clear"))
564-
return !!clear_stash(argc, argv, prefix);
565-
else if (!strcmp(argv[0], "drop"))
566-
return !!drop_stash(argc, argv, prefix);
567450

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

git-stash.sh

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -670,7 +670,7 @@ apply)
670670
;;
671671
clear)
672672
shift
673-
git stash--helper clear "$@"
673+
clear_stash "$@"
674674
;;
675675
create)
676676
shift
@@ -682,7 +682,7 @@ store)
682682
;;
683683
drop)
684684
shift
685-
git stash--helper drop "$@"
685+
drop_stash "$@"
686686
;;
687687
pop)
688688
shift

0 commit comments

Comments
 (0)