Signed-off-by: Pierre Habouzit <madcoder@xxxxxxxxxx> --- builtin-http-fetch.c | 65 +++++++++++++++++++++---------------------------- 1 files changed, 28 insertions(+), 37 deletions(-) diff --git a/builtin-http-fetch.c b/builtin-http-fetch.c index 4a50dbd..4b72b62 100644 --- a/builtin-http-fetch.c +++ b/builtin-http-fetch.c @@ -1,65 +1,57 @@ #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__VERBOSE(&get_verbosely), + 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_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 ids from stdin"), + OPT_END(), + }; 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, http_fetch_usage, 0); + if (argc != 2 - commits_on_stdin) { + usage_with_options(http_fetch_usage, 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 +64,5 @@ int cmd_http_fetch(int argc, const char **argv, const char *prefix) } walker_free(walker); - return rc; } -- 1.5.3.4.1231.g62b9a - To unsubscribe from this list: send the line "unsubscribe git" in the body of a message to majordomo@xxxxxxxxxxxxxxx More majordomo info at http://vger.kernel.org/majordomo-info.html