Show changes to builtin-fetch-pack.c +90 −54
diff --git a/builtin-fetch-pack.c b/builtin-fetch-pack.c
index 273239a..701be41 100644
--- a/builtin-fetch-pack.c
+++ b/builtin-fetch-pack.c
@@ -9,6 +9,7 @@
#include "fetch-pack.h"
#include "remote.h"
#include "run-command.h"
+#include "parse-options.h"
static int transfer_unpack_limit = -1;
static int fetch_unpack_limit = -1;
@@ -17,8 +18,10 @@ static struct fetch_pack_args args = {
/* .uploadpack = */ "git-upload-pack",
};
-static const char fetch_pack_usage[] =
-"git fetch-pack [--all] [--quiet|-q] [--keep|-k] [--thin] [--include-tag] [--upload-pack=<git-upload-pack>] [--depth=<n>] [--no-progress] [-v] [<host>:]<directory> [<refs>...]";
+static const char * const fetch_pack_usage[] = {
+ "git fetch-pack [options] [<host>:]<directory> [<refs>...]",
+ NULL
+};
#define COMPLETE (1U << 0)
#define COMMON (1U << 1)
@@ -667,6 +670,56 @@ static void fetch_pack_setup(void)
did_setup = 1;
}
+static int parse_opt_keep_pack_cb(const struct option *opt, const char *arg, int unset)
+{
+ struct fetch_pack_args *t_args = opt->value;
+ t_args->lock_pack = t_args->keep_pack;
+ t_args->keep_pack = 1;
+ return 0;
+}
+
+static int parse_opt_thin_cb(const struct option *opt, const char *arg, int unset)
+{
+ struct fetch_pack_args *t_args = opt->value;
+ t_args->use_thin_pack = unset ? 0 : 1;
+ return 0;
+}
+
+static int parse_opt_include_tag_cb(const struct option *opt, const char *arg, int unset)
+{
+ struct fetch_pack_args *t_args = opt->value;
+ t_args->include_tag = unset ? 0 : 1;
+ return 0;
+}
+
+static int parse_opt_no_progress_cb(const struct option *opt, const char *arg, int unset)
+{
+ struct fetch_pack_args *t_args = opt->value;
+ t_args->no_progress = 1;
+ return 0;
+}
+
+static int parse_opt_fetch_all_cb(const struct option *opt, const char *arg, int unset)
+{
+ struct fetch_pack_args *t_args = opt->value;
+ t_args->fetch_all = unset ? 0 : 1;
+ return 0;
+}
+
+static int parse_opt_quiet_cb(const struct option *opt, const char *arg, int unset)
+{
+ struct fetch_pack_args *t_args = opt->value;
+ t_args->quiet = unset ? 0 : 1;
+ return 0;
+}
+
+static int parse_opt_verbose_cb(const struct option *opt, const char *arg, int unset)
+{
+ struct fetch_pack_args *t_args = opt->value;
+ t_args->verbose = unset ? 0 : 1;
+ return 0;
+}
+
int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
{
int i, ret, nr_heads;
@@ -677,60 +730,43 @@ int cmd_fetch_pack(int argc, const char **argv, const char *prefix)
nr_heads = 0;
heads = NULL;
- for (i = 1; i < argc; i++) {
- const char *arg = argv[i];
- if (*arg == '-') {
- if (!prefixcmp(arg, "--upload-pack=")) {
- args.uploadpack = arg + 14;
- continue;
- }
- if (!prefixcmp(arg, "--exec=")) {
- args.uploadpack = arg + 7;
- continue;
- }
- if (!strcmp("--quiet", arg) || !strcmp("-q", arg)) {
- args.quiet = 1;
- continue;
- }
- if (!strcmp("--keep", arg) || !strcmp("-k", arg)) {
- args.lock_pack = args.keep_pack;
- args.keep_pack = 1;
- continue;
- }
- if (!strcmp("--thin", arg)) {
- args.use_thin_pack = 1;
- continue;
- }
- if (!strcmp("--include-tag", arg)) {
- args.include_tag = 1;
- continue;
- }
- if (!strcmp("--all", arg)) {
- args.fetch_all = 1;
- continue;
- }
- if (!strcmp("-v", arg)) {
- args.verbose = 1;
- continue;
- }
- if (!prefixcmp(arg, "--depth=")) {
- args.depth = strtol(arg + 8, NULL, 0);
- continue;
- }
- if (!strcmp("--no-progress", arg)) {
- args.no_progress = 1;
- continue;
- }
- usage(fetch_pack_usage);
- }
- dest = (char *)arg;
- heads = (char **)(argv + i + 1);
- nr_heads = argc - i - 1;
- break;
- }
+ const struct option options[] = {
+ { OPTION_CALLBACK, 0, "all", &args, NULL,
+ "fetch all remote refs", PARSE_OPT_NOARG,
+ parse_opt_fetch_all_cb },
+ OPT_STRING(0, "upload-pack", &args.uploadpack, "git-upload-pack",
+ "specify path to git-upload-pack on remote"),
+ OPT_STRING(0, "exec", &args.uploadpack, "git-upload-pack",
+ "same as --upload-pack <git-upload-pack>."),
+ { OPTION_CALLBACK, 0, "no-progress", &args, NULL,
+ "do not show the progress", PARSE_OPT_NOARG | PARSE_OPT_NONEG,
+ parse_opt_no_progress_cb },
+ { OPTION_CALLBACK, 'q', "quiet", &args, NULL,
+ "be quiet", PARSE_OPT_NOARG, parse_opt_quiet_cb },
+ { OPTION_CALLBACK, 'v', "verbose", &args, NULL,
+ "be verbose", PARSE_OPT_NOARG, parse_opt_verbose_cb },
+ OPT_INTEGER(0, "depth", &args.depth, "fetch chains not longer than <n>"),
+ { OPTION_CALLBACK, 'k', "keep", &args, NULL,
+ "create a single packfile of received data",
+ PARSE_OPT_NOARG | PARSE_OPT_NONEG, parse_opt_keep_pack_cb },
+ { OPTION_CALLBACK, 0, "include-tag", &args, NULL,
+ "download annotated tags too", PARSE_OPT_NOARG,
+ parse_opt_include_tag_cb },
+ { OPTION_CALLBACK, 0, "thin", &args, NULL,
+ "minimize number of objects to be sent",
+ PARSE_OPT_NOARG, parse_opt_thin_cb },
+ OPT_END()
+ };
+
+ argc = parse_options(argc, argv, options, fetch_pack_usage, 0);
+
+ dest = (char *)argv[0];
+ heads = (char **)(argv + 1);
+ nr_heads = argc - 1;
+
if (!dest)
- usage(fetch_pack_usage);
+ usage_with_options(fetch_pack_usage, options);
conn = git_connect(fd, (char *)dest, args.uploadpack,
args.verbose ? CONNECT_VERBOSE : 0);