From: Daniel Barkalow <barkalow@iabervon.org>
To: Junio C Hamano <junkio@cox.net>
Cc: git@vger.kernel.org
Subject: [PATCH] Use parseopts in builtin-fetch
Date: Sun, 4 Nov 2007 22:35:34 -0500 (EST) [thread overview]
Message-ID: <Pine.LNX.4.64.0711042233590.7357@iabervon.org> (raw)
Signed-off-by: Daniel Barkalow <barkalow@iabervon.org>
---
I mostly did this and the next one for practice with the API. I'm
impressed that "git fetch -vv" is even handled correctly without anything
special. Now that I've done it, assuming I did it right, it might as well
get added to the series.
builtin-fetch.c | 95 +++++++++++++++---------------------------------------
1 files changed, 27 insertions(+), 68 deletions(-)
diff --git a/builtin-fetch.c b/builtin-fetch.c
index 6b1750d..a079cb0 100644
--- a/builtin-fetch.c
+++ b/builtin-fetch.c
@@ -8,8 +8,12 @@
#include "path-list.h"
#include "remote.h"
#include "transport.h"
+#include "parse-options.h"
-static const char fetch_usage[] = "git-fetch [-a | --append] [--upload-pack <upload-pack>] [-f | --force] [--no-tags] [-t | --tags] [-k | --keep] [-u | --update-head-ok] [--depth <depth>] [-v | --verbose] [<repository> <refspec>...]";
+static const char * const fetch_usage[] = {
+ "git-fetch [option] [<repository> <refspec>...]",
+ NULL
+};
static int append, force, tags, no_tags, update_head_ok, verbose, quiet;
static char *default_rla = NULL;
@@ -470,71 +474,21 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
int cmd_len = 0;
const char *depth = NULL, *upload_pack = NULL;
int keep = 0;
-
- for (i = 1; i < argc; i++) {
- const char *arg = argv[i];
- cmd_len += strlen(arg);
-
- if (arg[0] != '-')
- break;
- if (!strcmp(arg, "--append") || !strcmp(arg, "-a")) {
- append = 1;
- continue;
- }
- if (!prefixcmp(arg, "--upload-pack=")) {
- upload_pack = arg + 14;
- continue;
- }
- if (!strcmp(arg, "--upload-pack")) {
- i++;
- if (i == argc)
- usage(fetch_usage);
- upload_pack = argv[i];
- continue;
- }
- if (!strcmp(arg, "--force") || !strcmp(arg, "-f")) {
- force = 1;
- continue;
- }
- if (!strcmp(arg, "--no-tags")) {
- no_tags = 1;
- continue;
- }
- if (!strcmp(arg, "--tags") || !strcmp(arg, "-t")) {
- tags = 1;
- continue;
- }
- if (!strcmp(arg, "--keep") || !strcmp(arg, "-k")) {
- keep = 1;
- continue;
- }
- if (!strcmp(arg, "--update-head-ok") || !strcmp(arg, "-u")) {
- update_head_ok = 1;
- continue;
- }
- if (!prefixcmp(arg, "--depth=")) {
- depth = arg + 8;
- continue;
- }
- if (!strcmp(arg, "--depth")) {
- i++;
- if (i == argc)
- usage(fetch_usage);
- depth = argv[i];
- continue;
- }
- if (!strcmp(arg, "--quiet") || !strcmp(arg, "-q")) {
- quiet = 1;
- continue;
- }
- if (!strcmp(arg, "--verbose") || !strcmp(arg, "-v")) {
- verbose++;
- continue;
- }
- usage(fetch_usage);
- }
-
- for (j = i; j < argc; j++)
+ struct option options[] = {
+ OPT__VERBOSE(&verbose),
+ OPT_BOOLEAN('a', "append", &append, "append fetched data to exisitng FETCH_HEAD"),
+ OPT_BOOLEAN('f', "force", &force, "force"),
+ OPT_BOOLEAN( 0 , "no-tags", &no_tags, "don't fetch tags"),
+ OPT_BOOLEAN('t', "tags", &tags, "fetch all tags"),
+ OPT_BOOLEAN('k', "keep", &keep, "keep pack file"),
+ OPT_STRING( 0, "depth", &depth, "depth", "deepen the repository by <depth> commits"),
+ OPT_BOOLEAN('u', "update-head-ok", &update_head_ok, "allow updating head"),
+ OPT_BOOLEAN('q', "quiet", &quiet, "fetch silently"),
+ OPT_STRING( 0 , "upload-pack", &upload_pack, "upload-pack", "remote executable for git-upload-pack"),
+ OPT_END(),
+ };
+
+ for (j = 1; j < argc; j++)
cmd_len += strlen(argv[j]);
default_rla = xmalloc(cmd_len + 5 + argc + 1);
@@ -545,12 +499,16 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
rla_offset += strlen(argv[j]) + 1;
}
- if (i == argc)
+ argc = parse_options(argc, argv, options, fetch_usage, 0);
+
+ if (argc == 0)
remote = remote_get(NULL);
else
- remote = remote_get(argv[i++]);
+ remote = remote_get(argv[0]);
transport = transport_get(remote, remote->url[0]);
+ if (!transport)
+ die("couldn't get transport");
if (verbose >= 2)
transport->verbose = 1;
if (quiet)
@@ -565,6 +523,7 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
if (!transport->url)
die("Where do you want to fetch from today?");
+ i = 1;
if (i < argc) {
int j = 0;
refs = xcalloc(argc - i + 1, sizeof(const char *));
--
1.5.3.5.1528.gb6568-dirty
next reply other threads:[~2007-11-05 3:35 UTC|newest]
Thread overview: 8+ messages / expand[flat|nested] mbox.gz Atom feed top
2007-11-05 3:35 Daniel Barkalow [this message]
2007-11-05 8:43 ` [PATCH] Use parseopts in builtin-fetch Pierre Habouzit
2007-11-05 17:14 ` Daniel Barkalow
2007-11-05 8:55 ` Pierre Habouzit
2007-11-05 17:02 ` Kristian Høgsberg
2007-11-05 17:41 ` Daniel Barkalow
2007-11-05 19:13 ` Junio C Hamano
2007-11-05 19:48 ` Pierre Habouzit
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=Pine.LNX.4.64.0711042233590.7357@iabervon.org \
--to=barkalow@iabervon.org \
--cc=git@vger.kernel.org \
--cc=junkio@cox.net \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).