builtin/receive-pack.c: use parse_options API

Make receive-pack use the parse_options API, bringing it more in line with send-pack and push. Helped-by: Matthieu Moy <matthieu.moy@grenoble-inp.fr> Signed-off-by: Sidhant Sharma [:tk] <tigerkid001@gmail.com> Reviewed-by: Matthieu Moy <Matthieu.Moy@imag.fr> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Sidhant Sharma [:tk] committed Mar 2, 2016 at 01:51 UTC 1b68387e026f81dcda330f721c0e54a8902ad4eb
1 file changed +20 -33
builtin/receive-pack.c
+20 -33
@@ -21,7 +21,10 @@
21 #include "sigchain.h"
22 #include "fsck.h"
23
24 -static const char receive_pack_usage[] = "git receive-pack <git-dir>";
24 +static const char * const receive_pack_usage[] = {
25 + N_("git receive-pack <git-dir>"),
26 + NULL
27 +};
28
29 enum deny_action {
30 DENY_UNCONFIGURED,
@@ -49,7 +52,7 @@ static int quiet;
52 static int prefer_ofs_delta = 1;
53 static int auto_update_server_info;
54 static int auto_gc = 1;
52 -static int fix_thin = 1;
55 +static int reject_thin;
56 static int stateless_rpc;
57 static const char *service_dir;
58 static const char *head_name;
@@ -1548,7 +1551,7 @@ static const char *unpack(int err_fd, struct shallow_info *si)
1551 if (fsck_objects)
1552 argv_array_pushf(&child.args, "--strict%s",
1553 fsck_msg_types.buf);
1551 - if (fix_thin)
1554 + if (!reject_thin)
1555 argv_array_push(&child.args, "--fix-thin");
1556 child.out = -1;
1557 child.err = err_fd;
@@ -1707,45 +1710,29 @@ static int delete_only(struct command *commands)
1710 int cmd_receive_pack(int argc, const char **argv, const char *prefix)
1711 {
1712 int advertise_refs = 0;
1710 - int i;
1713 struct command *commands;
1714 struct sha1_array shallow = SHA1_ARRAY_INIT;
1715 struct sha1_array ref = SHA1_ARRAY_INIT;
1716 struct shallow_info si;
1717
1716 - packet_trace_identity("receive-pack");
1718 + struct option options[] = {
1719 + OPT__QUIET(&quiet, N_("quiet")),
1720 + OPT_HIDDEN_BOOL(0, "stateless-rpc", &stateless_rpc, NULL),
1721 + OPT_HIDDEN_BOOL(0, "advertise-refs", &advertise_refs, NULL),
1722 + OPT_HIDDEN_BOOL(0, "reject-thin-pack-for-testing", &reject_thin, NULL),
1723 + OPT_END()
1724 + };
1725
1718 - argv++;
1719 - for (i = 1; i < argc; i++) {
1720 - const char *arg = *argv++;
1726 + packet_trace_identity("receive-pack");
1727
1722 - if (*arg == '-') {
1723 - if (!strcmp(arg, "--quiet")) {
1724 - quiet = 1;
1725 - continue;
1726 - }
1728 + argc = parse_options(argc, argv, prefix, options, receive_pack_usage, 0);
1729
1728 - if (!strcmp(arg, "--advertise-refs")) {
1729 - advertise_refs = 1;
1730 - continue;
1731 - }
1732 - if (!strcmp(arg, "--stateless-rpc")) {
1733 - stateless_rpc = 1;
1734 - continue;
1735 - }
1736 - if (!strcmp(arg, "--reject-thin-pack-for-testing")) {
1737 - fix_thin = 0;
1738 - continue;
1739 - }
1730 + if (argc > 1)
1731 + usage_msg_opt(_("Too many arguments."), receive_pack_usage, options);
1732 + if (argc == 0)
1733 + usage_msg_opt(_("You must specify a directory."), receive_pack_usage, options);
1734
1741 - usage(receive_pack_usage);
1742 - }
1743 - if (service_dir)
1744 - usage(receive_pack_usage);
1745 - service_dir = arg;
1746 - }
1747 - if (!service_dir)
1748 - usage(receive_pack_usage);
1735 + service_dir = argv[0];
1736
1737 setup_path();
1738