@matheusbsbs / matheus-bagliano / commits / b2565ae573
Fork 0

Make builtin-pack-refs.c use parse_options.

Signed-off-by: Pierre Habouzit <madcoder@debian.org> Signed-off-by: Shawn O. Pearce <spearce@spearce.org>

Pierre Habouzit committed Oct 15, 2007 at 23:06 UTC b2565ae57376116b9d78369b6eac07e55c6f7851
1 file changed +20 -27
builtin-pack-refs.c
+20 -27
@@ -3,9 +3,7 @@
3 #include "refs.h"
4 #include "object.h"
5 #include "tag.h"
6 -
7 -static const char builtin_pack_refs_usage[] =
8 -"git-pack-refs [--all] [--prune | --no-prune]";
6 +#include "parse-options.h"
7
8 struct ref_to_prune {
9 struct ref_to_prune *next;
@@ -117,31 +115,26 @@ static int pack_refs(unsigned int flags)
115 return 0;
116 }
117
118 +static char const * const pack_refs_usage[] = {
119 + "git-pack-refs [options]",
120 + NULL
121 +};
122 +
123 int cmd_pack_refs(int argc, const char **argv, const char *prefix)
124 {
122 - int i;
123 - unsigned int flags;
124 -
125 - flags = PACK_REFS_PRUNE;
126 - for (i = 1; i < argc; i++) {
127 - const char *arg = argv[i];
128 - if (!strcmp(arg, "--prune")) {
129 - flags |= PACK_REFS_PRUNE; /* now the default */
130 - continue;
131 - }
132 - if (!strcmp(arg, "--no-prune")) {
133 - flags &= ~PACK_REFS_PRUNE;
134 - continue;
135 - }
136 - if (!strcmp(arg, "--all")) {
137 - flags |= PACK_REFS_ALL;
138 - continue;
139 - }
140 - /* perhaps other parameters later... */
141 - break;
142 - }
143 - if (i != argc)
144 - usage(builtin_pack_refs_usage);
145 -
125 + int all = 0, prune = 1;
126 + unsigned int flags = 0;
127 + struct option opts[] = {
128 + OPT_BOOLEAN(0, "all", &all, "pack everything"),
129 + OPT_BOOLEAN(0, "prune", &prune, "prune loose refs (default)"),
130 + OPT_END(),
131 + };
132 +
133 + if (parse_options(argc, argv, opts, pack_refs_usage, 0))
134 + usage_with_options(pack_refs_usage, opts);
135 + if (prune)
136 + flags |= PACK_REFS_PRUNE;
137 + if (all)
138 + flags |= PACK_REFS_ALL;
139 return pack_refs(flags);
140 }