(short) documentation for the testgit remote helper
[git.git] / archive-zip.c
index d56e5cfc1e4047a2e86a2aeacaafc8fb2931179e..02d1f3787acd8d6583073458ab7c8946684f9371 100644 (file)
@@ -2,11 +2,6 @@
  * Copyright (c) 2006 Rene Scharfe
  */
 #include "cache.h"
-#include "commit.h"
-#include "blob.h"
-#include "tree.h"
-#include "quote.h"
-#include "builtin.h"
 #include "archive.h"
 
 static int zip_date;
@@ -93,16 +88,16 @@ static void copy_le32(unsigned char *dest, unsigned int n)
 }
 
 static void *zlib_deflate(void *data, unsigned long size,
-                          unsigned long *compressed_size)
+               int compression_level, unsigned long *compressed_size)
 {
-       z_stream stream;
+       git_zstream stream;
        unsigned long maxsize;
        void *buffer;
        int result;
 
        memset(&stream, 0, sizeof(stream));
-       deflateInit(&stream, zlib_compression_level);
-       maxsize = deflateBound(&stream, size);
+       git_deflate_init(&stream, compression_level);
+       maxsize = git_deflate_bound(&stream, size);
        buffer = xmalloc(maxsize);
 
        stream.next_in = data;
@@ -111,7 +106,7 @@ static void *zlib_deflate(void *data, unsigned long size,
        stream.avail_out = maxsize;
 
        do {
-               result = deflate(&stream, Z_FINISH);
+               result = git_deflate(&stream, Z_FINISH);
        } while (result == Z_OK);
 
        if (result != Z_STREAM_END) {
@@ -119,7 +114,7 @@ static void *zlib_deflate(void *data, unsigned long size,
                return NULL;
        }
 
-       deflateEnd(&stream);
+       git_deflate_end(&stream);
        *compressed_size = stream.total_out;
 
        return buffer;
@@ -157,7 +152,7 @@ static int write_zip_entry(struct archiver_args *args,
                method = 0;
                attr2 = S_ISLNK(mode) ? ((mode | 0777) << 16) :
                        (mode & 0111) ? ((mode) << 16) : 0;
-               if (S_ISREG(mode) && zlib_compression_level != 0)
+               if (S_ISREG(mode) && args->compression_level != 0)
                        method = 8;
                crc = crc32(crc, buffer, size);
                out = buffer;
@@ -169,7 +164,8 @@ static int write_zip_entry(struct archiver_args *args,
        }
 
        if (method == 8) {
-               deflated = zlib_deflate(buffer, size, &compressed_size);
+               deflated = zlib_deflate(buffer, size, args->compression_level,
+                               &compressed_size);
                if (deflated && compressed_size - 6 < size) {
                        /* ZLIB --> raw compressed data (see RFC 1950) */
                        /* CMF and FLG ... */
@@ -265,7 +261,8 @@ static void dos_time(time_t *time, int *dos_date, int *dos_time)
        *dos_time = t->tm_sec / 2 + t->tm_min * 32 + t->tm_hour * 2048;
 }
 
-int write_zip_archive(struct archiver_args *args)
+static int write_zip_archive(const struct archiver *ar,
+                            struct archiver_args *args)
 {
        int err;
 
@@ -282,3 +279,14 @@ int write_zip_archive(struct archiver_args *args)
 
        return err;
 }
+
+static struct archiver zip_archiver = {
+       "zip",
+       write_zip_archive,
+       ARCHIVER_WANT_COMPRESSION_LEVELS|ARCHIVER_REMOTE
+};
+
+void init_zip_archiver(void)
+{
+       register_archiver(&zip_archiver);
+}