[PATCH] Make builtin-http-fetch use parse_options.

!MAILaRCHIVE_VOTE_RePLACE
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]
To: <git@...>, Junio C Hamano <gitster@...>
Cc: Pierre Habouzit <madcoder@...>, <git@...>
Date: Saturday, October 13, 2007 - 9:29 am

Signed-off-by: Pierre Habouzit <madcoder@debian.org>
---
 builtin-http-fetch.c |   67 ++++++++++++++++++++++---------------------------
 1 files changed, 30 insertions(+), 37 deletions(-)

diff --git a/builtin-http-fetch.c b/builtin-http-fetch.c
index 4a50dbd..5e1003e 100644
--- a/builtin-http-fetch.c
+++ b/builtin-http-fetch.c
@@ -1,65 +1,59 @@
 #include "cache.h"
 #include "walker.h"
+#include "parse-options.h"
+
+static char const * const http_fetch_usage[] = {
+	"git-http-fetch [option] (--stdin | <commit-id>) url",
+	NULL
+};
 
 int cmd_http_fetch(int argc, const char **argv, const char *prefix)
 {
 	struct walker *walker;
 	int commits_on_stdin = 0;
 	int commits;
-	const char **write_ref = NULL;
+	const char *wref = NULL, **write_ref = NULL;
 	char **commit_id;
-	const char *url;
-	int arg = 1;
 	int rc = 0;
-	int get_tree = 0;
-	int get_history = 0;
-	int get_all = 0;
+	int get_tree = 0, get_history = 0, get_all = 0;
 	int get_verbosely = 0;
 	int get_recover = 0;
+	struct option http_fetch_options[] = {
+		OPT_BOOLEAN('c', NULL, &get_history, "get the commit objects"),
+		OPT_BOOLEAN('t', NULL, &get_tree, "get the trees"),
+		OPT_BOOLEAN('a', NULL, &get_all, "get all the objects"),
+		OPT_BOOLEAN('v', "verbose", &get_verbosely, "be verbose"),
+		OPT_STRING( 'w', NULL, &wref, "file",
+					"write the commit-id into a $GIT/refs/<file>"),
+		OPT_BOOLEAN( 0 , "recover", &get_recover, "recover from an interrupted fetch"),
+		OPT_BOOLEAN( 0 , "stdin", &commits_on_stdin, "read the commit id's from stdin"),
+	};
 
 	git_config(git_default_config);
-
-	while (arg < argc && argv[arg][0] == '-') {
-		if (argv[arg][1] == 't') {
-			get_tree = 1;
-		} else if (argv[arg][1] == 'c') {
-			get_history = 1;
-		} else if (argv[arg][1] == 'a') {
-			get_all = 1;
-			get_tree = 1;
-			get_history = 1;
-		} else if (argv[arg][1] == 'v') {
-			get_verbosely = 1;
-		} else if (argv[arg][1] == 'w') {
-			write_ref = &argv[arg + 1];
-			arg++;
-		} else if (!strcmp(argv[arg], "--recover")) {
-			get_recover = 1;
-		} else if (!strcmp(argv[arg], "--stdin")) {
-			commits_on_stdin = 1;
-		}
-		arg++;
-	}
-	if (argc < arg + 2 - commits_on_stdin) {
-		usage("git-http-fetch [-c] [-t] [-a] [-v] [--recover] [-w ref] [--stdin] commit-id url");
+	argc = parse_options(argc, argv, http_fetch_options,
+	                     ARRAY_SIZE(http_fetch_options),
+	                     http_fetch_usage, 0);
+	if (argc != 2 - commits_on_stdin) {
+		make_usage(http_fetch_usage, http_fetch_options,
+				   ARRAY_SIZE(http_fetch_options));
 		return 1;
 	}
 	if (commits_on_stdin) {
 		commits = walker_targets_stdin(&commit_id, &write_ref);
 	} else {
-		commit_id = (char **) &argv[arg++];
+		commit_id = (char **)argv++;
+		write_ref = &wref;
 		commits = 1;
 	}
-	url = argv[arg];
 
-	walker = get_http_walker(url);
-	walker->get_tree = get_tree;
-	walker->get_history = get_history;
+	walker = get_http_walker(argv[0]);
+	walker->get_tree = get_tree | get_all;
+	walker->get_history = get_history | get_all;
 	walker->get_all = get_all;
 	walker->get_verbosely = get_verbosely;
 	walker->get_recover = get_recover;
 
-	rc = walker_fetch(walker, commits, commit_id, write_ref, url);
+	rc = walker_fetch(walker, commits, commit_id, write_ref, argv[0]);
 
 	if (commits_on_stdin)
 		walker_targets_free(commits, commit_id, write_ref);
@@ -72,6 +66,5 @@ int cmd_http_fetch(int argc, const char **argv, const char *prefix)
 	}
 
 	walker_free(walker);
-
 	return rc;
 }
-- 
1.5.3.GIT

-
To unsubscribe from this list: send the line "unsubscribe git" in
the body of a message to majordomo@vger.kernel.org
More majordomo info at  http://vger.kernel.org/majordomo-info.html
Previous message: [thread] [date] [author]
Next message: [thread] [date] [author]

Messages in current thread:
[RFC] CLI option parsing and usage generation for porcelains, Pierre Habouzit, (Sat Oct 13, 9:29 am)
[PATCH] parse-options: Allow abbreviated options when unambi..., Johannes Schindelin, (Sun Oct 14, 12:54 pm)
Re: [PATCH] parse-options: Allow abbreviated options when un..., Johannes Schindelin, (Sun Oct 14, 2:02 pm)
Re: [PATCH] parse-options: Allow abbreviated options when un..., Johannes Schindelin, (Sun Oct 14, 6:12 pm)
git-svn and submodules, was Re: [PATCH] parse-options: Allow..., Johannes Schindelin, (Sun Oct 14, 6:59 pm)
Re: git-svn and submodules, Benoit SIGOURE, (Mon Oct 15, 3:07 am)
Re: git-svn and submodules, Linus Torvalds, (Mon Oct 15, 11:53 am)
Re: git-svn and submodules, Karl , (Mon Oct 15, 10:45 am)
.gitignore and svn:ignore [WAS: git-svn and submodules], Chris Shoemaker, (Mon Oct 15, 11:14 am)
Re: .gitignore and svn:ignore [WAS: git-svn and submodules], Chris Shoemaker, (Tue Oct 16, 9:05 am)
Re: git-svn and submodules, Andreas Ericsson, (Mon Oct 15, 6:00 am)
Re: git-svn and submodules, Benoit SIGOURE, (Mon Oct 15, 6:51 am)
Re: [RFC] CLI option parsing and usage generation for porcel..., Wincent Colaiuta, (Sat Oct 13, 10:53 am)
[PATCH] Add a simple option parser., Pierre Habouzit, (Sat Oct 13, 9:29 am)
Re: [PATCH] Add a simple option parser., Alex Riesen, (Sat Oct 13, 3:16 pm)
Re: [PATCH] Add a simple option parser., Pierre Habouzit, (Sat Oct 13, 4:54 pm)
Re: [PATCH] Add a simple option parser., Alex Riesen, (Sat Oct 13, 6:14 pm)
Re: [PATCH] Add a simple option parser., Pierre Habouzit, (Sun Oct 14, 3:02 am)
Re: [PATCH] Add a simple option parser., Johannes Schindelin, (Sat Oct 13, 10:39 am)
Re: [PATCH] Add a simple option parser., Pierre Habouzit, (Sat Oct 13, 10:58 am)
[PATCH] Port builtin-add.c to use the new option parser., Pierre Habouzit, (Sat Oct 13, 9:29 am)
Re: [PATCH] Port builtin-add.c to use the new option parser., Johannes Schindelin, (Sat Oct 13, 10:47 am)
Re: [PATCH] Port builtin-add.c to use the new option parser., Pierre Habouzit, (Sat Oct 13, 11:03 am)
Re: [PATCH] Port builtin-add.c to use the new option parser., Pierre Habouzit, (Sat Oct 13, 4:27 pm)
[PATCH] Make builtin-rm use parse_options., Pierre Habouzit, (Sat Oct 13, 9:29 am)
[PATCH] Make builtin-mv use parse-options, Pierre Habouzit, (Sat Oct 13, 9:29 am)
[PATCH] Make builtin-branch.c use parse_options., Pierre Habouzit, (Sat Oct 13, 9:29 am)
[PATCH] Make builtin-describe use parse_options, Pierre Habouzit, (Sat Oct 13, 9:29 am)
[PATCH] Make git-fetch use parse_options., Pierre Habouzit, (Sat Oct 13, 9:29 am)
[PATCH] Make builtin-revert.c use parse_options., Pierre Habouzit, (Sat Oct 13, 9:29 am)
[PATCH] Make builtin-update-ref.c use parse_options, Pierre Habouzit, (Sat Oct 13, 9:29 am)
[PATCH] Simplify usage string printing, Jonas Fonseca, (Sun Oct 14, 10:01 am)
Re: [PATCH] Simplify usage string printing, Pierre Habouzit, (Sun Oct 14, 12:26 pm)
[PATCH] Make builtin-symbolic-ref.c use parse_options., Pierre Habouzit, (Sat Oct 13, 9:29 am)
[PATCH] Make builtin-http-fetch use parse_options., Pierre Habouzit, (Sat Oct 13, 9:29 am)