git.vger.kernel.org archive mirror
 help / color / mirror / Atom feed
* [PATCH] builtin/receive-pack.c: use parse_options API
@ 2016-03-01 15:36 Sidhant Sharma [:tk]
  2016-03-01 17:22 ` Matthieu Moy
  2016-03-01 20:21 ` [PATCH v2] " Sidhant Sharma [:tk]
  0 siblings, 2 replies; 14+ messages in thread
From: Sidhant Sharma [:tk] @ 2016-03-01 15:36 UTC (permalink / raw)
  To: git; +Cc: matthieu.moy

This patch makes 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>
---
 builtin/receive-pack.c | 55 ++++++++++++++++++++++----------------------------
 1 file changed, 24 insertions(+), 31 deletions(-)

diff --git a/builtin/receive-pack.c b/builtin/receive-pack.c
index c8e32b2..fe9a594 100644
--- a/builtin/receive-pack.c
+++ b/builtin/receive-pack.c
@@ -21,7 +21,10 @@
 #include "sigchain.h"
 #include "fsck.h"

-static const char receive_pack_usage[] = "git receive-pack <git-dir>";
+static const char * const receive_pack_usage[] = {
+	N_("git receive-pack <git-dir>"),
+	NULL
+};

 enum deny_action {
 	DENY_UNCONFIGURED,
@@ -45,12 +48,12 @@ static int unpack_limit = 100;
 static int report_status;
 static int use_sideband;
 static int use_atomic;
-static int quiet;
+static int quiet = 0;
 static int prefer_ofs_delta = 1;
 static int auto_update_server_info;
 static int auto_gc = 1;
 static int fix_thin = 1;
-static int stateless_rpc;
+static int stateless_rpc = 0;
 static const char *service_dir;
 static const char *head_name;
 static void *head_name_to_free;
@@ -1707,45 +1710,35 @@ static int delete_only(struct command *commands)
 int cmd_receive_pack(int argc, const char **argv, const char *prefix)
 {
 	int advertise_refs = 0;
-	int i;
 	struct command *commands;
 	struct sha1_array shallow = SHA1_ARRAY_INIT;
 	struct sha1_array ref = SHA1_ARRAY_INIT;
 	struct shallow_info si;
+	struct option options[] = {
+		OPT__QUIET(&quiet, N_("quiet")),
+		OPT_HIDDEN_BOOL(0, "stateless-rpc", &stateless_rpc, NULL),
+		OPT_HIDDEN_BOOL(0, "advertise-refs", &advertise_refs, NULL),
+		/* Hidden OPT_BOOL option */
+		{
+			OPTION_SET_INT, 0, "reject-thin-pack-for-testing", &fix_thin, NULL,
+			NULL, PARSE_OPT_NOARG | PARSE_OPT_HIDDEN, NULL, 0,
+		},
+		OPT_END()
+	};

 	packet_trace_identity("receive-pack");

-	argv++;
-	for (i = 1; i < argc; i++) {
-		const char *arg = *argv++;
+	argc = parse_options(argc, argv, prefix, options, receive_pack_usage, 0);

-		if (*arg == '-') {
-			if (!strcmp(arg, "--quiet")) {
-				quiet = 1;
-				continue;
-			}
+	if (argc > 1)
+		usage_msg_opt(_("Too many arguments."), receive_pack_usage, options);
+	if (argc == 0)
+		usage_msg_opt(_("You must specify a directory."), receive_pack_usage, options);

-			if (!strcmp(arg, "--advertise-refs")) {
-				advertise_refs = 1;
-				continue;
-			}
-			if (!strcmp(arg, "--stateless-rpc")) {
-				stateless_rpc = 1;
-				continue;
-			}
-			if (!strcmp(arg, "--reject-thin-pack-for-testing")) {
-				fix_thin = 0;
-				continue;
-			}
+	service_dir = argv[0];

-			usage(receive_pack_usage);
-		}
-		if (service_dir)
-			usage(receive_pack_usage);
-		service_dir = arg;
-	}
 	if (!service_dir)
-		usage(receive_pack_usage);
+		usage_with_options(receive_pack_usage, options);

 	setup_path();

--
2.6.2

^ permalink raw reply related	[flat|nested] 14+ messages in thread

end of thread, other threads:[~2016-03-02 13:54 UTC | newest]

Thread overview: 14+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2016-03-01 15:36 [PATCH] builtin/receive-pack.c: use parse_options API Sidhant Sharma [:tk]
2016-03-01 17:22 ` Matthieu Moy
2016-03-01 17:48   ` Sidhant Sharma
2016-03-01 17:57     ` Matthieu Moy
2016-03-01 18:54       ` Eric Sunshine
2016-03-01 20:21 ` [PATCH v2] " Sidhant Sharma [:tk]
2016-03-01 20:31   ` Sidhant Sharma
2016-03-01 20:39   ` Matthieu Moy
2016-03-01 22:05     ` Junio C Hamano
2016-03-02  5:18       ` Sidhant Sharma
2016-03-02  8:51         ` Junio C Hamano
2016-03-02  8:23       ` Matthieu Moy
2016-03-02  9:53   ` Duy Nguyen
2016-03-02 13:53     ` Sidhant Sharma

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).