From patchwork Wed May 19 19:13:39 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Patrick Steinhardt X-Patchwork-Id: 12268273 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id DA45DC43460 for ; Wed, 19 May 2021 19:13:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 7EF4B6135A for ; Wed, 19 May 2021 19:13:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231889AbhESTPD (ORCPT ); Wed, 19 May 2021 15:15:03 -0400 Received: from out1-smtp.messagingengine.com ([66.111.4.25]:45657 "EHLO out1-smtp.messagingengine.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231956AbhESTPB (ORCPT ); Wed, 19 May 2021 15:15:01 -0400 Received: from compute6.internal (compute6.nyi.internal [10.202.2.46]) by mailout.nyi.internal (Postfix) with ESMTP id BB3555C00E4 for ; Wed, 19 May 2021 15:13:41 -0400 (EDT) Received: from mailfrontend2 ([10.202.2.163]) by compute6.internal (MEProxy); Wed, 19 May 2021 15:13:41 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=pks.im; h=date :from:to:subject:message-id:references:mime-version:content-type :in-reply-to; s=fm1; bh=8syEP58N1OpoHFUpudab6VLfAK4BVvwzE8lkgyNe anA=; b=MvfCSjDTRqQxmVxIWdHFDk+7Bka9VKrhvhz+4+xEurmeXDAWS4O9+kLH Wj12swrzyZS3wI+cZ0v40vA/Ka4eicKV8ZWEm6s+LLq5Qo7HSX8j6NZymXFwXooF DiG+DlkBTfy/aAkWBK7TW6SfgR0rFGf7yAhzvQ5MTDwzr7Ra7YRtXhCSlcCEL15s X9Tbkr4NOuWk0+qx3DUKE3x+VZ9qVVVhv2aC8PV17r4elss7jBNDivG9e8JQSGd7 gt3vdR1hIszglnj+vjppfIyDNb3ayaF4TfB/mablMhgR7lvpLop8jyqhGWVy+XcQ 1NMHmQf7OF9S3wcm3sdx8Pl4V9PdqQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d= messagingengine.com; h=content-type:date:from:in-reply-to :message-id:mime-version:references:subject:to:x-me-proxy :x-me-proxy:x-me-sender:x-me-sender:x-sasl-enc; s=fm2; bh=8syEP5 8N1OpoHFUpudab6VLfAK4BVvwzE8lkgyNeanA=; b=pbsL4Gq/YXyYKZEIXbYoQK a2941sUTF8Qq3Mn5Zd53kmfhZwkWvK0qZIPCeN/EqxbShKj5KY6WofBW5QqYGhCd B09GQFplmUAUagRy2owyW+rolyUpwsPWJ3838/mOYz+ziKp1jHCLeuPbJNrHVNFb VnVJBnb9va9/r7FZx8eEIQMCxnd7ZbTRldNG5nndtGvwSGNdkzQ2CXQ6Kl74mhfp 7xCrhM8xPqx85xbT1CZ9dyC6DPU6tv9c88VY56PiB008KNz2hU9HkDejIlRGjA+j QKDzD7I1ZMt9rNJlDVfJTt2g+ExU1yeFOePO4+LGWfmUV7Z0XSJx/9xkFuzGa6PQ == X-ME-Sender: X-ME-Proxy-Cause: gggruggvucftvghtrhhoucdtuddrgeduledrvdeiledgudefudcutefuodetggdotefrod ftvfcurfhrohhfihhlvgemucfhrghsthforghilhdpqfgfvfdpuffrtefokffrpgfnqfgh necuuegrihhlohhuthemuceftddtnecunecujfgurhepfffhvffukfhfgggtuggjsehgtd erredttddvnecuhfhrohhmpefrrghtrhhitghkucfuthgvihhnhhgrrhguthcuoehpshes phhkshdrihhmqeenucggtffrrghtthgvrhhnpeehgefhtdefueffheekgfffudelffejtd fhvdejkedthfehvdelgfetgfdvtedthfenucfkphepjeejrddukeefrdefjedrudehieen ucevlhhushhtvghrufhiiigvpedtnecurfgrrhgrmhepmhgrihhlfhhrohhmpehpshesph hkshdrihhm X-ME-Proxy: Received: from vm-mail.pks.im (x4db7259c.dyn.telefonica.de [77.183.37.156]) by mail.messagingengine.com (Postfix) with ESMTPA for ; Wed, 19 May 2021 15:13:41 -0400 (EDT) Received: from localhost (ncase [10.192.0.11]) by vm-mail.pks.im (OpenSMTPD) with ESMTPSA id a6964163 (TLSv1.3:TLS_AES_256_GCM_SHA384:256:NO) for ; Wed, 19 May 2021 19:13:40 +0000 (UTC) Date: Wed, 19 May 2021 21:13:39 +0200 From: Patrick Steinhardt To: git@vger.kernel.org Subject: [PATCH 5/8] object-file: allow reading loose objects without reading their contents Message-ID: References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org We're about to add a new implementation of the connectivity check via the object quarantine directory, which will directly iterate over any loose object via their paths. For optimization purposes, we'll want to skip over any loose blobs, but right now there's no easy way to read a loose object without also slurping in all its contents. Fix this shortcoming by modifying `read_loose_object()` such that it can handle the case where no pointer for `contents` was passed in. If so, then we'll simply skip reading the loose object. Signed-off-by: Patrick Steinhardt --- object-file.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/object-file.c b/object-file.c index 884855b9df..ab695823fd 100644 --- a/object-file.c +++ b/object-file.c @@ -2552,7 +2552,8 @@ int read_loose_object(const char *path, git_zstream stream; char hdr[MAX_HEADER_LEN]; - *contents = NULL; + if (contents) + *contents = NULL; map = map_loose_object_1(the_repository, path, NULL, &mapsize); if (!map) { @@ -2572,6 +2573,12 @@ int read_loose_object(const char *path, goto out; } + if (!contents) { + git_inflate_end(&stream); + ret = 0; + goto out; + } + if (*type == OBJ_BLOB && *size > big_file_threshold) { if (check_stream_oid(&stream, hdr, *size, path, expected_oid) < 0) goto out;