Skip to content

Commit 1fdee85

Browse files
committed
mktree: use parse-options
Signed-off-by: Junio C Hamano <gitster@pobox.com>
1 parent 633e355 commit 1fdee85

1 file changed

Lines changed: 10 additions & 10 deletions

File tree

builtin-mktree.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
#include "builtin.h"
77
#include "quote.h"
88
#include "tree.h"
9+
#include "parse-options.h"
910

1011
static struct treeent {
1112
unsigned mode;
@@ -61,24 +62,23 @@ static void write_tree(unsigned char *sha1)
6162
write_sha1_file(buf.buf, buf.len, tree_type, sha1);
6263
}
6364

64-
static const char mktree_usage[] = "git mktree [-z]";
65+
static const char *mktree_usage[] = {
66+
"git mktree [-z]",
67+
NULL
68+
};
6569

6670
int cmd_mktree(int ac, const char **av, const char *prefix)
6771
{
6872
struct strbuf sb = STRBUF_INIT;
6973
struct strbuf p_uq = STRBUF_INIT;
7074
unsigned char sha1[20];
7175
int line_termination = '\n';
76+
const struct option option[] = {
77+
OPT_SET_INT('z', NULL, &line_termination, "input is NUL terminated", '\0'),
78+
OPT_END()
79+
};
7280

73-
while ((1 < ac) && av[1][0] == '-') {
74-
const char *arg = av[1];
75-
if (!strcmp("-z", arg))
76-
line_termination = 0;
77-
else
78-
usage(mktree_usage);
79-
ac--;
80-
av++;
81-
}
81+
ac = parse_options(ac, av, option, mktree_usage, 0);
8282

8383
while (strbuf_getline(&sb, stdin, line_termination) != EOF) {
8484
char *ptr, *ntr;

0 commit comments

Comments
 (0)