5
5
#include "archive.h"
6
6
#include "streaming.h"
7
7
#include "utf8.h"
8
+ #include "userdiff.h"
9
+ #include "xdiff-interface.h"
8
10
9
11
static int zip_date ;
10
12
static int zip_time ;
@@ -188,6 +190,16 @@ static int has_only_ascii(const char *s)
188
190
}
189
191
}
190
192
193
+ static int entry_is_binary (const char * path , const void * buffer , size_t size )
194
+ {
195
+ struct userdiff_driver * driver = userdiff_find_by_path (path );
196
+ if (!driver )
197
+ driver = userdiff_find_by_name ("default" );
198
+ if (driver -> binary != -1 )
199
+ return driver -> binary ;
200
+ return buffer_is_binary (buffer , size );
201
+ }
202
+
191
203
#define STREAM_BUFFER_SIZE (1024 * 16)
192
204
193
205
static int write_zip_entry (struct archiver_args * args ,
@@ -209,6 +221,8 @@ static int write_zip_entry(struct archiver_args *args,
209
221
struct git_istream * stream = NULL ;
210
222
unsigned long flags = 0 ;
211
223
unsigned long size ;
224
+ int is_binary = -1 ;
225
+ const char * path_without_prefix = path + args -> baselen ;
212
226
213
227
crc = crc32 (0 , NULL , 0 );
214
228
@@ -255,6 +269,8 @@ static int write_zip_entry(struct archiver_args *args,
255
269
return error ("cannot read %s" ,
256
270
sha1_to_hex (sha1 ));
257
271
crc = crc32 (crc , buffer , size );
272
+ is_binary = entry_is_binary (path_without_prefix ,
273
+ buffer , size );
258
274
out = buffer ;
259
275
}
260
276
compressed_size = (method == 0 ) ? size : 0 ;
@@ -299,7 +315,6 @@ static int write_zip_entry(struct archiver_args *args,
299
315
copy_le16 (dirent .extra_length , ZIP_EXTRA_MTIME_SIZE );
300
316
copy_le16 (dirent .comment_length , 0 );
301
317
copy_le16 (dirent .disk , 0 );
302
- copy_le16 (dirent .attr1 , 0 );
303
318
copy_le32 (dirent .attr2 , attr2 );
304
319
copy_le32 (dirent .offset , zip_offset );
305
320
@@ -327,6 +342,9 @@ static int write_zip_entry(struct archiver_args *args,
327
342
if (readlen <= 0 )
328
343
break ;
329
344
crc = crc32 (crc , buf , readlen );
345
+ if (is_binary == -1 )
346
+ is_binary = entry_is_binary (path_without_prefix ,
347
+ buf , readlen );
330
348
write_or_die (1 , buf , readlen );
331
349
}
332
350
close_istream (stream );
@@ -359,6 +377,9 @@ static int write_zip_entry(struct archiver_args *args,
359
377
if (readlen <= 0 )
360
378
break ;
361
379
crc = crc32 (crc , buf , readlen );
380
+ if (is_binary == -1 )
381
+ is_binary = entry_is_binary (path_without_prefix ,
382
+ buf , readlen );
362
383
363
384
zstream .next_in = buf ;
364
385
zstream .avail_in = readlen ;
@@ -403,6 +424,8 @@ static int write_zip_entry(struct archiver_args *args,
403
424
free (deflated );
404
425
free (buffer );
405
426
427
+ copy_le16 (dirent .attr1 , !is_binary );
428
+
406
429
memcpy (zip_dir + zip_dir_offset , & dirent , ZIP_DIR_HEADER_SIZE );
407
430
zip_dir_offset += ZIP_DIR_HEADER_SIZE ;
408
431
memcpy (zip_dir + zip_dir_offset , path , pathlen );
0 commit comments