@matheusbsbs / matheus-bagliano / commits / 629de472b6
Fork 0

builtin-prune.c: use parse_options()

Using the OPT_DATE() introduced earlier, this updates builtin-prune to use parse_options(). Signed-off-by: Michele Ballabio <barra_cuda@katamail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Michele Ballabio committed Mar 23, 2008 at 21:50 UTC 629de472b67bdb6b1fbdc72a95e1f569e3b8f02d
1 file changed +16 -22
builtin-prune.c
+16 -22
@@ -4,8 +4,12 @@
4 #include "revision.h"
5 #include "builtin.h"
6 #include "reachable.h"
7 +#include "parse-options.h"
8
8 -static const char prune_usage[] = "git-prune [-n]";
9 +static const char * const prune_usage[] = {
10 + "git-prune [-n] [--expire <time>] [--] [<head>...]",
11 + NULL
12 +};
13 static int show_only;
14 static unsigned long expire;
15
@@ -123,32 +127,22 @@ static void remove_temporary_files(void)
127
128 int cmd_prune(int argc, const char **argv, const char *prefix)
129 {
126 - int i;
130 struct rev_info revs;
128 -
129 - for (i = 1; i < argc; i++) {
130 - const char *arg = argv[i];
131 - if (!strcmp(arg, "-n")) {
132 - show_only = 1;
133 - continue;
134 - }
135 - if (!strcmp(arg, "--expire")) {
136 - if (++i < argc) {
137 - expire = approxidate(argv[i]);
138 - continue;
139 - }
140 - }
141 - else if (!prefixcmp(arg, "--expire=")) {
142 - expire = approxidate(arg + 9);
143 - continue;
144 - }
145 - usage(prune_usage);
146 - }
131 + const struct option options[] = {
132 + OPT_BOOLEAN('n', NULL, &show_only,
133 + "do not remove, show only"),
134 + OPT_DATE(0, "expire", &expire,
135 + "expire objects older than <time>"),
136 + OPT_END()
137 + };
138
139 save_commit_buffer = 0;
140 init_revisions(&revs, prefix);
150 - mark_reachable_objects(&revs, 1);
141
142 + argc = parse_options(argc, argv, options, prune_usage, 0);
143 + if (argc)
144 + die ("unrecognized argument: %s", name);
145 + mark_reachable_objects(&revs, 1);
146 prune_object_dir(get_object_directory());
147
148 sync();