summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: 1d11d5b)
raw | patch | inline | side by side (parent: 1d11d5b)
author | René Scharfe <rene.scharfe@lsrfire.ath.cx> | |
Mon, 14 Jul 2008 19:22:05 +0000 (21:22 +0200) | ||
committer | Junio C Hamano <gitster@pobox.com> | |
Tue, 15 Jul 2008 14:18:04 +0000 (07:18 -0700) |
Replace the code that calls backend specific argument parsers by a
simple flag mechanism. This reduces code size and complexity.
We can add back such a mechanism (based on incremental parse_opt(),
perhaps) when we need it. The compression level parameter, though,
is going to be shared by future compressing backends like tgz.
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
simple flag mechanism. This reduces code size and complexity.
We can add back such a mechanism (based on incremental parse_opt(),
perhaps) when we need it. The compression level parameter, though,
is going to be shared by future compressing backends like tgz.
Signed-off-by: Rene Scharfe <rene.scharfe@lsrfire.ath.cx>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
archive-zip.c | patch | blob | history | |
archive.h | patch | blob | history | |
builtin-archive.c | patch | blob | history |
diff --git a/archive-zip.c b/archive-zip.c
index 81312899bce9966b10da2698bada96a80b196123..d56e5cfc1e4047a2e86a2aeacaafc8fb2931179e 100644 (file)
--- a/archive-zip.c
+++ b/archive-zip.c
return err;
}
-
-void *parse_extra_zip_args(int argc, const char **argv)
-{
- for (; argc > 0; argc--, argv++) {
- const char *arg = argv[0];
-
- if (arg[0] == '-' && isdigit(arg[1]) && arg[2] == '\0')
- zlib_compression_level = arg[1] - '0';
- else
- die("Unknown argument for zip format: %s", arg);
- }
- return NULL;
-}
diff --git a/archive.h b/archive.h
index 88ee3be5420421ccb8dab05688b8ba82ba032fa6..96bb1cd85362e68ee42c81d5017222411e6bf669 100644 (file)
--- a/archive.h
+++ b/archive.h
time_t time;
const char **pathspec;
unsigned int verbose : 1;
- void *extra;
};
typedef int (*write_archive_fn_t)(struct archiver_args *);
-typedef void *(*parse_extra_args_fn_t)(int argc, const char **argv);
-
typedef int (*write_archive_entry_fn_t)(struct archiver_args *args, const unsigned char *sha1, const char *path, size_t pathlen, unsigned int mode, void *buffer, unsigned long size);
struct archiver {
const char *name;
write_archive_fn_t write_archive;
- parse_extra_args_fn_t parse_extra;
+ unsigned int flags;
};
extern int parse_archive_args(int argc, const char **argv, const struct archiver **ar, struct archiver_args *args);
*/
extern int write_tar_archive(struct archiver_args *);
extern int write_zip_archive(struct archiver_args *);
-extern void *parse_extra_zip_args(int argc, const char **argv);
extern int write_archive_entries(struct archiver_args *args, write_archive_entry_fn_t write_entry);
diff --git a/builtin-archive.c b/builtin-archive.c
index e7f4ec634179a1cd23e967752b37e301f093e3ac..88204bf733ebdba79b1ac175da8ec26f6cfec597 100644 (file)
--- a/builtin-archive.c
+++ b/builtin-archive.c
static const char archive_usage[] = \
"git-archive --format=<fmt> [--prefix=<prefix>/] [--verbose] [<extra>] <tree-ish> [path...]";
+#define USES_ZLIB_COMPRESSION 1
+
const struct archiver archivers[] = {
- { "tar", write_tar_archive, NULL },
- { "zip", write_zip_archive, parse_extra_zip_args },
+ { "tar", write_tar_archive },
+ { "zip", write_zip_archive, USES_ZLIB_COMPRESSION },
};
static int run_remote_archiver(const char *remote, int argc,
int parse_archive_args(int argc, const char **argv, const struct archiver **ar,
struct archiver_args *args)
{
- const char *extra_argv[MAX_EXTRA_ARGS];
- int extra_argc = 0;
const char *format = "tar";
const char *base = "";
+ int compression_level = -1;
int verbose = 0;
int i;
@@ -168,12 +169,12 @@ int parse_archive_args(int argc, const char **argv, const struct archiver **ar,
i++;
break;
}
- if (arg[0] == '-') {
- if (extra_argc > MAX_EXTRA_ARGS - 1)
- die("Too many extra options");
- extra_argv[extra_argc++] = arg;
+ if (arg[0] == '-' && isdigit(arg[1]) && arg[2] == '\0') {
+ compression_level = arg[1] - '0';
continue;
}
+ if (arg[0] == '-')
+ die("Unknown argument: %s", arg);
break;
}
@@ -184,11 +185,13 @@ int parse_archive_args(int argc, const char **argv, const struct archiver **ar,
if (!*ar)
die("Unknown archive format '%s'", format);
- if (extra_argc) {
- if (!(*ar)->parse_extra)
- die("'%s' format does not handle %s",
- (*ar)->name, extra_argv[0]);
- args->extra = (*ar)->parse_extra(extra_argc, extra_argv);
+ if (compression_level != -1) {
+ if ((*ar)->flags & USES_ZLIB_COMPRESSION)
+ zlib_compression_level = compression_level;
+ else {
+ die("Argument not supported for format '%s': -%d",
+ format, compression_level);
+ }
}
args->verbose = verbose;
args->base = base;