5
#include "archive.h"
6
#include "streaming.h"
7
#include "utf8.h"
8
+#include "userdiff.h"
9
+#include "xdiff-interface.h"
10
11
static int zip_date;
12
static int zip_time;
191
}
192
}
193
194
+static int entry_is_binary(const char *path, const void *buffer, size_t size)
195
+{
196
+ struct userdiff_driver *driver = userdiff_find_by_path(path);
197
+ if (!driver)
198
+ driver = userdiff_find_by_name("default");
199
+ if (driver->binary != -1)
200
+ return driver->binary;
201
+ return buffer_is_binary(buffer, size);
202
+}
203
+
204
#define STREAM_BUFFER_SIZE (1024 * 16)
205
206
static int write_zip_entry(struct archiver_args *args,
222
struct git_istream *stream = NULL;
223
unsigned long flags = 0;
224
unsigned long size;
225
+ int is_binary = -1;
226
+ const char *path_without_prefix = path + args->baselen;
227
228
crc = crc32(0, NULL, 0);
229
270
return error("cannot read %s",
271
sha1_to_hex(sha1));
272
crc = crc32(crc, buffer, size);
273
+ is_binary = entry_is_binary(path_without_prefix,
274
+ buffer, size);
275
out = buffer;
276
}
277
compressed_size = (method == 0) ? size : 0;
316
copy_le16(dirent.extra_length, ZIP_EXTRA_MTIME_SIZE);
317
copy_le16(dirent.comment_length, 0);
318
copy_le16(dirent.disk, 0);
303
- copy_le16(dirent.attr1, 0);
319
copy_le32(dirent.attr2, attr2);
320
copy_le32(dirent.offset, zip_offset);
321
343
if (readlen <= 0)
344
break;
345
crc = crc32(crc, buf, readlen);
346
+ if (is_binary == -1)
347
+ is_binary = entry_is_binary(path_without_prefix,
348
+ buf, readlen);
349
write_or_die(1, buf, readlen);
350
}
351
close_istream(stream);
379
if (readlen <= 0)
380
break;
381
crc = crc32(crc, buf, readlen);
382
+ if (is_binary == -1)
383
+ is_binary = entry_is_binary(path_without_prefix,
384
+ buf, readlen);
385
386
zstream.next_in = buf;
387
zstream.avail_in = readlen;
426
free(deflated);
427
free(buffer);
428
429
+ copy_le16(dirent.attr1, !is_binary);
430
+
431
memcpy(zip_dir + zip_dir_offset, &dirent, ZIP_DIR_HEADER_SIZE);
432
zip_dir_offset += ZIP_DIR_HEADER_SIZE;
433
memcpy(zip_dir + zip_dir_offset, path, pathlen);