From patchwork Mon Aug 21 21:34: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: 13359838 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 AE7F4EE49A5 for ; Mon, 21 Aug 2023 21:34:39 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230167AbjHUVej (ORCPT ); Mon, 21 Aug 2023 17:34:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:42464 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229518AbjHUVej (ORCPT ); Mon, 21 Aug 2023 17:34:39 -0400 Received: from mail-yw1-x1136.google.com (mail-yw1-x1136.google.com [IPv6:2607:f8b0:4864:20::1136]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F23B410E for ; Mon, 21 Aug 2023 14:34:36 -0700 (PDT) Received: by mail-yw1-x1136.google.com with SMTP id 00721157ae682-59234aaca15so10365857b3.3 for ; Mon, 21 Aug 2023 14:34:36 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20221208.gappssmtp.com; s=20221208; t=1692653676; x=1693258476; 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=l5d8NzSBkSiNkrrtEFvPrJ7LnWsfZfx/6iDS0oVdLVk=; b=sDNz5ypVpTpHl84IB0lari4sZjxOnpcB8ZeU6PEFIDOgynFKpOX/1rHgaqpCZNMOuK O0NlEF0vYSyocVsIXLCh3v8Q2TAzC58CdNuzO2TGd8YWWT3+dX3emdxssSDFR58vkgCN EkH1waUYkm+/Bo6Ta61f1SAmtxnGNo230vzlIZ0bJjOA5jpipdvvFcuTENM/qIrEtyXk v/OtpfqzVu8vVfqtVEe3EXcAUrSDeItqk9mH13x3sJj0bf6akbbvexjozSDuXec2C7im Yn3OMLPqYqI52X/m4SA8+VyN+FIAnVD+lG6SfhjCRMtigfyXrpCj6Y8RAL1KxLsMB6w4 vY+g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692653676; x=1693258476; 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=l5d8NzSBkSiNkrrtEFvPrJ7LnWsfZfx/6iDS0oVdLVk=; b=OdsAbQURBtahP5YduIXlcdyEy9cmCYfmRClqXAemmeayO1WszWGYK2Bul4/8yR6ave RSTFbJRYV8o9tskIqBZIOdJu4ysk9eRvnvkV3Ipsa/kHKrrNg56w0KaBOkc9jA6pDxqF RObp6Y8qV5FM+RvgCtN+w449ygTG1peytdvY7AIsNkYyQjuvV+AQDU1G50MXWOYjBEPk S+2ACnqm9Q66Cl3TkbWK5g1ecx9gUbk1+qV76ovJmjYGQUJZMMFMTmYibaw4ZzRk82qT ouAAavCEjJG9tw82OUjnogV0K+iVOUUtoXPKjn5nIRGaJvGFqE+nGS6FStywk3O5xOj3 UaPg== X-Gm-Message-State: AOJu0YwEgR+NlbNjlErlHwcho3Vi5PoTCgR0sEqk4FOcdFxL8bQThY8D cXH0TrObZGHlJxm+GQrvKjtNynHZrJHQh1ELaFQ/ww== X-Google-Smtp-Source: AGHT+IESg4rlTzgi0CZcT3ABKU4g+LCCmtNeJ2ZYiXfebdc26YvAR6+heasV1B4ZbcwmiakdwUFEvw== X-Received: by 2002:a0d:d1c4:0:b0:583:b2a3:f780 with SMTP id t187-20020a0dd1c4000000b00583b2a3f780mr6970413ywd.49.1692653676040; Mon, 21 Aug 2023 14:34:36 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id c10-20020a81df0a000000b00577044eb00esm2395948ywn.21.2023.08.21.14.34.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Aug 2023 14:34:35 -0700 (PDT) Date: Mon, 21 Aug 2023 17:34:34 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Derrick Stolee Subject: [PATCH v3 1/4] commit-graph: introduce `commit_graph_generation_from_graph()` Message-ID: 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 Mon Aug 21 21:34: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: 13359839 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 65BB1EE4996 for ; Mon, 21 Aug 2023 21:34:44 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230231AbjHUVeo (ORCPT ); Mon, 21 Aug 2023 17:34:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39502 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229518AbjHUVen (ORCPT ); Mon, 21 Aug 2023 17:34:43 -0400 Received: from mail-yb1-xb2b.google.com (mail-yb1-xb2b.google.com [IPv6:2607:f8b0:4864:20::b2b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CB921116 for ; Mon, 21 Aug 2023 14:34:39 -0700 (PDT) Received: by mail-yb1-xb2b.google.com with SMTP id 3f1490d57ef6-d7485d37283so2209763276.1 for ; Mon, 21 Aug 2023 14:34:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20221208.gappssmtp.com; s=20221208; t=1692653679; x=1693258479; 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=Jlb4stkDk/YPWFDkKIlLo1/NLXcPj/5xIHz7ofLlxvg=; b=He1yqnlO/zL5Vib4tg8yfnNUi9vVlyGoCgGDxln/hSFxN7XmIVOSF4DnQfZ4tMnZCx jDOO2Vw+ZVe5w9AOvFtj1ilXWMG/4pVqR1T6qMdi8PJE6YnJoiMpMo3sVTmi+n5z1pWH +mq/4vflRs2+g70awCO5gzayoMykLBWfTUKSlfo7vY/tjWvZzN9mUYzevjqD0yeEZmoA G3OWDaHEgDzGhdJOwt247iA2ylmLOu7OKUqOPL0oB1pN6IRIOfsvoi879BVwHhlM6+e6 q3FEJoyD/C0obMDrtju6e9O9QMYJFJMdXuy4tnU8pSw4MV8CVcz8KxpAgaGIQH7PEWV/ ZHNA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692653679; x=1693258479; 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=Jlb4stkDk/YPWFDkKIlLo1/NLXcPj/5xIHz7ofLlxvg=; b=Pz7NmJrjfxaT6SpiG1W3sOAgrL1cF+C/6nQCZMlv0qDpTr6VxpkPMjQrCPcFiWleqv xFLNuyCIsbd597Mi6OI0GxiLSudG3YdVVSE4agurZx3ocWcBiTdCZhPmsto8sf//5mbc eH5zPP21IOeirEh0GuMUNGSpDCiMywRvKxKlBt+Yr1cv6XcdNxP7/d/c1jM6HFpSgubb NSvMKNf47BelgHhIAiBuRt69wLwLNHqOgVrjsq3/X5HRokDY5J5Z/ybse2XCKJk5O9aR qSZnEKze85AnQx34iZAm0uncrqmlUdX6LsuldJQgAbLbhNFIfu0nBk7MvjDLbZXBmfSR wH/Q== X-Gm-Message-State: AOJu0YwkjKzQCfH9WPqpLKE32ZenogBja0InYGpb+ZLhtx8ZULxei62O Zji41r6+PMrM7YwGUDCXI/CA+1RAWvs4JhzQT3+mrA== X-Google-Smtp-Source: AGHT+IFUDOxYFlncthPvrlv1bCqWAsi103QMo6kD5djBMY6JQvezjTJ8oJKRAUyoEseaxjO1PkV/rw== X-Received: by 2002:a25:8689:0:b0:d0c:ceef:c668 with SMTP id z9-20020a258689000000b00d0cceefc668mr9214609ybk.25.1692653678785; Mon, 21 Aug 2023 14:34: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 e191-20020a2537c8000000b00d6861b49f01sm2053449yba.65.2023.08.21.14.34.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Aug 2023 14:34:38 -0700 (PDT) Date: Mon, 21 Aug 2023 17:34:37 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Derrick Stolee Subject: [PATCH v3 2/4] commit-graph: verify swapped zero/non-zero generation cases Message-ID: <8f8e0b6644135717e0035ffbcb18446a5d83d192.1692653671.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 Mon Aug 21 21:34:40 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Taylor Blau X-Patchwork-Id: 13359840 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 8958AEE49A6 for ; Mon, 21 Aug 2023 21:34:45 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230434AbjHUVep (ORCPT ); Mon, 21 Aug 2023 17:34:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39556 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230140AbjHUVeo (ORCPT ); Mon, 21 Aug 2023 17:34:44 -0400 Received: from mail-yb1-xb34.google.com (mail-yb1-xb34.google.com [IPv6:2607:f8b0:4864:20::b34]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 59AF910E for ; Mon, 21 Aug 2023 14:34:42 -0700 (PDT) Received: by mail-yb1-xb34.google.com with SMTP id 3f1490d57ef6-d678b44d1f3so5223660276.0 for ; Mon, 21 Aug 2023 14:34:42 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20221208.gappssmtp.com; s=20221208; t=1692653681; x=1693258481; 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=KdpcKTE34f/TnkW6tiomJjCGgN3+mUvs49ILwJA/UW0=; b=SG8Fdxukmo1r52bVRLQyZ4qWZvGaWYvBJkPxBFwruUQe78wVJKgrFYWU0nfV+rBoty IR6wMRqgNa6uHFC26kC/JaBxpJjV2Qn46WaSo6CntbkT12fzzVjVDhHcMDflN7QjQwk3 37Lfhh5e6v3JkbyGbXmHLzP8PM4t8OHe7w2KojTkQV/x4/ofIXZE9AAoZu6dGNq5pUdw xHVI89K6lei6g9bknMhtmXvpu1RKSn+vDbi+fvJmXanJLO5HMDIos3rZElQHFNhkLKnY ji+0pKhSQMObx3OSv9rdVWD0Uzkdbhss0ZyYcW0CzUJVCyBH4IDDSGr8QXUXx47X0sS/ oC7g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692653681; x=1693258481; 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=KdpcKTE34f/TnkW6tiomJjCGgN3+mUvs49ILwJA/UW0=; b=Ox7SvgQ2Cuiyjbpf0BFbmNp/QLSAIi4MuQDSBzWmW4TuHzIioX9RzjUyOArFkFNI5/ FqWf5uhyjUjcYlhJKpZVeL6cW856FNPRIDNG+aUcU4Y3ESzpNHSwbTTIWMrKxii6xr7s HIBjq7IZjm/PhfZY153mpF6e9s/h9LBqhF3Bv1sl6tIFIIBwz0NiVtkJeIb3Z5WrIaym Sfo6U0g6M5+hL0hYgZc91KLASLiCkIEs8yHHEK/YYUauD7MFpdy6B/XXzToCqN2jtrMp GL2dfU8QoXAUJfl31tiQzMovGOMpT75dC4vfU1Wxj6Pa0vVM6Skg118OHrovHxqZTqzw LHCg== X-Gm-Message-State: AOJu0Yzy64LjAtc+137x0wpc+eIH0PA4fJZfrPLn+hQKesIbB0+FIbGC SjpOA77VeA18nwkfNEvBiY1t2zrKDGw3aWvdAMpu/w== X-Google-Smtp-Source: AGHT+IFNWBbbPnyBYJcKVdkhUbqv2Vde8iIi8Yw8qi6paKeCE1amQx2m7x8Ouq96+rNu2xst1Q9UaA== X-Received: by 2002:a5b:609:0:b0:d21:3e0d:4447 with SMTP id d9-20020a5b0609000000b00d213e0d4447mr6048697ybq.12.1692653681344; Mon, 21 Aug 2023 14:34:41 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id 206-20020a2506d7000000b00d1f0204c1b6sm2057276ybg.27.2023.08.21.14.34.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Aug 2023 14:34:41 -0700 (PDT) Date: Mon, 21 Aug 2023 17:34:40 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Derrick Stolee Subject: [PATCH v3 3/4] t/t5318-commit-graph.sh: test generation zero transitions during fsck Message-ID: <34a505dd4b94a03e57556841c86802f8043c0e56.1692653671.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 Mon Aug 21 21:34: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: 13359841 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 630A4EE4996 for ; Mon, 21 Aug 2023 21:34:50 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230483AbjHUVeu (ORCPT ); Mon, 21 Aug 2023 17:34:50 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230459AbjHUVet (ORCPT ); Mon, 21 Aug 2023 17:34:49 -0400 Received: from mail-oi1-x234.google.com (mail-oi1-x234.google.com [IPv6:2607:f8b0:4864:20::234]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 09587133 for ; Mon, 21 Aug 2023 14:34:45 -0700 (PDT) Received: by mail-oi1-x234.google.com with SMTP id 5614622812f47-3a812843f0fso2291159b6e.2 for ; Mon, 21 Aug 2023 14:34:45 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ttaylorr-com.20221208.gappssmtp.com; s=20221208; t=1692653684; x=1693258484; 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=bCMXdNFyiCh4dmsIJPYjqZttwI/hyKg2AP3DgpjyCYg=; b=Vf60gQux0cYSxCvnh+AC9vbAgvRSUdbd2LCB2Avr6468uRAXKGkrldnVQ3YtQvzg7l a08slo4DM7WPg4nHdCQZXfk6EopQVBDHg9vPeUmAPON7tkAN4HlKHaWetEO373KF0zSY KtybG3pkDHhDO26d871Ezxr21tANz7pu2r25BIZxuG1JiKuIRfWryn4BOqL1Gc2Cm1vj 6DgNpBdHQiJm2w58PRpS0iEjcpLQVio+U9i2IfbhFv1QcTDWGp4ivEhjon52QXIFdODd 90ogjKqvxOwwkk2nV9EgZC2RLmRO5q7kD6DqJ76oQxtB7OXD2rVx1DtQrTTi6oxE6XOL FysA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1692653684; x=1693258484; 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=bCMXdNFyiCh4dmsIJPYjqZttwI/hyKg2AP3DgpjyCYg=; b=E55ceaSFgdxP15SRL2MSehk7t/2imfg4le/GKf6iiJ0shLfh0ZDpygrpWxmPgTpTJC LX/lKoDBW1TlZ1FutcZxRZHMSpS9f7q8VNthPtbDJjhZ7wOXMgyuOH00/DH/AJmEmIht 7PTXdkVGHHLDboSCAhyBi8nsFZF5GwUwHJyOYAOxdKDQEQKJvCtPhsctvjqQMOHE0tdi O5lh9CsBVrXLybaT+QGNQmDBTSnNt149+1qwxZi1+Do0MySleJJLRF3Ya5FwMQglIDmg u1XfPVehQGAfZe2uh2RFLDMxn11WmohKbQIxuo9c8l++gy7xVCsrqzB80SFelS9oXdgZ JN0w== X-Gm-Message-State: AOJu0YyYzxn7/Y3uTcdjWhRKKb1xW9qRzc1zx2DJNG1TMTG5fM3tjUKQ gW6g81Mzfzrd2QYySos6mSyQboYtSdAsxprpNEKSRA== X-Google-Smtp-Source: AGHT+IHWCT9FN13v79hAWWjOAyg86xuHzrgYofMQsuLlH++KodjRvJL9ak6jIGalwRBG4ZrLvuSmPQ== X-Received: by 2002:a05:6358:70f:b0:134:e63f:a891 with SMTP id e15-20020a056358070f00b00134e63fa891mr3511959rwj.29.1692653684065; Mon, 21 Aug 2023 14:34:44 -0700 (PDT) Received: from localhost (104-178-186-189.lightspeed.milwwi.sbcglobal.net. [104.178.186.189]) by smtp.gmail.com with ESMTPSA id v17-20020a814811000000b00583b40d907esm2451150ywa.16.2023.08.21.14.34.43 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 21 Aug 2023 14:34:43 -0700 (PDT) Date: Mon, 21 Aug 2023 17:34:42 -0400 From: Taylor Blau To: git@vger.kernel.org Cc: Junio C Hamano , Jeff King , Derrick Stolee Subject: [PATCH v3 4/4] commit-graph: commit-graph: avoid repeated mixed generation number warnings Message-ID: <52b49bb43492f1dad366eb438b0c23e065c37710.1692653671.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 When validating that a commit-graph has either all zero, or all non-zero generation numbers, we emit a warning on both the rising and falling edge of transitioning between the two. So if we are unfortunate enough to see a commit-graph which has a repeating sequence of zero, then non-zero generation numbers, we'll generate many warnings that contain more or less the same information. Avoid this by keeping track of a single example for a commit with zero- and non-zero generation, and emit a single warning at the end of verification if both are non-NULL. Co-authored-by: Jeff King Signed-off-by: Jeff King Signed-off-by: Taylor Blau --- commit-graph.c | 29 +++++++++++++---------------- t/t5318-commit-graph.sh | 4 ++-- 2 files changed, 15 insertions(+), 18 deletions(-) diff --git a/commit-graph.c b/commit-graph.c index acca753ce8..9e6eaa8a46 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -2560,9 +2560,6 @@ static void graph_report(const char *fmt, ...) va_end(ap); } -#define GENERATION_ZERO_EXISTS 1 -#define GENERATION_NUMBER_EXISTS 2 - static int commit_graph_checksum_valid(struct commit_graph *g) { return hashfile_checksum_valid(g->data, g->data_len); @@ -2575,7 +2572,8 @@ static int verify_one_commit_graph(struct repository *r, { uint32_t i, cur_fanout_pos = 0; struct object_id prev_oid, cur_oid; - int generation_zero = 0; + struct commit *seen_gen_zero = NULL; + struct commit *seen_gen_non_zero = NULL; verify_commit_graph_error = verify_commit_graph_lite(g); if (verify_commit_graph_error) @@ -2681,19 +2679,12 @@ 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 (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 (commit_graph_generation_from_graph(graph_commit)) + seen_gen_non_zero = graph_commit; + else + seen_gen_zero = graph_commit; - if (generation_zero == GENERATION_ZERO_EXISTS) + if (seen_gen_zero) continue; /* @@ -2719,6 +2710,12 @@ static int verify_one_commit_graph(struct repository *r, odb_commit->date); } + if (seen_gen_zero && seen_gen_non_zero) + graph_report(_("commit-graph has both zero and non-zero " + "generations (e.g., commits '%s' and '%s')"), + oid_to_hex(&seen_gen_zero->object.oid), + oid_to_hex(&seen_gen_non_zero->object.oid)); + return verify_commit_graph_error; } diff --git a/t/t5318-commit-graph.sh b/t/t5318-commit-graph.sh index 8e96471b34..ba65f17dd9 100755 --- a/t/t5318-commit-graph.sh +++ b/t/t5318-commit-graph.sh @@ -620,12 +620,12 @@ test_expect_success 'detect incorrect chunk count' ' 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" + "both zero and non-zero generations" ' 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" + "both zero and non-zero generations" ' test_expect_success 'git fsck (checks commit-graph when config set to true)' '