THIS IS A TEST INSTANCE ONLY! REPOSITORIES CAN BE DELETED AT ANY TIME!

Git Source Code Mirror - This is a publish-only repository and all pull requests are ignored. Please follow Documentation/SubmittingPatches procedure for any of your improvements.
git
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

655 lines
17KB

  1. /*
  2. * Copyright (c) 2006 Rene Scharfe
  3. */
  4. #include "cache.h"
  5. #include "config.h"
  6. #include "archive.h"
  7. #include "streaming.h"
  8. #include "utf8.h"
  9. #include "object-store.h"
  10. #include "userdiff.h"
  11. #include "xdiff-interface.h"
  12. static int zip_date;
  13. static int zip_time;
  14. /* We only care about the "buf" part here. */
  15. static struct strbuf zip_dir;
  16. static uintmax_t zip_offset;
  17. static uint64_t zip_dir_entries;
  18. static unsigned int max_creator_version;
  19. #define ZIP_STREAM (1 << 3)
  20. #define ZIP_UTF8 (1 << 11)
  21. struct zip_local_header {
  22. unsigned char magic[4];
  23. unsigned char version[2];
  24. unsigned char flags[2];
  25. unsigned char compression_method[2];
  26. unsigned char mtime[2];
  27. unsigned char mdate[2];
  28. unsigned char crc32[4];
  29. unsigned char compressed_size[4];
  30. unsigned char size[4];
  31. unsigned char filename_length[2];
  32. unsigned char extra_length[2];
  33. unsigned char _end[1];
  34. };
  35. struct zip_data_desc {
  36. unsigned char magic[4];
  37. unsigned char crc32[4];
  38. unsigned char compressed_size[4];
  39. unsigned char size[4];
  40. unsigned char _end[1];
  41. };
  42. struct zip64_data_desc {
  43. unsigned char magic[4];
  44. unsigned char crc32[4];
  45. unsigned char compressed_size[8];
  46. unsigned char size[8];
  47. unsigned char _end[1];
  48. };
  49. struct zip_dir_trailer {
  50. unsigned char magic[4];
  51. unsigned char disk[2];
  52. unsigned char directory_start_disk[2];
  53. unsigned char entries_on_this_disk[2];
  54. unsigned char entries[2];
  55. unsigned char size[4];
  56. unsigned char offset[4];
  57. unsigned char comment_length[2];
  58. unsigned char _end[1];
  59. };
  60. struct zip_extra_mtime {
  61. unsigned char magic[2];
  62. unsigned char extra_size[2];
  63. unsigned char flags[1];
  64. unsigned char mtime[4];
  65. unsigned char _end[1];
  66. };
  67. struct zip64_extra {
  68. unsigned char magic[2];
  69. unsigned char extra_size[2];
  70. unsigned char size[8];
  71. unsigned char compressed_size[8];
  72. unsigned char _end[1];
  73. };
  74. struct zip64_dir_trailer {
  75. unsigned char magic[4];
  76. unsigned char record_size[8];
  77. unsigned char creator_version[2];
  78. unsigned char version[2];
  79. unsigned char disk[4];
  80. unsigned char directory_start_disk[4];
  81. unsigned char entries_on_this_disk[8];
  82. unsigned char entries[8];
  83. unsigned char size[8];
  84. unsigned char offset[8];
  85. unsigned char _end[1];
  86. };
  87. struct zip64_dir_trailer_locator {
  88. unsigned char magic[4];
  89. unsigned char disk[4];
  90. unsigned char offset[8];
  91. unsigned char number_of_disks[4];
  92. unsigned char _end[1];
  93. };
  94. /*
  95. * On ARM, padding is added at the end of the struct, so a simple
  96. * sizeof(struct ...) reports two bytes more than the payload size
  97. * we're interested in.
  98. */
  99. #define ZIP_LOCAL_HEADER_SIZE offsetof(struct zip_local_header, _end)
  100. #define ZIP_DATA_DESC_SIZE offsetof(struct zip_data_desc, _end)
  101. #define ZIP64_DATA_DESC_SIZE offsetof(struct zip64_data_desc, _end)
  102. #define ZIP_DIR_HEADER_SIZE offsetof(struct zip_dir_header, _end)
  103. #define ZIP_DIR_TRAILER_SIZE offsetof(struct zip_dir_trailer, _end)
  104. #define ZIP_EXTRA_MTIME_SIZE offsetof(struct zip_extra_mtime, _end)
  105. #define ZIP_EXTRA_MTIME_PAYLOAD_SIZE \
  106. (ZIP_EXTRA_MTIME_SIZE - offsetof(struct zip_extra_mtime, flags))
  107. #define ZIP64_EXTRA_SIZE offsetof(struct zip64_extra, _end)
  108. #define ZIP64_EXTRA_PAYLOAD_SIZE \
  109. (ZIP64_EXTRA_SIZE - offsetof(struct zip64_extra, size))
  110. #define ZIP64_DIR_TRAILER_SIZE offsetof(struct zip64_dir_trailer, _end)
  111. #define ZIP64_DIR_TRAILER_RECORD_SIZE \
  112. (ZIP64_DIR_TRAILER_SIZE - \
  113. offsetof(struct zip64_dir_trailer, creator_version))
  114. #define ZIP64_DIR_TRAILER_LOCATOR_SIZE \
  115. offsetof(struct zip64_dir_trailer_locator, _end)
  116. static void copy_le16(unsigned char *dest, unsigned int n)
  117. {
  118. dest[0] = 0xff & n;
  119. dest[1] = 0xff & (n >> 010);
  120. }
  121. static void copy_le32(unsigned char *dest, unsigned int n)
  122. {
  123. dest[0] = 0xff & n;
  124. dest[1] = 0xff & (n >> 010);
  125. dest[2] = 0xff & (n >> 020);
  126. dest[3] = 0xff & (n >> 030);
  127. }
  128. static void copy_le64(unsigned char *dest, uint64_t n)
  129. {
  130. dest[0] = 0xff & n;
  131. dest[1] = 0xff & (n >> 010);
  132. dest[2] = 0xff & (n >> 020);
  133. dest[3] = 0xff & (n >> 030);
  134. dest[4] = 0xff & (n >> 040);
  135. dest[5] = 0xff & (n >> 050);
  136. dest[6] = 0xff & (n >> 060);
  137. dest[7] = 0xff & (n >> 070);
  138. }
  139. static uint64_t clamp_max(uint64_t n, uint64_t max, int *clamped)
  140. {
  141. if (n <= max)
  142. return n;
  143. *clamped = 1;
  144. return max;
  145. }
  146. static void copy_le16_clamp(unsigned char *dest, uint64_t n, int *clamped)
  147. {
  148. copy_le16(dest, clamp_max(n, 0xffff, clamped));
  149. }
  150. static void copy_le32_clamp(unsigned char *dest, uint64_t n, int *clamped)
  151. {
  152. copy_le32(dest, clamp_max(n, 0xffffffff, clamped));
  153. }
  154. static int strbuf_add_le(struct strbuf *sb, size_t size, uintmax_t n)
  155. {
  156. while (size-- > 0) {
  157. strbuf_addch(sb, n & 0xff);
  158. n >>= 8;
  159. }
  160. return -!!n;
  161. }
  162. static uint32_t clamp32(uintmax_t n)
  163. {
  164. const uintmax_t max = 0xffffffff;
  165. return (n < max) ? n : max;
  166. }
  167. static void *zlib_deflate_raw(void *data, unsigned long size,
  168. int compression_level,
  169. unsigned long *compressed_size)
  170. {
  171. git_zstream stream;
  172. unsigned long maxsize;
  173. void *buffer;
  174. int result;
  175. git_deflate_init_raw(&stream, compression_level);
  176. maxsize = git_deflate_bound(&stream, size);
  177. buffer = xmalloc(maxsize);
  178. stream.next_in = data;
  179. stream.avail_in = size;
  180. stream.next_out = buffer;
  181. stream.avail_out = maxsize;
  182. do {
  183. result = git_deflate(&stream, Z_FINISH);
  184. } while (result == Z_OK);
  185. if (result != Z_STREAM_END) {
  186. free(buffer);
  187. return NULL;
  188. }
  189. git_deflate_end(&stream);
  190. *compressed_size = stream.total_out;
  191. return buffer;
  192. }
  193. static void write_zip_data_desc(unsigned long size,
  194. unsigned long compressed_size,
  195. unsigned long crc)
  196. {
  197. if (size >= 0xffffffff || compressed_size >= 0xffffffff) {
  198. struct zip64_data_desc trailer;
  199. copy_le32(trailer.magic, 0x08074b50);
  200. copy_le32(trailer.crc32, crc);
  201. copy_le64(trailer.compressed_size, compressed_size);
  202. copy_le64(trailer.size, size);
  203. write_or_die(1, &trailer, ZIP64_DATA_DESC_SIZE);
  204. zip_offset += ZIP64_DATA_DESC_SIZE;
  205. } else {
  206. struct zip_data_desc trailer;
  207. copy_le32(trailer.magic, 0x08074b50);
  208. copy_le32(trailer.crc32, crc);
  209. copy_le32(trailer.compressed_size, compressed_size);
  210. copy_le32(trailer.size, size);
  211. write_or_die(1, &trailer, ZIP_DATA_DESC_SIZE);
  212. zip_offset += ZIP_DATA_DESC_SIZE;
  213. }
  214. }
  215. static void set_zip_header_data_desc(struct zip_local_header *header,
  216. unsigned long size,
  217. unsigned long compressed_size,
  218. unsigned long crc)
  219. {
  220. copy_le32(header->crc32, crc);
  221. copy_le32(header->compressed_size, compressed_size);
  222. copy_le32(header->size, size);
  223. }
  224. static int has_only_ascii(const char *s)
  225. {
  226. for (;;) {
  227. int c = *s++;
  228. if (c == '\0')
  229. return 1;
  230. if (!isascii(c))
  231. return 0;
  232. }
  233. }
  234. static int entry_is_binary(struct index_state *istate, const char *path,
  235. const void *buffer, size_t size)
  236. {
  237. struct userdiff_driver *driver = userdiff_find_by_path(istate, path);
  238. if (!driver)
  239. driver = userdiff_find_by_name("default");
  240. if (driver->binary != -1)
  241. return driver->binary;
  242. return buffer_is_binary(buffer, size);
  243. }
  244. #define STREAM_BUFFER_SIZE (1024 * 16)
  245. static int write_zip_entry(struct archiver_args *args,
  246. const struct object_id *oid,
  247. const char *path, size_t pathlen,
  248. unsigned int mode)
  249. {
  250. struct zip_local_header header;
  251. uintmax_t offset = zip_offset;
  252. struct zip_extra_mtime extra;
  253. struct zip64_extra extra64;
  254. size_t header_extra_size = ZIP_EXTRA_MTIME_SIZE;
  255. int need_zip64_extra = 0;
  256. unsigned long attr2;
  257. unsigned long compressed_size;
  258. unsigned long crc;
  259. int method;
  260. unsigned char *out;
  261. void *deflated = NULL;
  262. void *buffer;
  263. struct git_istream *stream = NULL;
  264. unsigned long flags = 0;
  265. unsigned long size;
  266. int is_binary = -1;
  267. const char *path_without_prefix = path + args->baselen;
  268. unsigned int creator_version = 0;
  269. unsigned int version_needed = 10;
  270. size_t zip_dir_extra_size = ZIP_EXTRA_MTIME_SIZE;
  271. size_t zip64_dir_extra_payload_size = 0;
  272. crc = crc32(0, NULL, 0);
  273. if (!has_only_ascii(path)) {
  274. if (is_utf8(path))
  275. flags |= ZIP_UTF8;
  276. else
  277. warning(_("path is not valid UTF-8: %s"), path);
  278. }
  279. if (pathlen > 0xffff) {
  280. return error(_("path too long (%d chars, SHA1: %s): %s"),
  281. (int)pathlen, oid_to_hex(oid), path);
  282. }
  283. if (S_ISDIR(mode) || S_ISGITLINK(mode)) {
  284. method = 0;
  285. attr2 = 16;
  286. out = NULL;
  287. size = 0;
  288. compressed_size = 0;
  289. buffer = NULL;
  290. } else if (S_ISREG(mode) || S_ISLNK(mode)) {
  291. enum object_type type = oid_object_info(args->repo, oid,
  292. &size);
  293. method = 0;
  294. attr2 = S_ISLNK(mode) ? ((mode | 0777) << 16) :
  295. (mode & 0111) ? ((mode) << 16) : 0;
  296. if (S_ISLNK(mode) || (mode & 0111))
  297. creator_version = 0x0317;
  298. if (S_ISREG(mode) && args->compression_level != 0 && size > 0)
  299. method = 8;
  300. if (S_ISREG(mode) && type == OBJ_BLOB && !args->convert &&
  301. size > big_file_threshold) {
  302. stream = open_istream(oid, &type, &size, NULL);
  303. if (!stream)
  304. return error(_("cannot stream blob %s"),
  305. oid_to_hex(oid));
  306. flags |= ZIP_STREAM;
  307. out = buffer = NULL;
  308. } else {
  309. buffer = object_file_to_archive(args, path, oid, mode,
  310. &type, &size);
  311. if (!buffer)
  312. return error(_("cannot read %s"),
  313. oid_to_hex(oid));
  314. crc = crc32(crc, buffer, size);
  315. is_binary = entry_is_binary(args->repo->index,
  316. path_without_prefix,
  317. buffer, size);
  318. out = buffer;
  319. }
  320. compressed_size = (method == 0) ? size : 0;
  321. } else {
  322. return error(_("unsupported file mode: 0%o (SHA1: %s)"), mode,
  323. oid_to_hex(oid));
  324. }
  325. if (creator_version > max_creator_version)
  326. max_creator_version = creator_version;
  327. if (buffer && method == 8) {
  328. out = deflated = zlib_deflate_raw(buffer, size,
  329. args->compression_level,
  330. &compressed_size);
  331. if (!out || compressed_size >= size) {
  332. out = buffer;
  333. method = 0;
  334. compressed_size = size;
  335. }
  336. }
  337. copy_le16(extra.magic, 0x5455);
  338. copy_le16(extra.extra_size, ZIP_EXTRA_MTIME_PAYLOAD_SIZE);
  339. extra.flags[0] = 1; /* just mtime */
  340. copy_le32(extra.mtime, args->time);
  341. if (size > 0xffffffff || compressed_size > 0xffffffff)
  342. need_zip64_extra = 1;
  343. if (stream && size > 0x7fffffff)
  344. need_zip64_extra = 1;
  345. if (need_zip64_extra)
  346. version_needed = 45;
  347. copy_le32(header.magic, 0x04034b50);
  348. copy_le16(header.version, version_needed);
  349. copy_le16(header.flags, flags);
  350. copy_le16(header.compression_method, method);
  351. copy_le16(header.mtime, zip_time);
  352. copy_le16(header.mdate, zip_date);
  353. if (need_zip64_extra) {
  354. set_zip_header_data_desc(&header, 0xffffffff, 0xffffffff, crc);
  355. header_extra_size += ZIP64_EXTRA_SIZE;
  356. } else {
  357. set_zip_header_data_desc(&header, size, compressed_size, crc);
  358. }
  359. copy_le16(header.filename_length, pathlen);
  360. copy_le16(header.extra_length, header_extra_size);
  361. write_or_die(1, &header, ZIP_LOCAL_HEADER_SIZE);
  362. zip_offset += ZIP_LOCAL_HEADER_SIZE;
  363. write_or_die(1, path, pathlen);
  364. zip_offset += pathlen;
  365. write_or_die(1, &extra, ZIP_EXTRA_MTIME_SIZE);
  366. zip_offset += ZIP_EXTRA_MTIME_SIZE;
  367. if (need_zip64_extra) {
  368. copy_le16(extra64.magic, 0x0001);
  369. copy_le16(extra64.extra_size, ZIP64_EXTRA_PAYLOAD_SIZE);
  370. copy_le64(extra64.size, size);
  371. copy_le64(extra64.compressed_size, compressed_size);
  372. write_or_die(1, &extra64, ZIP64_EXTRA_SIZE);
  373. zip_offset += ZIP64_EXTRA_SIZE;
  374. }
  375. if (stream && method == 0) {
  376. unsigned char buf[STREAM_BUFFER_SIZE];
  377. ssize_t readlen;
  378. for (;;) {
  379. readlen = read_istream(stream, buf, sizeof(buf));
  380. if (readlen <= 0)
  381. break;
  382. crc = crc32(crc, buf, readlen);
  383. if (is_binary == -1)
  384. is_binary = entry_is_binary(args->repo->index,
  385. path_without_prefix,
  386. buf, readlen);
  387. write_or_die(1, buf, readlen);
  388. }
  389. close_istream(stream);
  390. if (readlen)
  391. return readlen;
  392. compressed_size = size;
  393. zip_offset += compressed_size;
  394. write_zip_data_desc(size, compressed_size, crc);
  395. } else if (stream && method == 8) {
  396. unsigned char buf[STREAM_BUFFER_SIZE];
  397. ssize_t readlen;
  398. git_zstream zstream;
  399. int result;
  400. size_t out_len;
  401. unsigned char compressed[STREAM_BUFFER_SIZE * 2];
  402. git_deflate_init_raw(&zstream, args->compression_level);
  403. compressed_size = 0;
  404. zstream.next_out = compressed;
  405. zstream.avail_out = sizeof(compressed);
  406. for (;;) {
  407. readlen = read_istream(stream, buf, sizeof(buf));
  408. if (readlen <= 0)
  409. break;
  410. crc = crc32(crc, buf, readlen);
  411. if (is_binary == -1)
  412. is_binary = entry_is_binary(args->repo->index,
  413. path_without_prefix,
  414. buf, readlen);
  415. zstream.next_in = buf;
  416. zstream.avail_in = readlen;
  417. result = git_deflate(&zstream, 0);
  418. if (result != Z_OK)
  419. die(_("deflate error (%d)"), result);
  420. out_len = zstream.next_out - compressed;
  421. if (out_len > 0) {
  422. write_or_die(1, compressed, out_len);
  423. compressed_size += out_len;
  424. zstream.next_out = compressed;
  425. zstream.avail_out = sizeof(compressed);
  426. }
  427. }
  428. close_istream(stream);
  429. if (readlen)
  430. return readlen;
  431. zstream.next_in = buf;
  432. zstream.avail_in = 0;
  433. result = git_deflate(&zstream, Z_FINISH);
  434. if (result != Z_STREAM_END)
  435. die("deflate error (%d)", result);
  436. git_deflate_end(&zstream);
  437. out_len = zstream.next_out - compressed;
  438. write_or_die(1, compressed, out_len);
  439. compressed_size += out_len;
  440. zip_offset += compressed_size;
  441. write_zip_data_desc(size, compressed_size, crc);
  442. } else if (compressed_size > 0) {
  443. write_or_die(1, out, compressed_size);
  444. zip_offset += compressed_size;
  445. }
  446. free(deflated);
  447. free(buffer);
  448. if (compressed_size > 0xffffffff || size > 0xffffffff ||
  449. offset > 0xffffffff) {
  450. if (compressed_size >= 0xffffffff)
  451. zip64_dir_extra_payload_size += 8;
  452. if (size >= 0xffffffff)
  453. zip64_dir_extra_payload_size += 8;
  454. if (offset >= 0xffffffff)
  455. zip64_dir_extra_payload_size += 8;
  456. zip_dir_extra_size += 2 + 2 + zip64_dir_extra_payload_size;
  457. }
  458. strbuf_add_le(&zip_dir, 4, 0x02014b50); /* magic */
  459. strbuf_add_le(&zip_dir, 2, creator_version);
  460. strbuf_add_le(&zip_dir, 2, version_needed);
  461. strbuf_add_le(&zip_dir, 2, flags);
  462. strbuf_add_le(&zip_dir, 2, method);
  463. strbuf_add_le(&zip_dir, 2, zip_time);
  464. strbuf_add_le(&zip_dir, 2, zip_date);
  465. strbuf_add_le(&zip_dir, 4, crc);
  466. strbuf_add_le(&zip_dir, 4, clamp32(compressed_size));
  467. strbuf_add_le(&zip_dir, 4, clamp32(size));
  468. strbuf_add_le(&zip_dir, 2, pathlen);
  469. strbuf_add_le(&zip_dir, 2, zip_dir_extra_size);
  470. strbuf_add_le(&zip_dir, 2, 0); /* comment length */
  471. strbuf_add_le(&zip_dir, 2, 0); /* disk */
  472. strbuf_add_le(&zip_dir, 2, !is_binary);
  473. strbuf_add_le(&zip_dir, 4, attr2);
  474. strbuf_add_le(&zip_dir, 4, clamp32(offset));
  475. strbuf_add(&zip_dir, path, pathlen);
  476. strbuf_add(&zip_dir, &extra, ZIP_EXTRA_MTIME_SIZE);
  477. if (zip64_dir_extra_payload_size) {
  478. strbuf_add_le(&zip_dir, 2, 0x0001); /* magic */
  479. strbuf_add_le(&zip_dir, 2, zip64_dir_extra_payload_size);
  480. if (size >= 0xffffffff)
  481. strbuf_add_le(&zip_dir, 8, size);
  482. if (compressed_size >= 0xffffffff)
  483. strbuf_add_le(&zip_dir, 8, compressed_size);
  484. if (offset >= 0xffffffff)
  485. strbuf_add_le(&zip_dir, 8, offset);
  486. }
  487. zip_dir_entries++;
  488. return 0;
  489. }
  490. static void write_zip64_trailer(void)
  491. {
  492. struct zip64_dir_trailer trailer64;
  493. struct zip64_dir_trailer_locator locator64;
  494. copy_le32(trailer64.magic, 0x06064b50);
  495. copy_le64(trailer64.record_size, ZIP64_DIR_TRAILER_RECORD_SIZE);
  496. copy_le16(trailer64.creator_version, max_creator_version);
  497. copy_le16(trailer64.version, 45);
  498. copy_le32(trailer64.disk, 0);
  499. copy_le32(trailer64.directory_start_disk, 0);
  500. copy_le64(trailer64.entries_on_this_disk, zip_dir_entries);
  501. copy_le64(trailer64.entries, zip_dir_entries);
  502. copy_le64(trailer64.size, zip_dir.len);
  503. copy_le64(trailer64.offset, zip_offset);
  504. copy_le32(locator64.magic, 0x07064b50);
  505. copy_le32(locator64.disk, 0);
  506. copy_le64(locator64.offset, zip_offset + zip_dir.len);
  507. copy_le32(locator64.number_of_disks, 1);
  508. write_or_die(1, &trailer64, ZIP64_DIR_TRAILER_SIZE);
  509. write_or_die(1, &locator64, ZIP64_DIR_TRAILER_LOCATOR_SIZE);
  510. }
  511. static void write_zip_trailer(const struct object_id *oid)
  512. {
  513. struct zip_dir_trailer trailer;
  514. int clamped = 0;
  515. copy_le32(trailer.magic, 0x06054b50);
  516. copy_le16(trailer.disk, 0);
  517. copy_le16(trailer.directory_start_disk, 0);
  518. copy_le16_clamp(trailer.entries_on_this_disk, zip_dir_entries,
  519. &clamped);
  520. copy_le16_clamp(trailer.entries, zip_dir_entries, &clamped);
  521. copy_le32(trailer.size, zip_dir.len);
  522. copy_le32_clamp(trailer.offset, zip_offset, &clamped);
  523. copy_le16(trailer.comment_length, oid ? the_hash_algo->hexsz : 0);
  524. write_or_die(1, zip_dir.buf, zip_dir.len);
  525. if (clamped)
  526. write_zip64_trailer();
  527. write_or_die(1, &trailer, ZIP_DIR_TRAILER_SIZE);
  528. if (oid)
  529. write_or_die(1, oid_to_hex(oid), the_hash_algo->hexsz);
  530. }
  531. static void dos_time(timestamp_t *timestamp, int *dos_date, int *dos_time)
  532. {
  533. time_t time;
  534. struct tm *t;
  535. if (date_overflows(*timestamp))
  536. die(_("timestamp too large for this system: %"PRItime),
  537. *timestamp);
  538. time = (time_t)*timestamp;
  539. t = localtime(&time);
  540. *timestamp = time;
  541. *dos_date = t->tm_mday + (t->tm_mon + 1) * 32 +
  542. (t->tm_year + 1900 - 1980) * 512;
  543. *dos_time = t->tm_sec / 2 + t->tm_min * 32 + t->tm_hour * 2048;
  544. }
  545. static int archive_zip_config(const char *var, const char *value, void *data)
  546. {
  547. return userdiff_config(var, value);
  548. }
  549. static int write_zip_archive(const struct archiver *ar,
  550. struct archiver_args *args)
  551. {
  552. int err;
  553. git_config(archive_zip_config, NULL);
  554. dos_time(&args->time, &zip_date, &zip_time);
  555. strbuf_init(&zip_dir, 0);
  556. err = write_archive_entries(args, write_zip_entry);
  557. if (!err)
  558. write_zip_trailer(args->commit_oid);
  559. strbuf_release(&zip_dir);
  560. return err;
  561. }
  562. static struct archiver zip_archiver = {
  563. "zip",
  564. write_zip_archive,
  565. ARCHIVER_WANT_COMPRESSION_LEVELS|ARCHIVER_REMOTE
  566. };
  567. void init_zip_archiver(void)
  568. {
  569. register_archiver(&zip_archiver);
  570. }