Skip to content

Commit 404d42e

Browse files
bebarinogitster
authored andcommitted
write-tree: migrate to parse-options
A check for extra options has been dropped, it could never be triggered in the original code as the usage message would be printed instead. Signed-off-by: Stephen Boyd <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 4ecbc17 commit 404d42e

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

builtin-write-tree.c

Lines changed: 19 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -7,37 +7,35 @@
77
#include "cache.h"
88
#include "tree.h"
99
#include "cache-tree.h"
10+
#include "parse-options.h"
1011

11-
static const char write_tree_usage[] =
12-
"git write-tree [--missing-ok] [--prefix=<prefix>/]";
12+
static const char * const write_tree_usage[] = {
13+
"git write-tree [--missing-ok] [--prefix=<prefix>/]",
14+
NULL
15+
};
1316

1417
int cmd_write_tree(int argc, const char **argv, const char *unused_prefix)
1518
{
1619
int flags = 0, ret;
1720
const char *prefix = NULL;
1821
unsigned char sha1[20];
1922
const char *me = "git-write-tree";
23+
struct option write_tree_options[] = {
24+
OPT_BIT(0, "missing-ok", &flags, "allow missing objects",
25+
WRITE_TREE_MISSING_OK),
26+
{ OPTION_STRING, 0, "prefix", &prefix, "<prefix>/",
27+
"write tree object for a subdirectory <prefix>" ,
28+
PARSE_OPT_LITERAL_ARGHELP },
29+
{ OPTION_BIT, 0, "ignore-cache-tree", &flags, NULL,
30+
"only useful for debugging",
31+
PARSE_OPT_HIDDEN | PARSE_OPT_NOARG, NULL,
32+
WRITE_TREE_IGNORE_CACHE_TREE },
33+
OPT_END()
34+
};
2035

2136
git_config(git_default_config, NULL);
22-
while (1 < argc) {
23-
const char *arg = argv[1];
24-
if (!strcmp(arg, "--missing-ok"))
25-
flags |= WRITE_TREE_MISSING_OK;
26-
else if (!prefixcmp(arg, "--prefix="))
27-
prefix = arg + 9;
28-
else if (!prefixcmp(arg, "--ignore-cache-tree"))
29-
/*
30-
* This is only useful for debugging, so I
31-
* do not bother documenting it.
32-
*/
33-
flags |= WRITE_TREE_IGNORE_CACHE_TREE;
34-
else
35-
usage(write_tree_usage);
36-
argc--; argv++;
37-
}
38-
39-
if (argc > 2)
40-
die("too many options");
37+
argc = parse_options(argc, argv, unused_prefix, write_tree_options,
38+
write_tree_usage, 0);
4139

4240
ret = write_cache_as_tree(sha1, flags, prefix);
4341
switch (ret) {

0 commit comments

Comments
 (0)