From patchwork Fri Apr 9 08:07:27 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12193279 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.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 CAA24C433B4 for ; Fri, 9 Apr 2021 08:07:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9C545611B0 for ; Fri, 9 Apr 2021 08:07:43 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232051AbhDIIHz (ORCPT ); Fri, 9 Apr 2021 04:07:55 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56984 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232005AbhDIIHx (ORCPT ); Fri, 9 Apr 2021 04:07:53 -0400 Received: from mail-wm1-x335.google.com (mail-wm1-x335.google.com [IPv6:2a00:1450:4864:20::335]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C63F6C061760 for ; Fri, 9 Apr 2021 01:07:40 -0700 (PDT) Received: by mail-wm1-x335.google.com with SMTP id y124-20020a1c32820000b029010c93864955so4203847wmy.5 for ; Fri, 09 Apr 2021 01:07:40 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=IccIA9PPX0A29TQyVOZgn/4F98G0734JFevU19zjFjM=; b=YJpiXpTJ7Gkiy6II/NDdbq8H/fdYGKUsCz0CsZGhqDwhUk7yVVXXk+f6Bl483vYyaN XF/0XTnPJLaTINWwKAfEO02kMNFeVjGwyE9kdmyiAJLnMM1Sdj9WURfuC/s9Zj4/W4ZP 3GQEUEdnULhOKL5a6ECYoruNMARpeWPcWKm3+L4csBIXI620KE5eVj/jPwrYbJjfhdo6 /9G0aH2qSbHnHh0E7382HFTq5qFap++vPI2QXfA2ryP3Fs8fyjciNtF83T9FmsHLUjrj rJDE0TSzljbXVijpSvs8lS5ttA2e6vJBkKagu+b59h0aypae3lND96dx9Q218e/beIuM 74BQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=IccIA9PPX0A29TQyVOZgn/4F98G0734JFevU19zjFjM=; b=dvf7nHtqG9G+82jIsk9823fBiHQcEVkX8L4Wpk3DQXa3TVvanWbootp06aTGrt6KJQ B6Df/KIaPCNL67CZwukHozIWCpjvTEPp7JJzCh48iZaxnCBsirZpkq422xLx1BjI+fZj WcMib4RYMppiCj91ZkKJCPii9hmrw1RuuKzOVGytghL1XSKE7mPXQTn4+n8l/iM/d5Gh kTCtsMhZ37BM1DO9T91odaTiZonbA5eBsTMJVAi8gLLs1uzgNX7r7sR21Ref8Y2CUDsX ToSOoaYfCYCQ0XjaeaHb51T9tYlo/KoXkmanX8C1ABzN9oZItWVLb//gNDkuCu8ELKJA ko/g== X-Gm-Message-State: AOAM530U4/zEHN049Bh4QT4CM9FR5pTMTaEX8SAT22hcTpF0A32KdzwC SQ644UGbq3bvffq5NEkXQ9/KfKF0I9nmTg== X-Google-Smtp-Source: ABdhPJy6cI+Ad0rxY/r140gKLm1+uckOgkw0tHe1UZHrXNJG3SGn7Qv0F/EE9Y02E+m/z0QONRC1Kw== X-Received: by 2002:a1c:2b05:: with SMTP id r5mr11841273wmr.107.1617955659288; Fri, 09 Apr 2021 01:07:39 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id b15sm3105988wrx.73.2021.04.09.01.07.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Apr 2021 01:07:38 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Jeff King , Taylor Blau , Elijah Newren , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 1/2] blob.c: remove buffer & size arguments to parse_blob_buffer() Date: Fri, 9 Apr 2021 10:07:27 +0200 Message-Id: X-Mailer: git-send-email 2.31.1.584.gf4baedee75 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org As noted in the comment introduced in 837d395a5c0 (Replace parse_blob() with an explanatory comment, 2010-01-18) the old parse_blob() function and the current parse_blob_buffer() exist merely to provide consistency in the API. We're not going to parse blobs like we "parse" commits, trees or tags. So let's not have the parse_blob_buffer() take arguments that pretends that we do. Its only use is to set the "parsed" flag. See bd2c39f58f9 ([PATCH] don't load and decompress objects twice with parse_object(), 2005-05-06) for the introduction of parse_blob_buffer(). I'm moving the prototype of parse_blob_buffer() below the comment added in 837d395a5c0 while I'm at it. That comment was originally meant to be a replacement for the missing parse_blob() function, but it's much less confusing to have it be above the parse_blob_buffer() function it refers to. Signed-off-by: Ævar Arnfjörð Bjarmason --- blob.c | 2 +- blob.h | 3 +-- object.c | 4 ++-- 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/blob.c b/blob.c index 182718aba9..389a7546dc 100644 --- a/blob.c +++ b/blob.c @@ -13,7 +13,7 @@ struct blob *lookup_blob(struct repository *r, const struct object_id *oid) return object_as_type(obj, OBJ_BLOB, 0); } -int parse_blob_buffer(struct blob *item, void *buffer, unsigned long size) +int parse_blob_buffer(struct blob *item) { item->object.parsed = 1; return 0; diff --git a/blob.h b/blob.h index 1664872055..ac1d4804a5 100644 --- a/blob.h +++ b/blob.h @@ -11,8 +11,6 @@ struct blob { struct blob *lookup_blob(struct repository *r, const struct object_id *oid); -int parse_blob_buffer(struct blob *item, void *buffer, unsigned long size); - /** * Blobs do not contain references to other objects and do not have * structured data that needs parsing. However, code may use the @@ -21,5 +19,6 @@ int parse_blob_buffer(struct blob *item, void *buffer, unsigned long size); * parse_blob_buffer() is used (by object.c) to flag that the object * has been read successfully from the database. **/ +int parse_blob_buffer(struct blob *item); #endif /* BLOB_H */ diff --git a/object.c b/object.c index 78343781ae..63896abf01 100644 --- a/object.c +++ b/object.c @@ -195,7 +195,7 @@ struct object *parse_object_buffer(struct repository *r, const struct object_id if (type == OBJ_BLOB) { struct blob *blob = lookup_blob(r, oid); if (blob) { - if (parse_blob_buffer(blob, buffer, size)) + if (parse_blob_buffer(blob)) return NULL; obj = &blob->object; } @@ -266,7 +266,7 @@ struct object *parse_object(struct repository *r, const struct object_id *oid) error(_("hash mismatch %s"), oid_to_hex(oid)); return NULL; } - parse_blob_buffer(lookup_blob(r, oid), NULL, 0); + parse_blob_buffer(lookup_blob(r, oid)); return lookup_object(r, oid); } From patchwork Fri Apr 9 08:07:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12193281 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.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT 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 F2705C433B4 for ; Fri, 9 Apr 2021 08:07:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id BAF98611B0 for ; Fri, 9 Apr 2021 08:07:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S232631AbhDIIH5 (ORCPT ); Fri, 9 Apr 2021 04:07:57 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:56992 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S232535AbhDIIHy (ORCPT ); Fri, 9 Apr 2021 04:07:54 -0400 Received: from mail-wr1-x435.google.com (mail-wr1-x435.google.com [IPv6:2a00:1450:4864:20::435]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6222EC061761 for ; Fri, 9 Apr 2021 01:07:41 -0700 (PDT) Received: by mail-wr1-x435.google.com with SMTP id e12so4674503wro.11 for ; Fri, 09 Apr 2021 01:07:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=VegrmzRhNKZVzzE17SXW49GEV7SvxJWKbFVl2j5qUVI=; b=b4re/scsS2JSqMAwpbONssyMkoLpxmCKsLon3218CUP4AE4vtzxohK0pXdPqEW1AQB EXHXEAY9mijETG3dpguv8DlJ+cafeaFd3oNrs+Ti2MmLEyWJebklAMjR8HPgUW0X9AEa qbUpsWdhcnh8dmecu7kGLIoHu/hpHWDz9Yk+0hJe5D51n3001kNTpdEJuF9l6Y/8Weuk GOqxZPvvpu1y1tJulx5v7htCDGYvkBZnPhdPWyXS8FRbtyk9EGtSUzHtKp4qzJGO1et+ UioBcXnYKMPtsLRQ8+M9/rARcr3D37SbiQsVQAzMQinOFu4qH5QSFYykbdWSF/TJ/gRc 391w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=VegrmzRhNKZVzzE17SXW49GEV7SvxJWKbFVl2j5qUVI=; b=QkqQQXGRY5WJtRLfp9p+2Xm4RMVMZTyKBt+NCLZEYVRY1seW4aK0pwiAkl8EOYwNd5 TioFbB3Zv22mA5UCRVMCAc78JeydDcV2YRok2HCQzkyq/mKXwGlI7A+32PHsvojpygBq caTpFhLmfQuT/9DGQZdjNxAzxt6N3VThxbg+yZrJe3D7i1GW7mkpg1aq91zGvIs5TXk8 BhmWE8Z4EaUKv9oY26yDwOu7gAMuTYpLpabwURV+/purAtBWBRKYc8pqTZfuNnDPDJ3g CW330Jhhf7QjWjMRYpJEHMhP3Lzdqm9Ptlin+n+GpaUQZLdutNC3iWorjeF4cxwbVI1E iacw== X-Gm-Message-State: AOAM532EDHYimpjojEy+BUg53r+bzruvB2urMSRrgPzIaOrRPTUS/kuF D7vsJ10CsiENkpVpDtYyiVM88B95/tT/qw== X-Google-Smtp-Source: ABdhPJzqbyPp4Mr+hzLqMy6WwgHgG7MFqxul38OyOOjDqlAKqoIP+CFHOdcKvA3mv7gYQB1zkIwbPA== X-Received: by 2002:adf:c641:: with SMTP id u1mr16485650wrg.332.1617955660003; Fri, 09 Apr 2021 01:07:40 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id b15sm3105988wrx.73.2021.04.09.01.07.39 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 09 Apr 2021 01:07:39 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Johannes Schindelin , Jeff King , Taylor Blau , Elijah Newren , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= Subject: [PATCH 2/2] object.c: initialize automatic variable in lookup_object() Date: Fri, 9 Apr 2021 10:07:28 +0200 Message-Id: X-Mailer: git-send-email 2.31.1.584.gf4baedee75 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Initialize a "struct object obj*" variable to NULL explicitly and return it instead of leaving it uninitialized until the "while" loop. There was no bug here, it's just less confusing when debugging if the "obj" is either NULL or a valid object, not some random invalid pointer. See 0556a11a0df (git object hash cleanups, 2006-06-30) for the initial implementation. Signed-off-by: Ævar Arnfjörð Bjarmason --- object.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/object.c b/object.c index 63896abf01..7fdca3ed1e 100644 --- a/object.c +++ b/object.c @@ -87,10 +87,10 @@ static void insert_obj_hash(struct object *obj, struct object **hash, unsigned i struct object *lookup_object(struct repository *r, const struct object_id *oid) { unsigned int i, first; - struct object *obj; + struct object *obj = NULL; if (!r->parsed_objects->obj_hash) - return NULL; + return obj; first = i = hash_obj(oid, r->parsed_objects->obj_hash_size); while ((obj = r->parsed_objects->obj_hash[i]) != NULL) {