summaryrefslogtreecommitdiff
path: root/archive.c
diff options
context:
space:
mode:
authorJeff King <peff@peff.net>2011-06-22 01:23:33 (GMT)
committerJunio C Hamano <gitster@pobox.com>2011-06-22 18:12:35 (GMT)
commit13e0f88d4aba326da9217c225d6ab5e642eb611d (patch)
treeaf7e13e62c420620946b152ea383f680d6105a94 /archive.c
parent40e7629194c79e72009b5b8e98cce65921b0faf2 (diff)
downloadgit-13e0f88d4aba326da9217c225d6ab5e642eb611d.zip
git-13e0f88d4aba326da9217c225d6ab5e642eb611d.tar.gz
git-13e0f88d4aba326da9217c225d6ab5e642eb611d.tar.bz2
archive: refactor list of archive formats
Most of the tar and zip code was nicely split out into two abstracted files which knew only about their specific formats. The entry point to this code was a single "write archive" function. However, as these basic formats grow more complex (e.g., by handling multiple file extensions and format names), a static list of the entry point functions won't be enough. Instead, let's provide a way for the tar and zip code to tell the main archive code what they support by registering archiver names and functions. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Diffstat (limited to 'archive.c')
-rw-r--r--archive.c33
1 files changed, 17 insertions, 16 deletions
diff --git a/archive.c b/archive.c
index 2616676..f0b4e85 100644
--- a/archive.c
+++ b/archive.c
@@ -14,16 +14,15 @@ static char const * const archive_usage[] = {
NULL
};
-#define USES_ZLIB_COMPRESSION 1
-
-static const struct archiver {
- const char *name;
- write_archive_fn_t write_archive;
- unsigned int flags;
-} archivers[] = {
- { "tar", write_tar_archive },
- { "zip", write_zip_archive, USES_ZLIB_COMPRESSION },
-};
+static const struct archiver **archivers;
+static int nr_archivers;
+static int alloc_archivers;
+
+void register_archiver(struct archiver *ar)
+{
+ ALLOC_GROW(archivers, nr_archivers + 1, alloc_archivers);
+ archivers[nr_archivers++] = ar;
+}
static void format_subst(const struct commit *commit,
const char *src, size_t len,
@@ -208,9 +207,9 @@ static const struct archiver *lookup_archiver(const char *name)
if (!name)
return NULL;
- for (i = 0; i < ARRAY_SIZE(archivers); i++) {
- if (!strcmp(name, archivers[i].name))
- return &archivers[i];
+ for (i = 0; i < nr_archivers; i++) {
+ if (!strcmp(name, archivers[i]->name))
+ return archivers[i];
}
return NULL;
}
@@ -355,8 +354,8 @@ static int parse_archive_args(int argc, const char **argv,
base = "";
if (list) {
- for (i = 0; i < ARRAY_SIZE(archivers); i++)
- printf("%s\n", archivers[i].name);
+ for (i = 0; i < nr_archivers; i++)
+ printf("%s\n", archivers[i]->name);
exit(0);
}
@@ -369,7 +368,7 @@ static int parse_archive_args(int argc, const char **argv,
args->compression_level = Z_DEFAULT_COMPRESSION;
if (compression_level != -1) {
- if ((*ar)->flags & USES_ZLIB_COMPRESSION)
+ if ((*ar)->flags & ARCHIVER_WANT_COMPRESSION_LEVELS)
args->compression_level = compression_level;
else {
die("Argument not supported for format '%s': -%d",
@@ -395,6 +394,8 @@ int write_archive(int argc, const char **argv, const char *prefix,
prefix = setup_git_directory_gently(&nongit);
git_config(git_default_config, NULL);
+ init_tar_archiver();
+ init_zip_archiver();
argc = parse_archive_args(argc, argv, &ar, &args);
if (nongit) {