@matheusbsbs / matheus-bagliano / commits / 785586142a
Fork 0

Make builtin-symbolic-ref.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 7, 2007 at 23:18 UTC 785586142a5ed083b97b7be472c08982ae88fd8f
1 file changed +18 -34
builtin-symbolic-ref.c
+18 -34
@@ -1,9 +1,12 @@
1 #include "builtin.h"
2 #include "cache.h"
3 #include "refs.h"
4 +#include "parse-options.h"
5
5 -static const char git_symbolic_ref_usage[] =
6 -"git-symbolic-ref [-q] [-m <reason>] name [ref]";
6 +static const char * const git_symbolic_ref_usage[] = {
7 + "git-symbolic-ref [options] name [ref]",
8 + NULL
9 +};
10
11 static void check_symref(const char *HEAD, int quiet)
12 {
@@ -26,44 +29,25 @@ int cmd_symbolic_ref(int argc, const char **argv, const char *prefix)
29 {
30 int quiet = 0;
31 const char *msg = NULL;
32 + struct option options[] = {
33 + OPT__QUIET(&quiet),
34 + OPT_STRING('m', NULL, &msg, "reason", "reason of the update"),
35 + OPT_END(),
36 + };
37
38 git_config(git_default_config);
31 -
32 - while (1 < argc) {
33 - const char *arg = argv[1];
34 - if (arg[0] != '-')
35 - break;
36 - else if (!strcmp("-q", arg))
37 - quiet = 1;
38 - else if (!strcmp("-m", arg)) {
39 - argc--;
40 - argv++;
41 - if (argc <= 1)
42 - break;
43 - msg = argv[1];
44 - if (!*msg)
45 - die("Refusing to perform update with empty message");
46 - }
47 - else if (!strcmp("--", arg)) {
48 - argc--;
49 - argv++;
50 - break;
51 - }
52 - else
53 - die("unknown option %s", arg);
54 - argc--;
55 - argv++;
56 - }
57 -
39 + argc = parse_options(argc, argv, options, git_symbolic_ref_usage, 0);
40 + if (msg &&!*msg)
41 + die("Refusing to perform update with empty message");
42 switch (argc) {
59 - case 2:
60 - check_symref(argv[1], quiet);
43 + case 1:
44 + check_symref(argv[0], quiet);
45 break;
62 - case 3:
63 - create_symref(argv[1], argv[2], msg);
46 + case 2:
47 + create_symref(argv[0], argv[1], msg);
48 break;
49 default:
66 - usage(git_symbolic_ref_usage);
50 + usage_with_options(git_symbolic_ref_usage, options);
51 }
52 return 0;
53 }