From patchwork Thu Aug 10 20:37:34 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13349907 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9DA16C001DE for ; Thu, 10 Aug 2023 20:37:41 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235284AbjHJUhk (ORCPT ); Thu, 10 Aug 2023 16:37:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:51320 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230459AbjHJUhh (ORCPT ); Thu, 10 Aug 2023 16:37:37 -0400 Received: from mail-yw1-x112b.google.com (mail-yw1-x112b.google.com [IPv6:2607:f8b0:4864:20::112b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id EF88D2733 for ; Thu, 10 Aug 2023 13:37:36 -0700 (PDT) Received: by mail-yw1-x112b.google.com with SMTP id 00721157ae682-589addee1c1so12531077b3.3 for ; Thu, 10 Aug 2023 13:37:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20221208.gappssmtp.com; s=20221208; t=1691699856; x=1692304656; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=ofzl09eKj+yUQsN17iTmwMKP9Q5MFiGKPCOHCIHHtsk=; b=mH8qq3ZULUpvm0oQ2aoHQknum2ZwtKUNG+HQ1c+J4WI/WkCfmgxnCFvd/itf+UWfMv nZ67GcarLX2sWXMbsNfYPsnjZWTNoavkhd7U8um7P/QiaBp3TPnEghaUiU6R8XOmPsx7 heqKaopeWheeyzUTZToercVngqeWfwm9C4grP6eIEbiNoOI9EyD4bVUPGvQ0KJSxJ7kj byFWT+XaYvcKJCbwwzn94WHtGtvnjho9+Rj9cICgG8t3T21a4o1SXUSmJFlYyenKSrGr 1VIaJCNRR7blSarvoxoi1s4tDEs1mWevMoSnN394e00invBL3Ng+DHiorlHh0+uo78aT XbSg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691699856; x=1692304656; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=ofzl09eKj+yUQsN17iTmwMKP9Q5MFiGKPCOHCIHHtsk=; b=RsI3HRBEA+QNKw8HLOlZwim709He27Xjsjjj6aoTrowkkh5AxxKLDOWH6+Cdk76TPM 6XgWRmPQcXp54X+kN+B3kPYzkkOV1I927/rpPcP8Ub7YWwAiLYu1MX83cDyAe5v1LlNs 7VbUvzhIxg0Fb/V1i6HNAs1G+Wxs8DHcH2Xi1hGfeEX+XhpZCzYcBNwv8OXQYQxChz/1 Od3IEns96MVxasan6GylpNhSd47ImKmCzddqb62pssWVoQAVOhO407IoZsZA6J2mUS9p OGlEzFPWQ1Zt7oSwWQx7/ETpylWqtx9Mm9AZcJvBMWZqcFI7mQHtfNOCA3/8dBeYBTKr UENw== X-Gm-Message-State: AOJu0Yzi9Q1zBh2Nfbr8QMcnUBbvYFahiXAUKA9OtXqNPGYxWwgMiBRv XkBf5iqebu+dlANSb6hDPe38K1Z8u4aeImP0fYTOQQ== X-Google-Smtp-Source: AGHT+IGrGzpNphow6g5BxNsZZ8ZCD4ljvclbo6lyOvESozX9Pc6LRQ+ITOIlJXmMkTr70ehEaD6lmw== X-Received: by 2002:a81:49d4:0:b0:570:2568:15e with SMTP id w203-20020a8149d4000000b005702568015emr3833971ywa.43.1691699855942; Thu, 10 Aug 2023 13:37:35 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id z20-20020a81c214000000b0058038e6609csm560681ywc.74.2023.08.10.13.37.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Aug 2023 13:37:35 -0700 (PDT) Date: Thu, 10 Aug 2023 16:37:34 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Derrick Stolee Subject: [PATCH 1/4] commit-graph: introduce `commit_graph_generation_from_graph()` Message-ID: <701c198e197a8e6008672b7be7e11e02007f808a.1691699851.git.me@ttaylorr.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org In 2ee11f7261 (commit-graph: return generation from memory, 2023-03-20), the `commit_graph_generation()` function stopped returning zeros when asked to locate the generation number of a given commit. This was done at the time to prepare for a later change which set generation values in memory, meaning that we could no longer rely on `graph_pos` alone to tell us whether or not to trust the generation number returned by this function. In 2ee11f7261, it was noted that this change only impacted very old commit-graphs, which were written with all commits having generation number 0. Indeed, zero is not a valid generation number, so we should never expect to see that value outside of the aforementioned case. The test fallout in 2ee11f7261 indicated that we were no longer able to fsck a specific old case of commit-graph corruption, where we see a non-zero generation number after having seen a generation number of 0 earlier. Introduce a variant of `commit_graph_generation()` which behaves like that function did prior to 2ee11f7261, known as `commit_graph_generation_from_graph()`. Then use this function in the context of `verify_one_commit_graph()`, where we only want to trust the values from the graph. Signed-off-by: Taylor Blau --- commit-graph.c | 14 ++++++++++++-- t/t5318-commit-graph.sh | 2 +- 2 files changed, 13 insertions(+), 3 deletions(-) diff --git a/commit-graph.c b/commit-graph.c index 0aa1640d15..c68f5c6b3a 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -128,6 +128,16 @@ timestamp_t commit_graph_generation(const struct commit *c) return GENERATION_NUMBER_INFINITY; } +static timestamp_t commit_graph_generation_from_graph(const struct commit *c) +{ + struct commit_graph_data *data = + commit_graph_data_slab_peek(&commit_graph_data_slab, c); + + if (!data || data->graph_pos == COMMIT_NOT_FROM_GRAPH) + return GENERATION_NUMBER_INFINITY; + return data->generation; +} + static struct commit_graph_data *commit_graph_data_at(const struct commit *c) { unsigned int i, nth_slab; @@ -2659,7 +2669,7 @@ static int verify_one_commit_graph(struct repository *r, oid_to_hex(&graph_parents->item->object.oid), oid_to_hex(&odb_parents->item->object.oid)); - generation = commit_graph_generation(graph_parents->item); + generation = commit_graph_generation_from_graph(graph_parents->item); if (generation > max_generation) max_generation = generation; @@ -2671,7 +2681,7 @@ static int verify_one_commit_graph(struct repository *r, graph_report(_("commit-graph parent list for commit %s terminates early"), oid_to_hex(&cur_oid)); - if (!commit_graph_generation(graph_commit)) { + if (!commit_graph_generation_from_graph(graph_commit)) { if (generation_zero == GENERATION_NUMBER_EXISTS) graph_report(_("commit-graph has generation number zero for commit %s, but non-zero elsewhere"), oid_to_hex(&cur_oid)); diff --git a/t/t5318-commit-graph.sh b/t/t5318-commit-graph.sh index 4df76173a8..4e70820c74 100755 --- a/t/t5318-commit-graph.sh +++ b/t/t5318-commit-graph.sh @@ -598,7 +598,7 @@ test_expect_success 'detect incorrect generation number' ' test_expect_success 'detect incorrect generation number' ' corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_GENERATION "\01" \ - "commit-graph generation for commit" + "but zero elsewhere" ' test_expect_success 'detect incorrect commit date' ' From patchwork Thu Aug 10 20:37:37 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13349908 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 9DCE4C04A94 for ; Thu, 10 Aug 2023 20:37:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235350AbjHJUhl (ORCPT ); Thu, 10 Aug 2023 16:37:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32828 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235323AbjHJUhl (ORCPT ); Thu, 10 Aug 2023 16:37:41 -0400 Received: from mail-yw1-x1133.google.com (mail-yw1-x1133.google.com [IPv6:2607:f8b0:4864:20::1133]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 77039273C for ; Thu, 10 Aug 2023 13:37:39 -0700 (PDT) Received: by mail-yw1-x1133.google.com with SMTP id 00721157ae682-58411e24eefso15172767b3.1 for ; Thu, 10 Aug 2023 13:37:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20221208.gappssmtp.com; s=20221208; t=1691699858; x=1692304658; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=rsn/XV3KpU9p50eo6y3IvKaLDzhPXSi3l9b0jiM0OSY=; b=ppLz83sXXYaSFgfdgYlGJM62xJfMRFUVNRyZueUIEcoAmq8Pw//d4MeRLohp4VXd0r F4I8TyRXQGFQxf/hkgAybDcHFHv80CyAqjfI9wDEzjzW6I2W391p6HHCK7Ti1ZGZ1efy V0uMFkBNjMlGlQEOF8qibNQISyZhIkYGwrEkxwv8B9ZfLAotgdS/g+oLS2c1/p2NgBcd bVBfZAJM6YHPLT/FXsBnSfMTOzfMm4DIPvEUluyABIBvb56uLAIUU5K7DRqKg5Pw//Zs SU4EapHBkWIhngXKDx7Z+qJ1vKewk3LPuoaLumm0Zt6qetjlsOTu/+GBE6yblFWA1HHZ inRA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691699858; x=1692304658; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=rsn/XV3KpU9p50eo6y3IvKaLDzhPXSi3l9b0jiM0OSY=; b=d+I3FDVEx31re7L2dFXDwgGkW6UTReOaiLWBmH+YKklOfRtphQvsZQT7VnWunq7UBX 0SEI/FRJCIfzEM5EyH5OaknIMoHQZYGe340SHqiUoU0iK0uTy81m5g9uPOwFVaQI2MT4 r+kGF0xLTWIUph75DhNHteBF9PWKKkMZJjliIAbrnzSFc4iYr90GMeR8oCo9MeIfjdec /V9bxUOz1yLZPWmaJOdP6jDXypty0uwhITyWpoAHiHqa+0tfBIxcHFP1vGgISoGhbXxy wkXJMzlFCN3NPhB1XVih5bCODoSaOMcZi8zr5h9EnS/ciIzXR9vGAjBZmZTERgFmy3DP a/XQ== X-Gm-Message-State: AOJu0YyCd4FTc7Hq5K6YgKzYLPwM0oeqj1wdbuoN23rBdqNgoqn6dCaL c1uygPRxx/4qaWqvGsalhrkjupBNIDGPr3FGnMOazQ== X-Google-Smtp-Source: AGHT+IF2KrGEKDa2mPuojfepwXCVrL8zSlcd1q1bVO6uyXe+azhG18HKyPrDChVZDcAHJC2PsPFNZA== X-Received: by 2002:a25:ac89:0:b0:d4b:7495:6317 with SMTP id x9-20020a25ac89000000b00d4b74956317mr3783243ybi.28.1691699858500; Thu, 10 Aug 2023 13:37:38 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id l35-20020a25b323000000b00d0d2c7dbfecsm544970ybj.7.2023.08.10.13.37.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Aug 2023 13:37:38 -0700 (PDT) Date: Thu, 10 Aug 2023 16:37:37 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Derrick Stolee Subject: [PATCH 2/4] commit-graph: verify swapped zero/non-zero generation cases Message-ID: <9b9483893c072961c5871bd0bae17a7098d73c06.1691699851.git.me@ttaylorr.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Jeff King In verify_one_commit_graph(), we have code that complains when a commit is found with a generation number of zero, and then later with a non-zero number. It works like this: 1. When we see an entry with generation zero, we set the generation_zero flag to GENERATION_ZERO_EXISTS. 2. When we later see an entry with a non-zero generation, we complain if the flag is GENERATION_ZERO_EXISTS. There's a matching GENERATION_NUMBER_EXISTS value, which in theory would be used to find the case that we see the entries in the opposite order: 1. When we see an entry with a non-zero generation, we set the generation_zero flag to GENERATION_NUMBER_EXISTS. 2. When we later see an entry with a zero generation, we complain if the flag is GENERATION_NUMBER_EXISTS. But that doesn't work; step 2 is implemented, but there is no step 1. We never use NUMBER_EXISTS at all, and Coverity rightly complains that step 2 is dead code. We can fix that by implementing that step 1. Signed-off-by: Jeff King Signed-off-by: Taylor Blau --- commit-graph.c | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/commit-graph.c b/commit-graph.c index c68f5c6b3a..acca753ce8 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -2686,9 +2686,12 @@ static int verify_one_commit_graph(struct repository *r, graph_report(_("commit-graph has generation number zero for commit %s, but non-zero elsewhere"), oid_to_hex(&cur_oid)); generation_zero = GENERATION_ZERO_EXISTS; - } else if (generation_zero == GENERATION_ZERO_EXISTS) - graph_report(_("commit-graph has non-zero generation number for commit %s, but zero elsewhere"), - oid_to_hex(&cur_oid)); + } else { + if (generation_zero == GENERATION_ZERO_EXISTS) + graph_report(_("commit-graph has non-zero generation number for commit %s, but zero elsewhere"), + oid_to_hex(&cur_oid)); + generation_zero = GENERATION_NUMBER_EXISTS; + } if (generation_zero == GENERATION_ZERO_EXISTS) continue; From patchwork Thu Aug 10 20:37:39 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13349909 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 41DFFC001DE for ; Thu, 10 Aug 2023 20:37:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235402AbjHJUho (ORCPT ); Thu, 10 Aug 2023 16:37:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32868 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235364AbjHJUhm (ORCPT ); Thu, 10 Aug 2023 16:37:42 -0400 Received: from mail-yw1-x112f.google.com (mail-yw1-x112f.google.com [IPv6:2607:f8b0:4864:20::112f]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F351E2738 for ; Thu, 10 Aug 2023 13:37:41 -0700 (PDT) Received: by mail-yw1-x112f.google.com with SMTP id 00721157ae682-583f036d50bso15055537b3.3 for ; Thu, 10 Aug 2023 13:37:41 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20221208.gappssmtp.com; s=20221208; t=1691699861; x=1692304661; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=jiOlJUhG+9no+fop+p2xwp8mlQwHAHXweQz3coMlkzs=; b=g1bOKIG7zrQKwG3q8mStpFUQ3mPw398TIH4qcmNa7oMcDh4NPYYdQmG3najkEHZmZ+ fh5BcgNZuvXzSPmwOIRZUuLObTgqzIyuNq75lhEtCdM5VGwIRKvBN074uSpm1qFFevm0 z72LyX6h21SI4oVgHTwpp57EcaC8hWfd/BBw7AvfQzL39BRCnY6Dx9gjh0RIufVj8tuX yP/kj5N1JrNtnbifbsS2ovj9tejpgw2zRADgJMz0Cj3Dcw0Wed6fvZ0pLeUA2k0fJrtV TpGzx3Wro0l6QOWcP1jUyun0Y3FRy0yTa4pYsVzPDN3DLvHbY/Z1EVOcwRsS6Sk6qT/v tCAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691699861; x=1692304661; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=jiOlJUhG+9no+fop+p2xwp8mlQwHAHXweQz3coMlkzs=; b=fEUHf35mGYbuh9wsemuTlAozhVwrHn/UGj6wIEVZHXC4NOWQ/HFkMVzagqQfyqT1Lj ChUQVtEGkSNa7jrzKMexegRyzDpq8wThD7BmxS4k6qAxJXTys0JCUVvF5sGzaV4wLSfT nC9/dSpqc9rff/Gbj93X6ggI6xK75T1I++etkJCVBsd0hpw2h/uPByDMsNVHYEdq4SW2 v/ChX+1mII/0z1L+CM2qRIS9QK9vCgehYFNxVhTEZmRAaWIYCmRCXTjoGEyHavBUZpoJ odssOoe7gPp8eRhCyKwiWAX2S32cC5xsfQWP2OC1OxPPf7RcV0RjO6PcBH88bYyQ/Kew 5wjw== X-Gm-Message-State: AOJu0Yy3/lI9YjKd9B2cQbealudvQ5onx9mYx/lbFMkXnos/5/0x+ji1 ogqDhv6CtJ5S9L7aGEj7yLo/gtyZNwcU8zRKwON+Rw== X-Google-Smtp-Source: AGHT+IHMpmAYgROY+vVG6rHOGVaV6XMvD5w0SKFbI/mM13UgwiuXUwaYo6saKE0HU54QcLnUQtleIA== X-Received: by 2002:a81:6d43:0:b0:589:a5b5:4e65 with SMTP id i64-20020a816d43000000b00589a5b54e65mr16793ywc.3.1691699860973; Thu, 10 Aug 2023 13:37:40 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id d125-20020a814f83000000b005869e7171d4sm565704ywb.80.2023.08.10.13.37.40 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Aug 2023 13:37:40 -0700 (PDT) Date: Thu, 10 Aug 2023 16:37:39 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Derrick Stolee Subject: [PATCH 3/4] t/t5318-commit-graph.sh: test generation zero transitions during fsck Message-ID: <8679db3d0e895bef7f9a12d8d6742ca812768241.1691699851.git.me@ttaylorr.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The second test called "detect incorrect generation number" asserts that we correctly warn during an fsck when we see a non-zero generation number after seeing a zero beforehand. The other transition (going from non-zero to zero) was previously untested. Test both directions, and rename the existing test to make clear which direction it is exercising. Signed-off-by: Taylor Blau --- t/t5318-commit-graph.sh | 18 ++++++++++++------ 1 file changed, 12 insertions(+), 6 deletions(-) diff --git a/t/t5318-commit-graph.sh b/t/t5318-commit-graph.sh index 4e70820c74..8e96471b34 100755 --- a/t/t5318-commit-graph.sh +++ b/t/t5318-commit-graph.sh @@ -450,14 +450,15 @@ GRAPH_BYTE_FANOUT2=$(($GRAPH_FANOUT_OFFSET + 4 * 255)) GRAPH_OID_LOOKUP_OFFSET=$(($GRAPH_FANOUT_OFFSET + 4 * 256)) GRAPH_BYTE_OID_LOOKUP_ORDER=$(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * 8)) GRAPH_BYTE_OID_LOOKUP_MISSING=$(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * 4 + 10)) +GRAPH_COMMIT_DATA_WIDTH=$(($HASH_LEN + 16)) GRAPH_COMMIT_DATA_OFFSET=$(($GRAPH_OID_LOOKUP_OFFSET + $HASH_LEN * $NUM_COMMITS)) GRAPH_BYTE_COMMIT_TREE=$GRAPH_COMMIT_DATA_OFFSET GRAPH_BYTE_COMMIT_PARENT=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN)) GRAPH_BYTE_COMMIT_EXTRA_PARENT=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 4)) GRAPH_BYTE_COMMIT_WRONG_PARENT=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 3)) GRAPH_BYTE_COMMIT_GENERATION=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 11)) +GRAPH_BYTE_COMMIT_GENERATION_LAST=$(($GRAPH_BYTE_COMMIT_GENERATION + $(($NUM_COMMITS - 1)) * $GRAPH_COMMIT_DATA_WIDTH)) GRAPH_BYTE_COMMIT_DATE=$(($GRAPH_COMMIT_DATA_OFFSET + $HASH_LEN + 12)) -GRAPH_COMMIT_DATA_WIDTH=$(($HASH_LEN + 16)) GRAPH_OCTOPUS_DATA_OFFSET=$(($GRAPH_COMMIT_DATA_OFFSET + \ $GRAPH_COMMIT_DATA_WIDTH * $NUM_COMMITS)) GRAPH_BYTE_OCTOPUS=$(($GRAPH_OCTOPUS_DATA_OFFSET + 4)) @@ -596,11 +597,6 @@ test_expect_success 'detect incorrect generation number' ' "generation for commit" ' -test_expect_success 'detect incorrect generation number' ' - corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_GENERATION "\01" \ - "but zero elsewhere" -' - test_expect_success 'detect incorrect commit date' ' corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_DATE "\01" \ "commit date" @@ -622,6 +618,16 @@ test_expect_success 'detect incorrect chunk count' ' $GRAPH_CHUNK_LOOKUP_OFFSET ' +test_expect_success 'detect mixed generation numbers (non-zero to zero)' ' + corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_GENERATION_LAST "\0\0\0\0" \ + "but non-zero elsewhere" +' + +test_expect_success 'detect mixed generation numbers (zero to non-zero)' ' + corrupt_graph_and_verify $GRAPH_BYTE_COMMIT_GENERATION "\0\0\0\0" \ + "but zero elsewhere" +' + test_expect_success 'git fsck (checks commit-graph when config set to true)' ' git -C full fsck && corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \ From patchwork Thu Aug 10 20:37:42 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13349910 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C2DE7C001DE for ; Thu, 10 Aug 2023 20:37:48 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S235364AbjHJUhs (ORCPT ); Thu, 10 Aug 2023 16:37:48 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:32900 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235407AbjHJUhp (ORCPT ); Thu, 10 Aug 2023 16:37:45 -0400 Received: from mail-yw1-x112c.google.com (mail-yw1-x112c.google.com [IPv6:2607:f8b0:4864:20::112c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 7E5682738 for ; Thu, 10 Aug 2023 13:37:44 -0700 (PDT) Received: by mail-yw1-x112c.google.com with SMTP id 00721157ae682-5768a7e3adbso35194357b3.0 for ; Thu, 10 Aug 2023 13:37:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20221208.gappssmtp.com; s=20221208; t=1691699863; x=1692304663; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:from:to:cc:subject:date:message-id:reply-to; bh=Yp8HVkrkFJaxoMxwM1nWT97ItGYpT0fKmOAQGws37dI=; b=fv1YPpc6kHfnC0FduMPPXf1x5flesiuEP1gUMlkPJe5e9XuQl/m4P3u862t6s4c3+q PuFmfr8b3LPbbM7tq7nu6yI5zfXvnsgPVGzvKzbeltmhR0+50M0iArXWovIacXGHPy4Q VPto1dAf5QG6lxXxV8ghy442rC8G3/1s69oItvphFfbAGeZKgli5GB0TFaHjZNoZC5fU ROfihiojRWD4YAr+uGFSdvfbuNRCfIrxR5DLT+IlI8jhkJufV0nZV/11CAueQdAwpC8H jL2RyQVp/d1w66lsRieTQ2isVzkP7WcNGkv3mPd5SvYXhScU9nYE3TwFLaLpI0PnrDHM ncuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1691699863; x=1692304663; h=in-reply-to:content-disposition:mime-version:references:message-id :subject:cc:to:from:date:x-gm-message-state:from:to:cc:subject:date :message-id:reply-to; bh=Yp8HVkrkFJaxoMxwM1nWT97ItGYpT0fKmOAQGws37dI=; b=HnijZ9lVESSfkbZE9OSvEa6eYU/7/6VdVAsBEbXyRDa3bzMAhX1aL/7FXf/IJy3ugu T+2mN79k/fEm1TnB1l/kTuR2XYrlx9lKvXWxXN2CG7ur+mm1HRDCckyViIUcv3KlnkfJ CVlR0lU4BW61OK2qhxXQ6tx/LxB/ItEWB+BZZ93QC8k5HP+N0wEyUa9Dnu9iSfj8tuJx K2xoYzYGa3ZTxOf2sAp8vOtfBVzsmWj4GfMBwLzF/YRFcciYlYfubo0A95u1WM+F5ps+ fo1P6TT7k5GRymkNOkHo9dDlhqKEczm9mLu3BINa3kZtl63W+Wn6Nse+lasdGik8+WlD tl3w== X-Gm-Message-State: AOJu0Ywpgzgofa17Ra3RxU+OxObzg9wCLdVB3xbJxTUqSnF6BTH/PD62 ToMfd6s4z6RwOEhJawwAS67gLTQjngfGCS3qhL8Njg== X-Google-Smtp-Source: AGHT+IHnyy6H7qgOCbH9br8cT4VrUXOzAOKXe3r88Ajoi4HoIdfg2aRFMiYZ8lDlSfaPqk9J/ChNdg== X-Received: by 2002:a81:8482:0:b0:586:a680:250 with SMTP id u124-20020a818482000000b00586a6800250mr7113ywf.5.1691699863558; Thu, 10 Aug 2023 13:37:43 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id f184-20020a0ddcc1000000b0057a44e20fb8sm570773ywe.73.2023.08.10.13.37.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Aug 2023 13:37:43 -0700 (PDT) Date: Thu, 10 Aug 2023 16:37:42 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Derrick Stolee Subject: [PATCH 4/4] commit-graph: invert negated conditional Message-ID: <6ea610f7d2faf77d1984d641d1b857a9c4b1214d.1691699851.git.me@ttaylorr.com> References: MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Now that we're using `commit_graph_generation_from_graph()` (which can return a zero value) and we have a pure if/else instead of an else-if, let's swap the arms of the if-statement. This avoids an "if (!x) { foo(); } else { bar(); }" and replaces it with the more readable "if (x) { bar(); } else { foo(); }". Signed-off-by: Taylor Blau --- commit-graph.c | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/commit-graph.c b/commit-graph.c index acca753ce8..b2cf9ed9d5 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -2681,16 +2681,16 @@ static int verify_one_commit_graph(struct repository *r, graph_report(_("commit-graph parent list for commit %s terminates early"), oid_to_hex(&cur_oid)); - if (!commit_graph_generation_from_graph(graph_commit)) { - if (generation_zero == GENERATION_NUMBER_EXISTS) - graph_report(_("commit-graph has generation number zero for commit %s, but non-zero elsewhere"), - oid_to_hex(&cur_oid)); - generation_zero = GENERATION_ZERO_EXISTS; - } else { + if (commit_graph_generation_from_graph(graph_commit)) { if (generation_zero == GENERATION_ZERO_EXISTS) graph_report(_("commit-graph has non-zero generation number for commit %s, but zero elsewhere"), oid_to_hex(&cur_oid)); generation_zero = GENERATION_NUMBER_EXISTS; + } else { + if (generation_zero == GENERATION_NUMBER_EXISTS) + graph_report(_("commit-graph has generation number zero for commit %s, but non-zero elsewhere"), + oid_to_hex(&cur_oid)); + generation_zero = GENERATION_ZERO_EXISTS; } if (generation_zero == GENERATION_ZERO_EXISTS)