{"thread":{"id":"52401","subject":"[PATCH] archive-zip: use enum for compression method","startedAt":"2019-12-07T12:20:42Z","lastAt":"2019-12-07T12:20:42Z","messageCount":1,"participants":["René Scharfe"],"isPatch":true,"patchVersion":1,"patchTotal":null},"messages":[{"id":"387674","messageId":"9acdf2e0-6a65-df73-1e43-0a9e1631f138@web.de","threadId":"52401","inReplyTo":null,"subject":"[PATCH] archive-zip: use enum for compression method","fromName":"René Scharfe","fromEmail":"l.s.r@web.de","sentAt":"2019-12-07T12:20:33Z","receivedAt":"2019-12-07T12:20:42Z","isPatch":true,"sender":{"key":"l.s.r@web.de","avatar":"https://avatars.githubusercontent.com/u/26122331?v=4"},"body":"Add an enumeration to assign names to the magic values that determine\nthe ZIP compression method to use.  Use those names to improve code\nreadability.\n\nSigned-off-by: René Scharfe <l.s.r@web.de>\n---\n archive-zip.c | 23 ++++++++++++++---------\n 1 file changed, 14 insertions(+), 9 deletions(-)\n\ndiff --git a/archive-zip.c b/archive-zip.c\nindex 4d66b5be6e..095b66a480 100644\n--- a/archive-zip.c\n+++ b/archive-zip.c\n@@ -24,6 +24,11 @@ static unsigned int max_creator_version;\n #define ZIP_STREAM\t(1 <<  3)\n #define ZIP_UTF8\t(1 << 11)\n\n+enum zip_method {\n+\tZIP_METHOD_STORE = 0,\n+\tZIP_METHOD_DEFLATE = 8\n+};\n+\n struct zip_local_header {\n \tunsigned char magic[4];\n \tunsigned char version[2];\n@@ -291,7 +296,7 @@ static int write_zip_entry(struct archiver_args *args,\n \tunsigned long attr2;\n \tunsigned long compressed_size;\n \tunsigned long crc;\n-\tint method;\n+\tenum zip_method method;\n \tunsigned char *out;\n \tvoid *deflated = NULL;\n \tvoid *buffer;\n@@ -320,7 +325,7 @@ static int write_zip_entry(struct archiver_args *args,\n \t}\n\n \tif (S_ISDIR(mode) || S_ISGITLINK(mode)) {\n-\t\tmethod = 0;\n+\t\tmethod = ZIP_METHOD_STORE;\n \t\tattr2 = 16;\n \t\tout = NULL;\n \t\tsize = 0;\n@@ -330,13 +335,13 @@ static int write_zip_entry(struct archiver_args *args,\n \t\tenum object_type type = oid_object_info(args->repo, oid,\n \t\t\t\t\t\t\t&size);\n\n-\t\tmethod = 0;\n+\t\tmethod = ZIP_METHOD_STORE;\n \t\tattr2 = S_ISLNK(mode) ? ((mode | 0777) << 16) :\n \t\t\t(mode & 0111) ? ((mode) << 16) : 0;\n \t\tif (S_ISLNK(mode) || (mode & 0111))\n \t\t\tcreator_version = 0x0317;\n \t\tif (S_ISREG(mode) && args->compression_level != 0 && size > 0)\n-\t\t\tmethod = 8;\n+\t\t\tmethod = ZIP_METHOD_DEFLATE;\n\n \t\tif (S_ISREG(mode) && type == OBJ_BLOB && !args->convert &&\n \t\t    size > big_file_threshold) {\n@@ -358,7 +363,7 @@ static int write_zip_entry(struct archiver_args *args,\n \t\t\t\t\t\t    buffer, size);\n \t\t\tout = buffer;\n \t\t}\n-\t\tcompressed_size = (method == 0) ? size : 0;\n+\t\tcompressed_size = (method == ZIP_METHOD_STORE) ? size : 0;\n \t} else {\n \t\treturn error(_(\"unsupported file mode: 0%o (SHA1: %s)\"), mode,\n \t\t\t\toid_to_hex(oid));\n@@ -367,13 +372,13 @@ static int write_zip_entry(struct archiver_args *args,\n \tif (creator_version > max_creator_version)\n \t\tmax_creator_version = creator_version;\n\n-\tif (buffer && method == 8) {\n+\tif (buffer && method == ZIP_METHOD_DEFLATE) {\n \t\tout = deflated = zlib_deflate_raw(buffer, size,\n \t\t\t\t\t\t  args->compression_level,\n \t\t\t\t\t\t  &compressed_size);\n \t\tif (!out || compressed_size >= size) {\n \t\t\tout = buffer;\n-\t\t\tmethod = 0;\n+\t\t\tmethod = ZIP_METHOD_STORE;\n \t\t\tcompressed_size = size;\n \t\t}\n \t}\n@@ -420,7 +425,7 @@ static int write_zip_entry(struct archiver_args *args,\n \t\tzip_offset += ZIP64_EXTRA_SIZE;\n \t}\n\n-\tif (stream && method == 0) {\n+\tif (stream && method == ZIP_METHOD_STORE) {\n \t\tunsigned char buf[STREAM_BUFFER_SIZE];\n \t\tssize_t readlen;\n\n@@ -443,7 +448,7 @@ static int write_zip_entry(struct archiver_args *args,\n \t\tzip_offset += compressed_size;\n\n \t\twrite_zip_data_desc(size, compressed_size, crc);\n-\t} else if (stream && method == 8) {\n+\t} else if (stream && method == ZIP_METHOD_DEFLATE) {\n \t\tunsigned char buf[STREAM_BUFFER_SIZE];\n \t\tssize_t readlen;\n \t\tgit_zstream zstream;\n--\n2.24.0\n"}]}