From patchwork Sat Dec 7 12:20:33 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?q?Ren=C3=A9_Scharfe?= X-Patchwork-Id: 11277315 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 5CECB109A for ; Sat, 7 Dec 2019 12:21:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 2D16921835 for ; Sat, 7 Dec 2019 12:21:07 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (1024-bit key) header.d=web.de header.i=@web.de header.b="hRxVhsxn" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726418AbfLGMUk (ORCPT ); Sat, 7 Dec 2019 07:20:40 -0500 Received: from mout.web.de ([212.227.17.12]:60383 "EHLO mout.web.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726106AbfLGMUk (ORCPT ); Sat, 7 Dec 2019 07:20:40 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=web.de; s=dbaedf251592; t=1575721234; bh=uxEv8yDrEjD3Ns5eJACVnIjCY1HZMwk69srS/1o8Gzo=; h=X-UI-Sender-Class:To:Cc:From:Subject:Date; b=hRxVhsxn/m5mKadzpkJDZ/5Ceii1P3gNQ8j6fjrGytuawhn8xoUknyWUiIO0a4pCi B6jpCJaeNzeIuhupismZX5oJPlEqdSRjN+sprnsuZJDlt6RTIq3a8G/uhap5aIsCLn 49dVVMxjRb4ZrXwR/VakoKJXCrmtLXAfc294IVO8= X-UI-Sender-Class: c548c8c5-30a9-4db5-a2e7-cb6cb037b8f9 Received: from [192.168.178.26] ([91.47.158.92]) by smtp.web.de (mrweb103 [213.165.67.124]) with ESMTPSA (Nemesis) id 0MFLB2-1iaHp81Sz6-00EJpR; Sat, 07 Dec 2019 13:20:34 +0100 To: Git Mailing List Cc: Junio C Hamano From: =?utf-8?q?Ren=C3=A9_Scharfe?= Subject: [PATCH] archive-zip: use enum for compression method Message-ID: <9acdf2e0-6a65-df73-1e43-0a9e1631f138@web.de> Date: Sat, 7 Dec 2019 13:20:33 +0100 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Thunderbird/60.9.0 MIME-Version: 1.0 Content-Language: en-US X-Provags-ID: V03:K1:VJZX1UqyrH50Q6gbbg5m7y3BuY2vKYGTBfQSN4McGQrQ3l3Sua+ FykxfOCQclR2EQSJMOf5hbM7ATdS40Fx5qJN05dFHpOjXAnCigURRGdLJ5rQfdcLEH2pJ/n UuAoGmZJ8x/RgVtQkXiPOje4N9W0GFedVC8YhAtc8tRgI/8G5+u2jyk08t3GjnrVjIYfe8B MAqPtJsdvQ7weCyNHiEwg== X-Spam-Flag: NO X-UI-Out-Filterresults: notjunk:1;V03:K0:BCbHKQmsUMA=:wlMIhkwYWHy9Kvwj0bMcCu jNLAP/CmZKmu/OhnpxJD56L0K8kM/8nTF0A15m5zbFjE1BHg3r+JBbmn4x0RV5BObIdiM3LC0 LeI6a6MUCQ+5yDbTtKtqBgsZXhxc/3kDpRdvIHH3Rw6AMEPCDvcxiFfKfIFhoFrfAHW6sGAAc brCkw6pB+P1pxnUg9cFylvIETorQjPHlffbFTbmBItPaR4iubGZjJaU2RtLl4ed9OPRylbTDj cE+INZD1JW1l146s+FR8q4+IYZthDL3iVS3b8Ou0n57qo5Jj9T8OoxztSZF4Xi+aApbhoivn3 Zpi4pCcnOK967OvW67aOWdMoumEVIqAY7R7bOVMaxtlARUINVab8QRRugbgZ0JZ2jgx/dKwNL curpla3AMPC4tGhMNTiBNZ8JJOQKxhhTnB0CKHjBsmjaiYO3fPbjf0m07ea8dsOXC2i/MNLXI kaZgbIXRs+meiqtNLwtC+XCiFxl4XHvd86hxVJOIv3ITap3ZpKMHyn7E9WCHDbZXA0zh7BLjX FmeRlFqUo28Yf9f78ruDijoMcdxxt+W9HsMorkhVfLjAondM4R8xC/OxmlpEhSv3XfW2K7O99 tVHFKhYVGI7EdreF3jEvt/dpMNKK9ns/Ch0G0FoRET+YYtO5T2aidIfxuCsgFUCzMLZVtmj4S MuoaFTy7S7YiIUKS/Q38h7e3qFp4OWnXY5tLFKschKi0XRiGTGgIc+rIUctfQ0DLEIKf2R0D/ Nuchrnszz+SrdxUaOXK7N7dPwU/+SQJPhA+vD5LL8C4618MmPSQofDGauO6TYSaB63XsPNBlM GbSMoAQLKH34o92VElPvmVUGXe8blGS76eWjgKeO6bJ6ae4Ug2PVbFz74d4HdGl6yK8i9H76x uYRx4I2RvufE+ALRxKeinOyu28jZxdHm4eTesFpdY9n+6CZ+ts5dUTAGwyvI7pEOab/mJ0dVS KgmQJ82UlkXLzuS0gd0p0S63hZHxN6RFPu+7hVaMCotvIQQ8RlD+4zf7Ht3RxP6WpatWuknF5 KBRl4S5wh6qWt34WipchfcLStPWtlhRIsxct10pCFe0KIxpXal/iFRP3E9Z22MzYiqVNOafqI U7cMtFMqQghGRoJShgm3NHdtKeMpKyxg+oZ2nEZiGHnbJeq7QhrjbsmAIZ5i19sLa3rhj1h0E UXGVlzQhlrg18zHRKDesLASjBDNxaKY9D5hpoX+P7XxYBNjAh2wz1BHw573fU6K06P6vCWeIh 5Z0+jNeWbVSJ3SRErxsTB/zJXCGs9N7vGM5+7yw== Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add an enumeration to assign names to the magic values that determine the ZIP compression method to use. Use those names to improve code readability. Signed-off-by: René Scharfe --- archive-zip.c | 23 ++++++++++++++--------- 1 file changed, 14 insertions(+), 9 deletions(-) -- 2.24.0 diff --git a/archive-zip.c b/archive-zip.c index 4d66b5be6e..095b66a480 100644 --- a/archive-zip.c +++ b/archive-zip.c @@ -24,6 +24,11 @@ static unsigned int max_creator_version; #define ZIP_STREAM (1 << 3) #define ZIP_UTF8 (1 << 11) +enum zip_method { + ZIP_METHOD_STORE = 0, + ZIP_METHOD_DEFLATE = 8 +}; + struct zip_local_header { unsigned char magic[4]; unsigned char version[2]; @@ -291,7 +296,7 @@ static int write_zip_entry(struct archiver_args *args, unsigned long attr2; unsigned long compressed_size; unsigned long crc; - int method; + enum zip_method method; unsigned char *out; void *deflated = NULL; void *buffer; @@ -320,7 +325,7 @@ static int write_zip_entry(struct archiver_args *args, } if (S_ISDIR(mode) || S_ISGITLINK(mode)) { - method = 0; + method = ZIP_METHOD_STORE; attr2 = 16; out = NULL; size = 0; @@ -330,13 +335,13 @@ static int write_zip_entry(struct archiver_args *args, enum object_type type = oid_object_info(args->repo, oid, &size); - method = 0; + method = ZIP_METHOD_STORE; attr2 = S_ISLNK(mode) ? ((mode | 0777) << 16) : (mode & 0111) ? ((mode) << 16) : 0; if (S_ISLNK(mode) || (mode & 0111)) creator_version = 0x0317; if (S_ISREG(mode) && args->compression_level != 0 && size > 0) - method = 8; + method = ZIP_METHOD_DEFLATE; if (S_ISREG(mode) && type == OBJ_BLOB && !args->convert && size > big_file_threshold) { @@ -358,7 +363,7 @@ static int write_zip_entry(struct archiver_args *args, buffer, size); out = buffer; } - compressed_size = (method == 0) ? size : 0; + compressed_size = (method == ZIP_METHOD_STORE) ? size : 0; } else { return error(_("unsupported file mode: 0%o (SHA1: %s)"), mode, oid_to_hex(oid)); @@ -367,13 +372,13 @@ static int write_zip_entry(struct archiver_args *args, if (creator_version > max_creator_version) max_creator_version = creator_version; - if (buffer && method == 8) { + if (buffer && method == ZIP_METHOD_DEFLATE) { out = deflated = zlib_deflate_raw(buffer, size, args->compression_level, &compressed_size); if (!out || compressed_size >= size) { out = buffer; - method = 0; + method = ZIP_METHOD_STORE; compressed_size = size; } } @@ -420,7 +425,7 @@ static int write_zip_entry(struct archiver_args *args, zip_offset += ZIP64_EXTRA_SIZE; } - if (stream && method == 0) { + if (stream && method == ZIP_METHOD_STORE) { unsigned char buf[STREAM_BUFFER_SIZE]; ssize_t readlen; @@ -443,7 +448,7 @@ static int write_zip_entry(struct archiver_args *args, zip_offset += compressed_size; write_zip_data_desc(size, compressed_size, crc); - } else if (stream && method == 8) { + } else if (stream && method == ZIP_METHOD_DEFLATE) { unsigned char buf[STREAM_BUFFER_SIZE]; ssize_t readlen; git_zstream zstream;