From patchwork Mon Mar 25 12:08:27 2019 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: 10868967 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id E72DC139A for ; Mon, 25 Mar 2019 12:08:49 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D17AF2915D for ; Mon, 25 Mar 2019 12:08:49 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id C41F629175; Mon, 25 Mar 2019 12:08:49 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 62D3A2932D for ; Mon, 25 Mar 2019 12:08:49 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731112AbfCYMIr (ORCPT ); Mon, 25 Mar 2019 08:08:47 -0400 Received: from mail-wr1-f53.google.com ([209.85.221.53]:42297 "EHLO mail-wr1-f53.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731098AbfCYMIr (ORCPT ); Mon, 25 Mar 2019 08:08:47 -0400 Received: by mail-wr1-f53.google.com with SMTP id g3so6336737wrx.9 for ; Mon, 25 Mar 2019 05:08:46 -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=TryJBwAkwQxDm1aGGzWLrQtjnpTYQFOtNncA80STXMk=; b=rbNu7yl/AD2PXbwqbLdE1vngRaXOm6SgNoGCkWom8JSd63kCzsb5RIGSkTVna6zKBO GG0zfjqWEN9T29lqlunu9MTABMRCsYi9XSGC8aLkknR7vQbI4XRzQEBoyqYfU255OGqh n5IXnXFb9yhLyKTml/8BQ1j5paTKdhXsU69pbltAyxNtCL8AeC5ETDxumLOCZ9vOc63o femUBd2Ft8lYAHUMpjZ+XFXJbWjgLyp8HCk4uY/kNCAeqJVE5G7HPTK0EpYjYfYPinUO RUsZPF2He6EWJLKXC3RlUyyFyL0f3DKHPqpkMZ2EDJwfiGRIdi0TsA6kQmhA6+OfOvpk /EkA== 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=TryJBwAkwQxDm1aGGzWLrQtjnpTYQFOtNncA80STXMk=; b=X5AAYLn8uE/M/TGDC0sHKO5y7PVylLbUFQt+DKxeUIoLeR8fYWbz8RrZ+2KsOR5Dsi 3z+nzADFu75BBAHbR+FI63jUpF/N/OHe4wE70IJst++aTTbeQb8vPKRGWSFLFTWJ0o6C mV2iDWlm91Ykuhn/IKlOEFXZx+fqBDrJ3w09/EB3ERBbClPvPZXcJMecLASWTm/AAfDi jem/B+42d2khi/NxYB/wLFy+sEsYUOneOpMwkdt19p9u8TozLdL1x4+hXjmyyYGDK1oh JePp3dNMtHd7uA+F/Lim2gg9AUJ5woTibXI15bQEeKbFkPvhgNGJqN9hdV751il3UwOP jHmQ== X-Gm-Message-State: APjAAAUGxNLDSrjVu+ZjFhutqQw+By7wPlyMSXQXzWBYiuf8/7C8JCZB ZgInvhd9IRKh0X6TbFTuQp038tE1 X-Google-Smtp-Source: APXvYqyJ1ml4IDZJpwfBDSLufX/tbQ66YFWf9xqG3u9YU4WRcCf3i9C3Cv3Gt5uCxHSNRuvEXp9wmg== X-Received: by 2002:a5d:474d:: with SMTP id o13mr15626936wrs.278.1553515725200; Mon, 25 Mar 2019 05:08:45 -0700 (PDT) Received: from vm.nix.is ([2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n188sm15339464wme.13.2019.03.25.05.08.44 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 25 Mar 2019 05:08:44 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , =?utf-8?q?SZEDER_G=C3=A1bor?= , Eric Sunshine , Ramsay Jones , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v3 1/8] commit-graph tests: split up corrupt_graph_and_verify() Date: Mon, 25 Mar 2019 13:08:27 +0100 Message-Id: <20190325120834.15529-2-avarab@gmail.com> X-Mailer: git-send-email 2.21.0.360.g471c308f928 In-Reply-To: <20190314214740.23360-1-avarab@gmail.com> References: <20190314214740.23360-1-avarab@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Split up the corrupt_graph_and_verify() function added in d9b9f8a6fd ("commit-graph: verify catches corrupt signature", 2018-06-27) into its logical components of setting up the test itself, doing the corruption in a particular way with "dd", and then finally testing that stderr is what we expect. This allows for re-using everything except the now slimmer corrupt_graph_and_verify() to corrupt the graph in a way that doesn't involve inserting a given byte sequence at a given position, e.g. truncating it entirely to a custom value. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t5318-commit-graph.sh | 22 ++++++++++++++++------ 1 file changed, 16 insertions(+), 6 deletions(-) diff --git a/t/t5318-commit-graph.sh b/t/t5318-commit-graph.sh index 561796f280..56a616831e 100755 --- a/t/t5318-commit-graph.sh +++ b/t/t5318-commit-graph.sh @@ -366,6 +366,19 @@ GRAPH_OCTOPUS_DATA_OFFSET=$(($GRAPH_COMMIT_DATA_OFFSET + \ GRAPH_BYTE_OCTOPUS=$(($GRAPH_OCTOPUS_DATA_OFFSET + 4)) GRAPH_BYTE_FOOTER=$(($GRAPH_OCTOPUS_DATA_OFFSET + 4 * $NUM_OCTOPUS_EDGES)) +corrupt_graph_setup() { + cd "$TRASH_DIRECTORY/full" && + test_when_finished mv commit-graph-backup $objdir/info/commit-graph && + cp $objdir/info/commit-graph commit-graph-backup +} + +corrupt_graph_verify() { + grepstr=$1 + test_must_fail git commit-graph verify 2>test_err && + grep -v "^+" test_err >err && + test_i18ngrep "$grepstr" err +} + # usage: corrupt_graph_and_verify [] # Manipulates the commit-graph file at the position # by inserting the data, optionally zeroing the file @@ -376,17 +389,14 @@ corrupt_graph_and_verify() { pos=$1 data="${2:-\0}" grepstr=$3 - cd "$TRASH_DIRECTORY/full" && + corrupt_graph_setup && orig_size=$(wc -c < $objdir/info/commit-graph) && zero_pos=${4:-${orig_size}} && - test_when_finished mv commit-graph-backup $objdir/info/commit-graph && - cp $objdir/info/commit-graph commit-graph-backup && printf "$data" | dd of="$objdir/info/commit-graph" bs=1 seek="$pos" conv=notrunc && dd of="$objdir/info/commit-graph" bs=1 seek="$zero_pos" if=/dev/null && generate_zero_bytes $(($orig_size - $zero_pos)) >>"$objdir/info/commit-graph" && - test_must_fail git commit-graph verify 2>test_err && - grep -v "^+" test_err >err && - test_i18ngrep "$grepstr" err + corrupt_graph_verify "$grepstr" + } test_expect_success 'detect bad signature' ' From patchwork Mon Mar 25 12:08:28 2019 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: 10868971 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1E3CE1575 for ; Mon, 25 Mar 2019 12:08:52 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0B4A12915D for ; Mon, 25 Mar 2019 12:08:52 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id F3E81292D6; Mon, 25 Mar 2019 12:08:51 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A7CA82915D for ; Mon, 25 Mar 2019 12:08:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731118AbfCYMIu (ORCPT ); Mon, 25 Mar 2019 08:08:50 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:55923 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731098AbfCYMIu (ORCPT ); Mon, 25 Mar 2019 08:08:50 -0400 Received: by mail-wm1-f65.google.com with SMTP id o25so8611109wmf.5 for ; Mon, 25 Mar 2019 05:08:49 -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=PYkMdXApGE4aYrKM81d6b9cOCU0BUZFifHyy+rtD0CI=; b=iFYZUQTx2x/2zRezN1j0t/+K1GmWalr8ipjDb8ZLXHhfO6q7z69sB4/+lVNiiW/Cw+ Fixsu1mqa29Au62q1PiyPlEjbQy5rRU/De5lUqAi7g/b/5SRyBmoarx7odr75J+cwLAG q8cIkr8/MELa3VXCrQwspJ2lHjJ1YZp5vaNC3Gsds8EvaQ7LX4OSY94Xjei2o6INFYT7 ns4yMNAyb7SpT/26VPoMVSVpbZFew5NkVx+MjKl8RrHyLHzzDICU5V8LGlpBM2YfXDhk 9iX9tANwXep27UvNJEo8pbV9Vt7dsM+1c2NnjtfbRfCdOmjhhWpz/gTu2BiHFmiXq/vL 9Fyw== 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=PYkMdXApGE4aYrKM81d6b9cOCU0BUZFifHyy+rtD0CI=; b=EP2FufkNBPTp8Qo2UJolphUXhxxR1xGYYHZHHrEjGolzWwk8eRBB2g88VrCpTKMBeF dLQyFZzXNwrGjc01tQx2BUsPKVtSXa0R83OQKimKjDQz44SwZ5JKASO9S4d/2FjYQHY2 DGG6Gz5IzqrEPIoK735T3aIlcxoH4Th963LDkRYo/iA59HLPvCF8QnG2oTXORPllhUhC MonbhspIjoIi4XTVu0KcU0BTdBuMWL51QEy+hdW0REIltfbAUkhCv0TCc6AAhr0ug6pH IBfe+iZ5T+vba+SgyfpJcX66+0gUWRi+LiEuqxqB34vqLoBxPzgpTyRTt311S40xGWNs PAyw== X-Gm-Message-State: APjAAAUiaObEe0+x+Vwb3dJHFNPy5FsAQlzEbIFTgTyxZpkqDRQnT4Rm RhdijsfN22jopeb5Lg6ZElac6GuJ X-Google-Smtp-Source: APXvYqwSW3dOgoeVmcsMLbaGm6BZ/6Gpa7Up5Es/03dPSdkgN4MfyXWlf+ey/74ndi5RLi7qAqegdg== X-Received: by 2002:a05:600c:2309:: with SMTP id 9mr11709008wmo.52.1553515728090; Mon, 25 Mar 2019 05:08:48 -0700 (PDT) Received: from vm.nix.is ([2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n188sm15339464wme.13.2019.03.25.05.08.47 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 25 Mar 2019 05:08:47 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , =?utf-8?q?SZEDER_G=C3=A1bor?= , Eric Sunshine , Ramsay Jones , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v3 2/8] commit-graph tests: test a graph that's too small Date: Mon, 25 Mar 2019 13:08:28 +0100 Message-Id: <20190325120834.15529-3-avarab@gmail.com> X-Mailer: git-send-email 2.21.0.360.g471c308f928 In-Reply-To: <20190314214740.23360-1-avarab@gmail.com> References: <20190314214740.23360-1-avarab@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Use the recently split-up components of the corrupt_graph_and_verify() function to assert that we error on graphs that are too small. The error was added in 2a2e32bdc5 ("commit-graph: implement git commit-graph read", 2018-04-10), but there was no test for it. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t5318-commit-graph.sh | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/t/t5318-commit-graph.sh b/t/t5318-commit-graph.sh index 56a616831e..ce3459a6f5 100755 --- a/t/t5318-commit-graph.sh +++ b/t/t5318-commit-graph.sh @@ -399,6 +399,12 @@ corrupt_graph_and_verify() { } +test_expect_success 'detect too small' ' + corrupt_graph_setup && + echo "a small graph" >$objdir/info/commit-graph && + corrupt_graph_verify "too small" +' + test_expect_success 'detect bad signature' ' corrupt_graph_and_verify 0 "\0" \ "graph signature" From patchwork Mon Mar 25 12:08:29 2019 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: 10868973 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id A9A131575 for ; Mon, 25 Mar 2019 12:08:54 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9571129175 for ; Mon, 25 Mar 2019 12:08:54 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 89D2F29329; Mon, 25 Mar 2019 12:08:54 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 0B5FE29175 for ; Mon, 25 Mar 2019 12:08:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731130AbfCYMIw (ORCPT ); Mon, 25 Mar 2019 08:08:52 -0400 Received: from mail-wm1-f65.google.com ([209.85.128.65]:55924 "EHLO mail-wm1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731071AbfCYMIv (ORCPT ); Mon, 25 Mar 2019 08:08:51 -0400 Received: by mail-wm1-f65.google.com with SMTP id o25so8611152wmf.5 for ; Mon, 25 Mar 2019 05:08:50 -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=PZdn2OfGSJf10mW5ZEiCMQsMAV45Sp0Jf/ljJmQRzdc=; b=TucLxcWWzxKLMiKbar4etl9MJ8IEphbmjLhfFPEZCnH8UVi/cs+DKHD8jCgI8idhsQ qBTgLdpMM6P7ZfPFZ8xw1RLq07WQQMamq5hq+uFcgntdzI3Sjs/69C8imR9Mb0bEpcfM Vdl/sVLHf2cBqbyCFiryurrr0ZhXh1M/GNS7T13vp8eOgzJfegqDFCGEdiDZ/C2giZ+C nTD/Sitx99vWF42F5LxpJ32e96gSM8O1Zd2+2f4JKLbPW2EdQ3TczvGmS6nFb+yVr9IG duFUQ1yg4twIkURYC+R2PSOzQgXSvb+pGgc6C/3lDZFLTLV+jBOxgramBEBuvqCsLPG5 W8JQ== 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=PZdn2OfGSJf10mW5ZEiCMQsMAV45Sp0Jf/ljJmQRzdc=; b=ozLXMAKLadYACvmYgqGGp8ItH+IDQvZLP13njXjABjSqhwyE8TyLCAvvIEK58BMR89 MXW5jurutP2ZlKMvMdhqiRgK5iRW52ZEiQNiKrgK+xz+XWdTinQ81qBpMA/Ooquh61pc Q3okJg759bK0led5ZgDXts+CF9z44GZLTclE3dkxblV8JYkVKLNYJV2xUvc/CSG5cfKr Xcz7FtzvUuXAXWAXVKR6aed4nPbauVrEHnZgzMKxHaMnqQ/FOrGxbUaWIwaUcV5uK3tI 25STLFOHAiZynd6NZgoSyJiHOOOv9K1sodccbNlYJGltIa39umR6mu8/xzH+9iktc6YY 2L9g== X-Gm-Message-State: APjAAAVHubgl7GB+0c5qryfAt7dSiMQoMVMh8m4m4UtA+S1+Cn6IBcvP +rmyDbgVirEHz+WyD3MpKVjguXEB X-Google-Smtp-Source: APXvYqzi6GDDbGIR2i5rZAZMJSKBbcriMjzykmzjGjiIcotqLTQrM/pwH9GVCxVurYXoLkwvYBsSmw== X-Received: by 2002:a1c:988d:: with SMTP id a135mr5243606wme.24.1553515729065; Mon, 25 Mar 2019 05:08:49 -0700 (PDT) Received: from vm.nix.is ([2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n188sm15339464wme.13.2019.03.25.05.08.48 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 25 Mar 2019 05:08:48 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , =?utf-8?q?SZEDER_G=C3=A1bor?= , Eric Sunshine , Ramsay Jones , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v3 3/8] commit-graph: fix segfault on e.g. "git status" Date: Mon, 25 Mar 2019 13:08:29 +0100 Message-Id: <20190325120834.15529-4-avarab@gmail.com> X-Mailer: git-send-email 2.21.0.360.g471c308f928 In-Reply-To: <20190314214740.23360-1-avarab@gmail.com> References: <20190314214740.23360-1-avarab@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When core.commitGraph=true is set, various common commands now consult the commit graph. Because the commit-graph code is very trusting of its input data, it's possibly to construct a graph that'll cause an immediate segfault on e.g. "status" (and e.g. "log", "blame", ...). In some other cases where git immediately exits with a cryptic error about the graph being broken. The root cause of this is that while the "commit-graph verify" sub-command exhaustively verifies the graph, other users of the graph simply trust the graph, and will e.g. deference data found at certain offsets as pointers, causing segfaults. This change does the bare minimum to ensure that we don't segfault in the common fill_commit_in_graph() codepath called by e.g. setup_revisions(), to do this instrument the "commit-graph verify" tests to always check if "status" would subsequently segfault. This fixes the following tests which would previously segfault: not ok 50 - detect low chunk count not ok 51 - detect missing OID fanout chunk not ok 52 - detect missing OID lookup chunk not ok 53 - detect missing commit data chunk Those happened because with the commit-graph enabled setup_revisions() would eventually call fill_commit_in_graph(), where e.g. g->chunk_commit_data is used early as an offset (and will be 0x0). With this change we get far enough to detect that the graph is broken, and show an error instead. E.g.: $ git status; echo $? error: commit-graph is missing the Commit Data chunk 1 That also sucks, we should *warn* and not hard-fail "status" just because the commit-graph is corrupt, but fixing is left to a follow-up change. A side-effect of changing the reporting from graph_report() to error() is that we now have an "error: " prefix for these even for "commit-graph verify". Pseudo-diff before/after: $ git commit-graph verify -commit-graph is missing the Commit Data chunk +error: commit-graph is missing the Commit Data chunk Changing that is OK. Various errors it emits now early on are prefixed with "error: ", moving these over and changing the output doesn't break anything. Signed-off-by: Ævar Arnfjörð Bjarmason --- commit-graph.c | 43 ++++++++++++++++++++++++++++++++--------- t/t5318-commit-graph.sh | 3 ++- 2 files changed, 36 insertions(+), 10 deletions(-) diff --git a/commit-graph.c b/commit-graph.c index 47e9be0a3a..f8201d888b 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -112,6 +112,36 @@ struct commit_graph *load_commit_graph_one(const char *graph_file) return ret; } +static int verify_commit_graph_lite(struct commit_graph *g) +{ + /* + * Basic validation shared between parse_commit_graph() + * which'll be called every time the graph is used, and the + * much more expensive verify_commit_graph() used by + * "commit-graph verify". + * + * There should only be very basic checks here to ensure that + * we don't e.g. segfault in fill_commit_in_graph(), but + * because this is a very hot codepath nothing that e.g. loops + * over g->num_commits, or runs a checksum on the commit-graph + * itself. + */ + if (!g->chunk_oid_fanout) { + error("commit-graph is missing the OID Fanout chunk"); + return 1; + } + if (!g->chunk_oid_lookup) { + error("commit-graph is missing the OID Lookup chunk"); + return 1; + } + if (!g->chunk_commit_data) { + error("commit-graph is missing the Commit Data chunk"); + return 1; + } + + return 0; +} + struct commit_graph *parse_commit_graph(void *graph_map, int fd, size_t graph_size) { @@ -233,6 +263,9 @@ struct commit_graph *parse_commit_graph(void *graph_map, int fd, last_chunk_offset = chunk_offset; } + if (verify_commit_graph_lite(graph)) + return NULL; + return graph; } @@ -1089,15 +1122,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g) return 1; } - verify_commit_graph_error = 0; - - if (!g->chunk_oid_fanout) - graph_report("commit-graph is missing the OID Fanout chunk"); - if (!g->chunk_oid_lookup) - graph_report("commit-graph is missing the OID Lookup chunk"); - if (!g->chunk_commit_data) - graph_report("commit-graph is missing the Commit Data chunk"); - + verify_commit_graph_error = verify_commit_graph_lite(g); if (verify_commit_graph_error) return verify_commit_graph_error; diff --git a/t/t5318-commit-graph.sh b/t/t5318-commit-graph.sh index ce3459a6f5..ad3a695f76 100755 --- a/t/t5318-commit-graph.sh +++ b/t/t5318-commit-graph.sh @@ -376,7 +376,8 @@ corrupt_graph_verify() { grepstr=$1 test_must_fail git commit-graph verify 2>test_err && grep -v "^+" test_err >err && - test_i18ngrep "$grepstr" err + test_i18ngrep "$grepstr" err && + test_might_fail git status --short } # usage: corrupt_graph_and_verify [] From patchwork Mon Mar 25 12:08:30 2019 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: 10868975 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id ADB4D139A for ; Mon, 25 Mar 2019 12:08:55 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 9A14429175 for ; Mon, 25 Mar 2019 12:08:55 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 8457C29333; Mon, 25 Mar 2019 12:08:55 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D5F9A29175 for ; Mon, 25 Mar 2019 12:08:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731086AbfCYMIx (ORCPT ); Mon, 25 Mar 2019 08:08:53 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:40053 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731121AbfCYMIx (ORCPT ); Mon, 25 Mar 2019 08:08:53 -0400 Received: by mail-wr1-f66.google.com with SMTP id t5so9788995wri.7 for ; Mon, 25 Mar 2019 05:08:51 -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=O/ql19PsfWKCt2xWIuc628GJETf/dP/bTSODTNC2EdU=; b=MEgSrxV71VFdA+kAJEtFRnkFQS3TRqs8/8fVnW+ZlwkNIfu1DdMmy8WcDv4AyfH+JA AwYaNxoOijLQvPS5qCCZ82E9bQFWGbaW0MBQqfsyl9yNYtserbtU7v1a5zrraawkKC4y n+qiG8uo2+B4i/Kvnc7WjKfqRxcMADsYvpravUK1CdiSzA+zAjabjgJ3iyfDjHj3hrGs ExAmvjDg7EpAjRZBBCN8TyKNbE3auJx6IB2rIvinyGvHFr6Dq9x57XwHiDGXAUNylgDa e/sIp+FvTyQ9aVbskhIyl8YYS1IufqUev+Qb4QNh0gJwWKkCwzKsBMIDkcLRDPL6ETe1 o+hw== 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=O/ql19PsfWKCt2xWIuc628GJETf/dP/bTSODTNC2EdU=; b=nWbc3kA7ABkOURtNklMu7NneGvVw1SbvjlPYjgvgYTNpNxPewXqWGWwp2QYb6XMyGm yoHrAYy29xJlrhEgvZxiqsYRx/LjmGvBf6wRsUe3zbHyNylwCxlsGzqUED/rp1zIsFfi T3ytkctlUN8ERvu9BEb+LvQ0eoLX27afanlInfWxGcfPoy5xLwka5j1n53Beaa3yDsyn srw3CyhZ0mHVsQNs/MrlXC/KwwQhMNqkr2Bdbj81hI/rHF0KRWXsguOmaJRE3SnMNhdn BRbuGodQfU4LGsLFvALckvT0T8ERI27lgoAmHurh6c7EmLgBGMUw1h4oYUfZ1BRIts/f SxHQ== X-Gm-Message-State: APjAAAXgezstJ1iDKK+1bMXpNklqQadNNpX6yo+vCPrNpkh7ohK6HZ4d /IfwPbvHVWQVplt2SYSJgZ77Mz39 X-Google-Smtp-Source: APXvYqxMAP66bzq29axdHB2lt1jwTYrzvheVpnBfordcYFWFkzmXnHtihs9sMDMdQXPfO72NDFYVpA== X-Received: by 2002:a5d:6682:: with SMTP id l2mr14868630wru.33.1553515730295; Mon, 25 Mar 2019 05:08:50 -0700 (PDT) Received: from vm.nix.is ([2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n188sm15339464wme.13.2019.03.25.05.08.49 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 25 Mar 2019 05:08:49 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , =?utf-8?q?SZEDER_G=C3=A1bor?= , Eric Sunshine , Ramsay Jones , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v3 4/8] commit-graph: don't early exit(1) on e.g. "git status" Date: Mon, 25 Mar 2019 13:08:30 +0100 Message-Id: <20190325120834.15529-5-avarab@gmail.com> X-Mailer: git-send-email 2.21.0.360.g471c308f928 In-Reply-To: <20190314214740.23360-1-avarab@gmail.com> References: <20190314214740.23360-1-avarab@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Make the commit-graph loading code work as a library that returns an error code instead of calling exit(1) when the commit-graph is corrupt. This means that e.g. "status" will now report commit-graph corruption as an "error: [...]" at the top of its output, but then proceed to work normally. This required splitting up the load_commit_graph_one() function so that the code that deals with open()-ing and stat()-ing the graph can now be called independently as open_commit_graph(). This is needed because "commit-graph verify" where the graph doesn't exist isn't an error. See the third paragraph in 283e68c72f ("commit-graph: add 'verify' subcommand", 2018-06-27). There's a bug in that logic where we conflate the intended ENOENT with other errno values (e.g. EACCES), but this change doesn't address that. That'll be addressed in a follow-up change. I'm then splitting most of the logic out of load_commit_graph_one() into load_commit_graph_one_fd_st(), which allows for providing an existing file descriptor and stat information to the loading code. This isn't strictly needed, but it would be redundant and confusing to open() and stat() the file twice for some of the codepaths, this allows for calling open_commit_graph() followed by load_commit_graph_one_fd_st(). The "graph_file" still needs to be passed to that function for the the "graph file %s is too small" error message. This leaves load_commit_graph_one() unused by everything except the internal prepare_commit_graph_one() function, so let's mark it as "static". If someone needs it in the future we can remove the "static" attribute. I could also rewrite its sole remaining user ("prepare_commit_graph_one()") to use load_commit_graph_one_fd_st() instead, but let's leave it at this. Signed-off-by: Ævar Arnfjörð Bjarmason Signed-off-by: Ramsay Jones --- builtin/commit-graph.c | 21 +++++++++++++++++---- commit-graph.c | 42 +++++++++++++++++++++++++++++------------ commit-graph.h | 4 +++- t/t5318-commit-graph.sh | 2 +- 4 files changed, 51 insertions(+), 18 deletions(-) diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c index 4ae502754c..32bcc63427 100644 --- a/builtin/commit-graph.c +++ b/builtin/commit-graph.c @@ -42,6 +42,9 @@ static int graph_verify(int argc, const char **argv) { struct commit_graph *graph = NULL; char *graph_name; + int open_ok; + int fd; + struct stat st; static struct option builtin_commit_graph_verify_options[] = { OPT_STRING(0, "object-dir", &opts.obj_dir, @@ -58,11 +61,14 @@ static int graph_verify(int argc, const char **argv) opts.obj_dir = get_object_directory(); graph_name = get_commit_graph_filename(opts.obj_dir); - graph = load_commit_graph_one(graph_name); + open_ok = open_commit_graph(graph_name, &fd, &st); + if (!open_ok) + return 0; + graph = load_commit_graph_one_fd_st(graph_name, fd, &st); FREE_AND_NULL(graph_name); if (!graph) - return 0; + return 1; UNLEAK(graph); return verify_commit_graph(the_repository, graph); @@ -72,6 +78,9 @@ static int graph_read(int argc, const char **argv) { struct commit_graph *graph = NULL; char *graph_name; + int open_ok; + int fd; + struct stat st; static struct option builtin_commit_graph_read_options[] = { OPT_STRING(0, "object-dir", &opts.obj_dir, @@ -88,10 +97,14 @@ static int graph_read(int argc, const char **argv) opts.obj_dir = get_object_directory(); graph_name = get_commit_graph_filename(opts.obj_dir); - graph = load_commit_graph_one(graph_name); + open_ok = open_commit_graph(graph_name, &fd, &st); + if (!open_ok) + die_errno(_("Could not open commit-graph '%s'"), graph_name); + + graph = load_commit_graph_one_fd_st(graph_name, fd, &st); if (!graph) - die("graph file %s does not exist", graph_name); + return 1; FREE_AND_NULL(graph_name); diff --git a/commit-graph.c b/commit-graph.c index f8201d888b..3acc032c1b 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -80,25 +80,31 @@ static int commit_graph_compatible(struct repository *r) return 1; } -struct commit_graph *load_commit_graph_one(const char *graph_file) +int open_commit_graph(const char *graph_file, int *fd, struct stat *st) +{ + *fd = git_open(graph_file); + if (*fd < 0) + return 0; + if (fstat(*fd, st)) { + close(*fd); + return 0; + } + return 1; +} + +struct commit_graph *load_commit_graph_one_fd_st(const char *graph_file, + int fd, struct stat *st) { void *graph_map; size_t graph_size; - struct stat st; struct commit_graph *ret; - int fd = git_open(graph_file); - if (fd < 0) - return NULL; - if (fstat(fd, &st)) { - close(fd); - return NULL; - } - graph_size = xsize_t(st.st_size); + graph_size = xsize_t(st->st_size); if (graph_size < GRAPH_MIN_SIZE) { close(fd); - die(_("graph file %s is too small"), graph_file); + error(_("graph file %s is too small"), graph_file); + return NULL; } graph_map = xmmap(NULL, graph_size, PROT_READ, MAP_PRIVATE, fd, 0); ret = parse_commit_graph(graph_map, fd, graph_size); @@ -106,7 +112,6 @@ struct commit_graph *load_commit_graph_one(const char *graph_file) if (!ret) { munmap(graph_map, graph_size); close(fd); - exit(1); } return ret; @@ -269,6 +274,19 @@ struct commit_graph *parse_commit_graph(void *graph_map, int fd, return graph; } +static struct commit_graph *load_commit_graph_one(const char *graph_file) +{ + + struct stat st; + int fd; + int open_ok = open_commit_graph(graph_file, &fd, &st); + + if (!open_ok) + return NULL; + + return load_commit_graph_one_fd_st(graph_file, fd, &st); +} + static void prepare_commit_graph_one(struct repository *r, const char *obj_dir) { char *graph_name; diff --git a/commit-graph.h b/commit-graph.h index 096d8bac34..77cc739bc0 100644 --- a/commit-graph.h +++ b/commit-graph.h @@ -11,6 +11,7 @@ struct commit; char *get_commit_graph_filename(const char *obj_dir); +int open_commit_graph(const char *graph_file, int *fd, struct stat *st); /* * Given a commit struct, try to fill the commit struct info, including: @@ -52,7 +53,8 @@ struct commit_graph { const unsigned char *chunk_extra_edges; }; -struct commit_graph *load_commit_graph_one(const char *graph_file); +struct commit_graph *load_commit_graph_one_fd_st(const char *graph_file, + int fd, struct stat *st); struct commit_graph *parse_commit_graph(void *graph_map, int fd, size_t graph_size); diff --git a/t/t5318-commit-graph.sh b/t/t5318-commit-graph.sh index ad3a695f76..71d775e313 100755 --- a/t/t5318-commit-graph.sh +++ b/t/t5318-commit-graph.sh @@ -377,7 +377,7 @@ corrupt_graph_verify() { test_must_fail git commit-graph verify 2>test_err && grep -v "^+" test_err >err && test_i18ngrep "$grepstr" err && - test_might_fail git status --short + git status --short } # usage: corrupt_graph_and_verify [] From patchwork Mon Mar 25 12:08:31 2019 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: 10868977 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 3473A139A for ; Mon, 25 Mar 2019 12:08:57 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 20BB629175 for ; Mon, 25 Mar 2019 12:08:57 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 152DB2932C; Mon, 25 Mar 2019 12:08:57 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id A606629175 for ; Mon, 25 Mar 2019 12:08:56 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731071AbfCYMIy (ORCPT ); Mon, 25 Mar 2019 08:08:54 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:32916 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731058AbfCYMIx (ORCPT ); Mon, 25 Mar 2019 08:08:53 -0400 Received: by mail-wr1-f66.google.com with SMTP id q1so9854892wrp.0 for ; Mon, 25 Mar 2019 05:08:52 -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=8KBMIoufgK0VuPFB2g3EY0LDiHONfBFoAK4Gz9Ecu2E=; b=Kj0B0UIz+u1hVqzcgZs8NuLgPVhp9TW5XlbH65pjXV2e9sOmapVL1H1SfBVwZGSZyN LJogbHHgE4ugvBr+kqKhmo13prlX8ayAwiGBdlEBaa8v245UkkJXtydpKD4hC17597VH 7DRLuTVi4CAmZCEGsC/uBkKaBjdqCeZNewoxjDBsg5vLA5iz9Zw9ILLhTLoyba2/Sc7S HXfn2tfSXXe4BxvGnk1doh2GkLfvbb6lR30DYsCXR+Krnzjwu1J0KWooISbWyBLQtoKr hcEd2jTP5InALgI19sWAhvBh8BCDRBL6ZWgkg0bovTNOn3gpqzu7WiNtGEXMwCFP4mxF VhyA== 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=8KBMIoufgK0VuPFB2g3EY0LDiHONfBFoAK4Gz9Ecu2E=; b=PzbUwWTi0UWj2QxLs1MgjwfiFRmu+Bw+mYEXiisFtWqGmee1wL1T1xH6DgCqPIJD6Z 8LSFQNH8Czg5jgHpJfmtpyYRU4C5NZUIedxfxL3AHQyjd0EHBPdF4dlitqTh2oz8N+Tf G2KMVLvb39BsGZLU477eFsC+xTAXIu0tRj9PoaiJMUQhvxynOZn5em7Ms8Ll/ZFjUKCM ppP9QRsiFKU2YY+pFZRFHTw9uw7m/dzknNgDSBQWADCyCof3y1GoV2SM0bQTY1us6kx7 alOynQBWoTMHwveG0k48jxWR6NurMDi1xeUHQBIGOgJC8uRnhd0DNFNq8QT7Rb11Z8aL S5ig== X-Gm-Message-State: APjAAAXtEbgciY7wouJdnFUlStOm+VH3P5GqT+yL7bohtBBcEO6nxSvF qMQCPRYMxJfVu/C2DW+SZFI/NaQpzkI= X-Google-Smtp-Source: APXvYqzmn6VnlJQJTKW+04FqTHoNm4bkKjjR0W0xkT4cOHrZu7GECr9w6J9azD0C2U3DIMCOlFt6Kg== X-Received: by 2002:a5d:6406:: with SMTP id z6mr14486141wru.266.1553515731693; Mon, 25 Mar 2019 05:08:51 -0700 (PDT) Received: from vm.nix.is ([2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n188sm15339464wme.13.2019.03.25.05.08.50 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 25 Mar 2019 05:08:50 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , =?utf-8?q?SZEDER_G=C3=A1bor?= , Eric Sunshine , Ramsay Jones , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v3 5/8] commit-graph: don't pass filename to load_commit_graph_one_fd_st() Date: Mon, 25 Mar 2019 13:08:31 +0100 Message-Id: <20190325120834.15529-6-avarab@gmail.com> X-Mailer: git-send-email 2.21.0.360.g471c308f928 In-Reply-To: <20190314214740.23360-1-avarab@gmail.com> References: <20190314214740.23360-1-avarab@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP An earlier change implemented load_commit_graph_one_fd_st() in a way that was bug-compatible with earlier code in terms of the "graph file %s is too small" error message printing out the path to the commit-graph (".git/objects/info/commit-graph"). But change that, because: * A function that takes an already-open file descriptor also needing the filename isn't very intuitive. * The vast majority of errors we might emit when loading the graph come from parse_commit_graph(), which doesn't report the filename. Let's not do that either in this case for consistency. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/commit-graph.c | 4 ++-- commit-graph.c | 7 +++---- commit-graph.h | 3 +-- 3 files changed, 6 insertions(+), 8 deletions(-) diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c index 32bcc63427..8196fdbe9c 100644 --- a/builtin/commit-graph.c +++ b/builtin/commit-graph.c @@ -64,7 +64,7 @@ static int graph_verify(int argc, const char **argv) open_ok = open_commit_graph(graph_name, &fd, &st); if (!open_ok) return 0; - graph = load_commit_graph_one_fd_st(graph_name, fd, &st); + graph = load_commit_graph_one_fd_st(fd, &st); FREE_AND_NULL(graph_name); if (!graph) @@ -102,7 +102,7 @@ static int graph_read(int argc, const char **argv) if (!open_ok) die_errno(_("Could not open commit-graph '%s'"), graph_name); - graph = load_commit_graph_one_fd_st(graph_name, fd, &st); + graph = load_commit_graph_one_fd_st(fd, &st); if (!graph) return 1; diff --git a/commit-graph.c b/commit-graph.c index 3acc032c1b..a26d266663 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -92,8 +92,7 @@ int open_commit_graph(const char *graph_file, int *fd, struct stat *st) return 1; } -struct commit_graph *load_commit_graph_one_fd_st(const char *graph_file, - int fd, struct stat *st) +struct commit_graph *load_commit_graph_one_fd_st(int fd, struct stat *st) { void *graph_map; size_t graph_size; @@ -103,7 +102,7 @@ struct commit_graph *load_commit_graph_one_fd_st(const char *graph_file, if (graph_size < GRAPH_MIN_SIZE) { close(fd); - error(_("graph file %s is too small"), graph_file); + error(_("commit-graph file is too small")); return NULL; } graph_map = xmmap(NULL, graph_size, PROT_READ, MAP_PRIVATE, fd, 0); @@ -284,7 +283,7 @@ static struct commit_graph *load_commit_graph_one(const char *graph_file) if (!open_ok) return NULL; - return load_commit_graph_one_fd_st(graph_file, fd, &st); + return load_commit_graph_one_fd_st(fd, &st); } static void prepare_commit_graph_one(struct repository *r, const char *obj_dir) diff --git a/commit-graph.h b/commit-graph.h index 77cc739bc0..ada7aea9ed 100644 --- a/commit-graph.h +++ b/commit-graph.h @@ -53,8 +53,7 @@ struct commit_graph { const unsigned char *chunk_extra_edges; }; -struct commit_graph *load_commit_graph_one_fd_st(const char *graph_file, - int fd, struct stat *st); +struct commit_graph *load_commit_graph_one_fd_st(int fd, struct stat *st); struct commit_graph *parse_commit_graph(void *graph_map, int fd, size_t graph_size); From patchwork Mon Mar 25 12:08:32 2019 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: 10868983 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 92811139A for ; Mon, 25 Mar 2019 12:09:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7EFC42915D for ; Mon, 25 Mar 2019 12:09:01 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 7351B292D6; Mon, 25 Mar 2019 12:09:01 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 1CAA72915D for ; Mon, 25 Mar 2019 12:09:01 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731140AbfCYMI5 (ORCPT ); Mon, 25 Mar 2019 08:08:57 -0400 Received: from mail-wm1-f66.google.com ([209.85.128.66]:53357 "EHLO mail-wm1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731121AbfCYMIz (ORCPT ); Mon, 25 Mar 2019 08:08:55 -0400 Received: by mail-wm1-f66.google.com with SMTP id q16so8625773wmj.3 for ; Mon, 25 Mar 2019 05:08:53 -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=az/n15HTlzAVklvmNwJJSBsLR/HQZUHIqjvJa6Id0Y4=; b=T9MyKmGSt/LHsYRlf1nz5N/P5C5Bn7GdlJCq8IeDWd98ofGxZ2DFz+0hTheu2iA1dU U3Vy4cqQwCykJ3I0KZr6uIxp3zUNxRYGe8AyfGV+OBd7lt+clVHYix3TyLkW5WKmJrqZ JkOyonn/Bw+uZIc0qB6+JnKFPD3cjIakFTBjgb+ojorp20BZWqsYTTjExVgd4vNQuDz8 1+C6w3oFPaEuXe66xJrHRTHVIegI0/zTkiIhLQdyZeEzYxmMoShHef9UmvjNx6aRiwa/ DokO6yUMK9a0gIbLnyJ9cJhAQcJB2P4OmhxzzVQP+Uu0IOcma6zsbto3wUVGmROIGzg5 Ylsg== 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=az/n15HTlzAVklvmNwJJSBsLR/HQZUHIqjvJa6Id0Y4=; b=sUTTSHa99FMHgYcd1x2NsK675sBhj2Cp98v3rBoUqOhiJk65NgTDlGEFP2btNzC3lE y8IDCAZe2IQT62rjiSgpzbI4Ia+R/RtLfBWe/WVOexwlrR33OsfPKMpZ1D4ASuYzltbA 23XGGdqd5TNTf8IsfBLxXb5ehNaXqf+oN5pOzqvMgSUpNoq4KhWbPsXyJCyWBFwBd3m3 m+Tv2YN5N/mj3amaNBO0o67GbvMDNzTi4oG8a3/FZhl7ENF9LzfdptIb4kyyNvOBiwXM Wg8bD5ta1zgJ5BcA3swDu2YtuClHM7/gV5mNcIbM0KqF50jvYrfNh76yX2VeUcwHG2RH lECA== X-Gm-Message-State: APjAAAXCpPY2QUG+PYKQ4IE77M1iPK1H6rUNLFHSAW/XVt14QFBxEw1F hmWcjkUnAgBHxnDhsMSCxCySMsA0FF0= X-Google-Smtp-Source: APXvYqzxr5Vfd/2n/VbLqltIjE6LXT3nMBZpwTWqF8lhD3iCUGcQZ+3iuRBmaaFp1Wk4b7glbu1isw== X-Received: by 2002:a1c:7311:: with SMTP id d17mr1487895wmb.115.1553515732934; Mon, 25 Mar 2019 05:08:52 -0700 (PDT) Received: from vm.nix.is ([2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n188sm15339464wme.13.2019.03.25.05.08.51 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 25 Mar 2019 05:08:51 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , =?utf-8?q?SZEDER_G=C3=A1bor?= , Eric Sunshine , Ramsay Jones , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v3 6/8] commit-graph verify: detect inability to read the graph Date: Mon, 25 Mar 2019 13:08:32 +0100 Message-Id: <20190325120834.15529-7-avarab@gmail.com> X-Mailer: git-send-email 2.21.0.360.g471c308f928 In-Reply-To: <20190314214740.23360-1-avarab@gmail.com> References: <20190314214740.23360-1-avarab@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Change "commit-graph verify" to error on open() failures other than ENOENT. As noted in the third paragraph of 283e68c72f ("commit-graph: add 'verify' subcommand", 2018-06-27) and the test it added it's intentional that "commit-graph verify" doesn't error out when the file doesn't exist. But let's not be overly promiscuous in what we accept. If we can't read the file for other reasons, e.g. permission errors, bad file descriptor etc. we'd like to report an error to the user. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/commit-graph.c | 4 +++- t/t5318-commit-graph.sh | 6 ++++++ 2 files changed, 9 insertions(+), 1 deletion(-) diff --git a/builtin/commit-graph.c b/builtin/commit-graph.c index 8196fdbe9c..537fdfd0f0 100644 --- a/builtin/commit-graph.c +++ b/builtin/commit-graph.c @@ -62,8 +62,10 @@ static int graph_verify(int argc, const char **argv) graph_name = get_commit_graph_filename(opts.obj_dir); open_ok = open_commit_graph(graph_name, &fd, &st); - if (!open_ok) + if (!open_ok && errno == ENOENT) return 0; + if (!open_ok) + die_errno(_("Could not open commit-graph '%s'"), graph_name); graph = load_commit_graph_one_fd_st(fd, &st); FREE_AND_NULL(graph_name); diff --git a/t/t5318-commit-graph.sh b/t/t5318-commit-graph.sh index 71d775e313..1cb0355c7e 100755 --- a/t/t5318-commit-graph.sh +++ b/t/t5318-commit-graph.sh @@ -400,6 +400,12 @@ corrupt_graph_and_verify() { } +test_expect_success POSIXPERM,SANITY 'detect permission problem' ' + corrupt_graph_setup && + chmod 000 $objdir/info/commit-graph && + corrupt_graph_verify "Could not open" +' + test_expect_success 'detect too small' ' corrupt_graph_setup && echo "a small graph" >$objdir/info/commit-graph && From patchwork Mon Mar 25 12:08:33 2019 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: 10868981 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 046A61575 for ; Mon, 25 Mar 2019 12:09:01 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id E40AB2915D for ; Mon, 25 Mar 2019 12:09:00 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id D7E10292D6; Mon, 25 Mar 2019 12:09:00 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id D10012915D for ; Mon, 25 Mar 2019 12:08:59 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731009AbfCYMI5 (ORCPT ); Mon, 25 Mar 2019 08:08:57 -0400 Received: from mail-wr1-f48.google.com ([209.85.221.48]:40694 "EHLO mail-wr1-f48.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731138AbfCYMI4 (ORCPT ); Mon, 25 Mar 2019 08:08:56 -0400 Received: by mail-wr1-f48.google.com with SMTP id t5so9789194wri.7 for ; Mon, 25 Mar 2019 05:08:55 -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=1TOmfnxLYLrMWfiJ9ILhdwq1eLAphKC0g7BwWDC4V58=; b=Hv0vMAM5zeMtEx5dwgaXtm5xjrmSiAQkNpWLgPy943/0X039AI42GdqZQqEnsXc99v Dfc37ONVmrfxjgUYcwqffJdv8qnd+XtRzvQWWETDk2Iz8zmfFhsn02QPKmg9mFhyvrfa dm+jWrbwgTU8JvRV0unmDbTabzdfWSoih9e+3mzyZRUUcnkFF+Whxl2UkGNRAwIfV1Zz J/j10fgfVn6GXY49ks1Oq5h/M21syxhNA51dsKOq2j0iQ01bnbv+7/SQaNEqMH0Zuk3m ygDqifzqAbxW/ktSwLZ7QdspnXERL9XA6kfuLH09BuKLBT29+hbLcwRVYCQGFvrllEVC CIoA== 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=1TOmfnxLYLrMWfiJ9ILhdwq1eLAphKC0g7BwWDC4V58=; b=WJpJzAl2fcXK0KoJAVmveVlvQTXDTJDO5YPRz1xYpX9afs2ozIRFZQYIHJWR6PxHxt i+HyCwbT2XvJ4OcOLu/zXykI4IRR3SvYOnw1q2p9UIJpKRvyLnmFy807QCnLDgvnaAvl eVMpxtPL0h5wQBzYGjefruDZFHzkSUwAw3eSvkza/G0bowrNW1FzzDvWXaJESqaNPm4b p2Uhpzo6s4A+uTRfiDMNGJgbcc2YNSS2uxWS+ZR72PcxHrd86ga0aZUxRMDMqaXdlnOj L4VhS5fA1UILH5m9oJKHR3ir3dwwrH99Cn801e5X6hEuOnE1ZRpORxeFiBHoTFzWQ97i 3s8A== X-Gm-Message-State: APjAAAW4M/E+7bXjR6xqTlNpOYmfG/AjyL40AlD2dMkhs9Z+YuLE+JYU CbEbILOOeZLXlbJpGovQGDk2FqKMZMk= X-Google-Smtp-Source: APXvYqyogzfvbARA+Dpme85bP9I82QkoCliA4o2qC623h6/SwbQa8H7XmhEYvSbcrR+H0fg0hMcXuA== X-Received: by 2002:a5d:4d42:: with SMTP id a2mr16588515wru.130.1553515733971; Mon, 25 Mar 2019 05:08:53 -0700 (PDT) Received: from vm.nix.is ([2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n188sm15339464wme.13.2019.03.25.05.08.52 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 25 Mar 2019 05:08:53 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , =?utf-8?q?SZEDER_G=C3=A1bor?= , Eric Sunshine , Ramsay Jones , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v3 7/8] commit-graph write: don't die if the existing graph is corrupt Date: Mon, 25 Mar 2019 13:08:33 +0100 Message-Id: <20190325120834.15529-8-avarab@gmail.com> X-Mailer: git-send-email 2.21.0.360.g471c308f928 In-Reply-To: <20190314214740.23360-1-avarab@gmail.com> References: <20190314214740.23360-1-avarab@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP When the commit-graph is written we end up calling parse_commit(). This will in turn invoke code that'll consult the existing commit-graph about the commit, if the graph is corrupted we die. We thus get into a state where a failing "commit-graph verify" can't be followed-up with a "commit-graph write" if core.commitGraph=true is set, the graph either needs to be manually removed to proceed, or core.commitGraph needs to be set to "false". Change the "commit-graph write" codepath to use a new parse_commit_no_graph() helper instead of parse_commit() to avoid this. The latter will call repo_parse_commit_internal() with use_commit_graph=1 as seen in 177722b344 ("commit: integrate commit graph with commit parsing", 2018-04-10). Not using the old graph at all slows down the writing of the new graph by some small amount, but is a sensible way to prevent an error in the existing commit-graph from spreading. Just fixing the current issue would be likely to result in code that's inadvertently broken in the future. New code might use the commit-graph at a distance. To detect such cases introduce a "GIT_TEST_COMMIT_GRAPH_DIE_ON_LOAD" setting used when we do our corruption tests, and test that a "write/verify" combo works after every one of our current test cases where we now detect commit-graph corruption. Some of the code changes here might be strictly unnecessary, e.g. I was unable to find cases where the parse_commit() called from write_graph_chunk_data() didn't exit early due to "item->object.parsed" being true in repo_parse_commit_internal() (before the use_commit_graph=1 has any effect). But let's also convert those cases for good measure, we do not have exhaustive tests for all possible types of commit-graph corruption. This might need to be re-visited if we learn to write the commit-graph incrementally, but probably not. Hopefully we'll just start by finding out what commits we have in total, then read the old graph(s) to see what they cover, and finally write a new graph file with everything that's missing. In that case the new graph writing code just needs to continue to use e.g. a parse_commit() that doesn't consult the existing commit-graphs. Signed-off-by: Ævar Arnfjörð Bjarmason --- commit-graph.c | 10 +++++++--- commit-graph.h | 1 + commit.h | 6 ++++++ t/t5318-commit-graph.sh | 11 +++++++++-- 4 files changed, 23 insertions(+), 5 deletions(-) diff --git a/commit-graph.c b/commit-graph.c index a26d266663..34ecaaf857 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -311,6 +311,10 @@ static int prepare_commit_graph(struct repository *r) struct object_directory *odb; int config_value; + if (git_env_bool(GIT_TEST_COMMIT_GRAPH_DIE_ON_LOAD, 0)) + die("dying as requested by the '%s' variable on commit-graph load!", + GIT_TEST_COMMIT_GRAPH_DIE_ON_LOAD); + if (r->objects->commit_graph_attempted) return !!r->objects->commit_graph; r->objects->commit_graph_attempted = 1; @@ -575,7 +579,7 @@ static void write_graph_chunk_data(struct hashfile *f, int hash_len, uint32_t packedDate[2]; display_progress(progress, ++*progress_cnt); - parse_commit(*list); + parse_commit_no_graph(*list); hashwrite(f, get_commit_tree_oid(*list)->hash, hash_len); parent = (*list)->parents; @@ -772,7 +776,7 @@ static void close_reachable(struct packed_oid_list *oids, int report_progress) display_progress(progress, i + 1); commit = lookup_commit(the_repository, &oids->list[i]); - if (commit && !parse_commit(commit)) + if (commit && !parse_commit_no_graph(commit)) add_missing_parents(oids, commit); } stop_progress(&progress); @@ -1021,7 +1025,7 @@ void write_commit_graph(const char *obj_dir, continue; commits.list[commits.nr] = lookup_commit(the_repository, &oids.list[i]); - parse_commit(commits.list[commits.nr]); + parse_commit_no_graph(commits.list[commits.nr]); for (parent = commits.list[commits.nr]->parents; parent; parent = parent->next) diff --git a/commit-graph.h b/commit-graph.h index ada7aea9ed..7dfb8c896f 100644 --- a/commit-graph.h +++ b/commit-graph.h @@ -7,6 +7,7 @@ #include "cache.h" #define GIT_TEST_COMMIT_GRAPH "GIT_TEST_COMMIT_GRAPH" +#define GIT_TEST_COMMIT_GRAPH_DIE_ON_LOAD "GIT_TEST_COMMIT_GRAPH_DIE_ON_LOAD" struct commit; diff --git a/commit.h b/commit.h index 42728c2906..5d33477e78 100644 --- a/commit.h +++ b/commit.h @@ -89,6 +89,12 @@ static inline int repo_parse_commit(struct repository *r, struct commit *item) { return repo_parse_commit_gently(r, item, 0); } + +static inline int parse_commit_no_graph(struct commit *commit) +{ + return repo_parse_commit_internal(the_repository, commit, 0, 0); +} + #ifndef NO_THE_REPOSITORY_COMPATIBILITY_MACROS #define parse_commit_internal(item, quiet, use) repo_parse_commit_internal(the_repository, item, quiet, use) #define parse_commit_gently(item, quiet) repo_parse_commit_gently(the_repository, item, quiet) diff --git a/t/t5318-commit-graph.sh b/t/t5318-commit-graph.sh index 1cb0355c7e..d146cf4982 100755 --- a/t/t5318-commit-graph.sh +++ b/t/t5318-commit-graph.sh @@ -377,7 +377,13 @@ corrupt_graph_verify() { test_must_fail git commit-graph verify 2>test_err && grep -v "^+" test_err >err && test_i18ngrep "$grepstr" err && - git status --short + if test "$2" != "no-copy" + then + cp $objdir/info/commit-graph commit-graph-pre-write-test + fi && + git status --short && + GIT_TEST_COMMIT_GRAPH_DIE_ON_LOAD=true git commit-graph write && + git commit-graph verify } # usage: corrupt_graph_and_verify [] @@ -403,7 +409,7 @@ corrupt_graph_and_verify() { test_expect_success POSIXPERM,SANITY 'detect permission problem' ' corrupt_graph_setup && chmod 000 $objdir/info/commit-graph && - corrupt_graph_verify "Could not open" + corrupt_graph_verify "Could not open" "no-copy" ' test_expect_success 'detect too small' ' @@ -522,6 +528,7 @@ test_expect_success 'git fsck (checks commit-graph)' ' git fsck && corrupt_graph_and_verify $GRAPH_BYTE_FOOTER "\00" \ "incorrect checksum" && + cp commit-graph-pre-write-test $objdir/info/commit-graph && test_must_fail git fsck ' From patchwork Mon Mar 25 12:08:34 2019 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: 10868979 Return-Path: Received: from mail.wl.linuxfoundation.org (pdx-wl-mail.web.codeaurora.org [172.30.200.125]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 8884F1575 for ; Mon, 25 Mar 2019 12:08:59 +0000 (UTC) Received: from mail.wl.linuxfoundation.org (localhost [127.0.0.1]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id 7441C2915D for ; Mon, 25 Mar 2019 12:08:59 +0000 (UTC) Received: by mail.wl.linuxfoundation.org (Postfix, from userid 486) id 6850929308; Mon, 25 Mar 2019 12:08:59 +0000 (UTC) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on pdx-wl-mail.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-8.0 required=2.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FROM,MAILING_LIST_MULTI,RCVD_IN_DNSWL_HI autolearn=ham version=3.3.1 Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.wl.linuxfoundation.org (Postfix) with ESMTP id B71FB29175 for ; Mon, 25 Mar 2019 12:08:58 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1731150AbfCYMI6 (ORCPT ); Mon, 25 Mar 2019 08:08:58 -0400 Received: from mail-wr1-f66.google.com ([209.85.221.66]:41255 "EHLO mail-wr1-f66.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731058AbfCYMI5 (ORCPT ); Mon, 25 Mar 2019 08:08:57 -0400 Received: by mail-wr1-f66.google.com with SMTP id r4so2134966wrq.8 for ; Mon, 25 Mar 2019 05:08:56 -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=wgZahpgW4PzIp1BpklZcG2GIWVNFLFYvBc2Mg8aYGX4=; b=Qt6h/H9ov64am1hAZ+sgFGHdb8Gy4b7hpuOjDrdSYKiCyg5RSB2Fmu9gJGXj42+wsX JWDHEYHVw6BHM/p35NbVoU1ltrC/6TrWASeAmJuM2ZDQkONRGXwOGiDQGB4R7Iah+0cR jlVOJ0yE2RVPypuzPgHy6m9xr4gFlVuQ8rhdDTvE4OFX0yeJabAtObbEUPXS1sB4XtXD cH99m/Wh7hHWbsrNG3n2LvNRY23k+h1tAfhRaRi3oRRd/ZozIOzJlurGC1W3YyIKsdbB eCrVXo0atk+yvWRHBCcnOkJqZ3hvyeBE7620w+QEYldSQnS6tyriSyEZu8sXsIj+slLZ Ju6g== 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=wgZahpgW4PzIp1BpklZcG2GIWVNFLFYvBc2Mg8aYGX4=; b=i636X/EzBOwFDt16aM2loiO92fipJY5xCwY85cx3dbk/joqlolEHgNQ7NNyOflnuVc RPkqRa1Rwa0k2pZ2vq/B2UBzPAMieL9cdVda8HXOJUfTC1+A7DazaW3TMkkolWjIHIRx G3PqcSwiNVetH1DgZC+fqEalYhdrUgy6ZIeLeZsJSLxMHVocapVnjL2O6ugqneMA7OlW DZ6lZ4IskrULOBax/lN5yAN0al9IKVXuBLGg0DZ7Up/hW9jwDgdPmK5zPyB0sHcGleNM yYqyUxTsSMMhYid3eK3X3H+DWibOd2Wfydqg1lwl12JjK+OwZSZVlfIGwmy9A+1ZOkUF i3UQ== X-Gm-Message-State: APjAAAWHyug31cppwvFV+tuw5sj2YIEQ9sfk905tVKnze7AALIF4+eG4 Q5trNrOFmQsZSJjDNxLit2I8Mi7xFdw= X-Google-Smtp-Source: APXvYqzPHHHM3p9SrhJ83TRfbZCugsXqLo1siWdVX5ys1DLQRS6zkel/sXCH3KOFotvHeeat0hKGKw== X-Received: by 2002:a5d:6292:: with SMTP id k18mr15958105wru.303.1553515735158; Mon, 25 Mar 2019 05:08:55 -0700 (PDT) Received: from vm.nix.is ([2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id n188sm15339464wme.13.2019.03.25.05.08.53 (version=TLS1_3 cipher=AEAD-AES256-GCM-SHA384 bits=256/256); Mon, 25 Mar 2019 05:08:54 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Derrick Stolee , =?utf-8?q?SZEDER_G=C3=A1bor?= , Eric Sunshine , Ramsay Jones , =?utf-8?b?w4Z2YXIgQXJuZmrDtnI=?= =?utf-8?b?w7AgQmphcm1hc29u?= Subject: [PATCH v3 8/8] commit-graph: improve & i18n error messages Date: Mon, 25 Mar 2019 13:08:34 +0100 Message-Id: <20190325120834.15529-9-avarab@gmail.com> X-Mailer: git-send-email 2.21.0.360.g471c308f928 In-Reply-To: <20190314214740.23360-1-avarab@gmail.com> References: <20190314214740.23360-1-avarab@gmail.com> MIME-Version: 1.0 Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org X-Virus-Scanned: ClamAV using ClamSMTP Change the error emitted when a commit-graph file is corrupt so that we actually mention the commit-graph, e.g. change errors like: error: improper chunk offset 0000000000385e0c To: error: commit-graph improper chunk offset 0000000000385e0c As discussed in the commits leading up to this one the commit-graph machinery is now used by common commands like "status". If the graph was corrupt we'd often emit some error that gave no indication what was wrong. Now some of them are still cryptic, but they'll at least mention "commit-graph" to give the user a hint as to where to look. While I'm at it mark some of the strings that hadn't been marked for translation. It's clear from the commit history and the code that this was merely forgotten at the time, and wasn't intentional.p5 Signed-off-by: Ævar Arnfjörð Bjarmason --- commit-graph.c | 38 +++++++++++++++++++------------------- 1 file changed, 19 insertions(+), 19 deletions(-) diff --git a/commit-graph.c b/commit-graph.c index 34ecaaf857..66865acbd7 100644 --- a/commit-graph.c +++ b/commit-graph.c @@ -167,21 +167,21 @@ struct commit_graph *parse_commit_graph(void *graph_map, int fd, graph_signature = get_be32(data); if (graph_signature != GRAPH_SIGNATURE) { - error(_("graph signature %X does not match signature %X"), + error(_("commit-graph signature %X does not match signature %X"), graph_signature, GRAPH_SIGNATURE); return NULL; } graph_version = *(unsigned char*)(data + 4); if (graph_version != GRAPH_VERSION) { - error(_("graph version %X does not match version %X"), + error(_("commit-graph version %X does not match version %X"), graph_version, GRAPH_VERSION); return NULL; } hash_version = *(unsigned char*)(data + 5); if (hash_version != oid_version()) { - error(_("hash version %X does not match version %X"), + error(_("commit-graph hash version %X does not match version %X"), hash_version, oid_version()); return NULL; } @@ -204,7 +204,7 @@ struct commit_graph *parse_commit_graph(void *graph_map, int fd, if (data + graph_size - chunk_lookup < GRAPH_CHUNKLOOKUP_WIDTH) { - error(_("chunk lookup table entry missing; graph file may be incomplete")); + error(_("commit-graph chunk lookup table entry missing; file may be incomplete")); free(graph); return NULL; } @@ -215,7 +215,7 @@ struct commit_graph *parse_commit_graph(void *graph_map, int fd, chunk_lookup += GRAPH_CHUNKLOOKUP_WIDTH; if (chunk_offset > graph_size - the_hash_algo->rawsz) { - error(_("improper chunk offset %08x%08x"), (uint32_t)(chunk_offset >> 32), + error(_("commit-graph improper chunk offset %08x%08x"), (uint32_t)(chunk_offset >> 32), (uint32_t)chunk_offset); free(graph); return NULL; @@ -252,7 +252,7 @@ struct commit_graph *parse_commit_graph(void *graph_map, int fd, } if (chunk_repeated) { - error(_("chunk id %08x appears multiple times"), chunk_id); + error(_("commit-graph chunk id %08x appears multiple times"), chunk_id); free(graph); return NULL; } @@ -1162,7 +1162,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g) hashcpy(cur_oid.hash, g->chunk_oid_lookup + g->hash_len * i); if (i && oidcmp(&prev_oid, &cur_oid) >= 0) - graph_report("commit-graph has incorrect OID order: %s then %s", + graph_report(_("commit-graph has incorrect OID order: %s then %s"), oid_to_hex(&prev_oid), oid_to_hex(&cur_oid)); @@ -1172,14 +1172,14 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g) uint32_t fanout_value = get_be32(g->chunk_oid_fanout + cur_fanout_pos); if (i != fanout_value) - graph_report("commit-graph has incorrect fanout value: fanout[%d] = %u != %u", + graph_report(_("commit-graph has incorrect fanout value: fanout[%d] = %u != %u"), cur_fanout_pos, fanout_value, i); cur_fanout_pos++; } graph_commit = lookup_commit(r, &cur_oid); if (!parse_commit_in_graph_one(r, g, graph_commit)) - graph_report("failed to parse %s from commit-graph", + graph_report(_("failed to parse commit %s from commit-graph"), oid_to_hex(&cur_oid)); } @@ -1187,7 +1187,7 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g) uint32_t fanout_value = get_be32(g->chunk_oid_fanout + cur_fanout_pos); if (g->num_commits != fanout_value) - graph_report("commit-graph has incorrect fanout value: fanout[%d] = %u != %u", + graph_report(_("commit-graph has incorrect fanout value: fanout[%d] = %u != %u"), cur_fanout_pos, fanout_value, i); cur_fanout_pos++; @@ -1209,14 +1209,14 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g) graph_commit = lookup_commit(r, &cur_oid); odb_commit = (struct commit *)create_object(r, cur_oid.hash, alloc_commit_node(r)); if (parse_commit_internal(odb_commit, 0, 0)) { - graph_report("failed to parse %s from object database", + graph_report(_("failed to parse commit %s from object database for commit-graph"), oid_to_hex(&cur_oid)); continue; } if (!oideq(&get_commit_tree_in_graph_one(r, g, graph_commit)->object.oid, get_commit_tree_oid(odb_commit))) - graph_report("root tree OID for commit %s in commit-graph is %s != %s", + graph_report(_("root tree OID for commit %s in commit-graph is %s != %s"), oid_to_hex(&cur_oid), oid_to_hex(get_commit_tree_oid(graph_commit)), oid_to_hex(get_commit_tree_oid(odb_commit))); @@ -1226,13 +1226,13 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g) while (graph_parents) { if (odb_parents == NULL) { - graph_report("commit-graph parent list for commit %s is too long", + graph_report(_("commit-graph parent list for commit %s is too long"), oid_to_hex(&cur_oid)); break; } if (!oideq(&graph_parents->item->object.oid, &odb_parents->item->object.oid)) - graph_report("commit-graph parent for %s is %s != %s", + graph_report(_("commit-graph parent for %s is %s != %s"), oid_to_hex(&cur_oid), oid_to_hex(&graph_parents->item->object.oid), oid_to_hex(&odb_parents->item->object.oid)); @@ -1245,16 +1245,16 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g) } if (odb_parents != NULL) - graph_report("commit-graph parent list for commit %s terminates early", + graph_report(_("commit-graph parent list for commit %s terminates early"), oid_to_hex(&cur_oid)); if (!graph_commit->generation) { if (generation_zero == GENERATION_NUMBER_EXISTS) - graph_report("commit-graph has generation number zero for commit %s, but non-zero elsewhere", + 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", + graph_report(_("commit-graph has non-zero generation number for commit %s, but zero elsewhere"), oid_to_hex(&cur_oid)); if (generation_zero == GENERATION_ZERO_EXISTS) @@ -1269,13 +1269,13 @@ int verify_commit_graph(struct repository *r, struct commit_graph *g) max_generation--; if (graph_commit->generation != max_generation + 1) - graph_report("commit-graph generation for commit %s is %u != %u", + graph_report(_("commit-graph generation for commit %s is %u != %u"), oid_to_hex(&cur_oid), graph_commit->generation, max_generation + 1); if (graph_commit->date != odb_commit->date) - graph_report("commit date for commit %s in commit-graph is %"PRItime" != %"PRItime, + graph_report(_("commit date for commit %s in commit-graph is %"PRItime" != %"PRItime), oid_to_hex(&cur_oid), graph_commit->date, odb_commit->date);