From patchwork Thu Feb 22 14:36:41 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13567422 Received: from mail-wr1-f47.google.com (mail-wr1-f47.google.com [209.85.221.47]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id C777F3DB9A for ; Thu, 22 Feb 2024 14:36:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.221.47 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708612611; cv=none; b=HirdeES8ufQ5YjBTUz2IDfo0VUU9B84ZUNJNvhT+J2TLD2LxmGcwQgCTUBt+WZrYW5VCU67oieCqkTkC6wyuvpVdM4MrQGgG9BHWn5LCC9LfN5wD81P77/tHZDu1VP1lduCppzDihge5sWVtnQ9p4jwCzg7u63kafVk+HWhkUUk= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708612611; c=relaxed/simple; bh=CWSOJRx5fGiD+VWfre6qxlFaVX4Agto1Xz0sb8/ndRc=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=oumQo3CMapXVaHO1O58LKoojlMTzmnKsGo9zIWuIgjd+PqVtO8ExANajlsxiAvw2WVPqLL8TbovpND17qaEp8HKu+C2VZ49ifAYYGAMRmADqI7s7vyuy8AvJ5UMdD1A0jdHDpCLQE3cxTO3oD9Vhw8aUeNJ0MRMmpSQnYbhGmew= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=maQ0meK8; arc=none smtp.client-ip=209.85.221.47 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="maQ0meK8" Received: by mail-wr1-f47.google.com with SMTP id ffacd0b85a97d-33d568fbf62so2593855f8f.3 for ; Thu, 22 Feb 2024 06:36:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708612608; x=1709217408; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=FwYeaUigHoLqe07Dyr7OAsD6q6DCJT125jNN3V4+eZs=; b=maQ0meK87yYvS1nnBxj/ez3sWz0L3VUXbuwb35yXK7i27q9Csx+/tw3GboGm2wqOyz QBxynSj1OLOMj/CzGRfz95TwLIKZkLCAMQy68ON0pfRPT0vlMX5hVijsyAx1zqWpRbxh 2WU+8haiyCMwuq8vdNAdjlg2v1PyNBfX4ve0ZLFPmfmMOqXhzet/MbmD3CFzjg6vxbfa JUFmjHHfFSV3yyNfTLQ84SDnYGacCtgTifdkX+sV5HwrZDlTwHW/bJZXLJi7KjOyZJAZ h6bR2rdU7NpV0jzkAtC9EyXNpWjhQmh5jf07aDvAd5XpXntnufcFbiH0lNWG0FFLLPXQ z9iw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708612608; x=1709217408; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=FwYeaUigHoLqe07Dyr7OAsD6q6DCJT125jNN3V4+eZs=; b=F5chVlo1L3cE0OJ0W4yQT1bPhMwe9MSBkovuAQDtNLH8jZECOFTK4RJuaFTZFG1Gy1 xYYpL0t2QPSHadwJqUu1b3a5ClLYJONzmwnezhoXElcHGPz5TBaITziMSYIdoMqZSH2f jOMTgUjh8uoElnLWWF6rX+zKR7VJiLbhe8GO5u+3DaO6ggibZZjOv4zXreXpXUiaj8ko IfNJCl79okUziVootAUIXpH9wa0FF8fWJrCUINVWSb+7mz7Lda8baXA3IS42I3JRF0k/ xf+sankRnd+jMyMBm88dH0YqsV24MBrEwRvyMksfXFajzElIaD0k64RdA24VV2GRdVuC C7aw== X-Gm-Message-State: AOJu0Yxebg6sGnREdqHenuRQE0CFEh0Q926X9qMRbbKCDiCMmSOLDlgH LwoCRz9n61w/vp42+WRY7RzT/MYIjM2q4lI4yWQW1ospAR6X5k8uMq9nqUP9 X-Google-Smtp-Source: AGHT+IE7KajycQsS9qgG2zSUtc22MGDOmJVFpb71r2lUcuG4YBBqNaM4xE7HmCLhgueml5R8VCMckQ== X-Received: by 2002:a05:6000:1a85:b0:33d:264d:6dfc with SMTP id f5-20020a0560001a8500b0033d264d6dfcmr14448968wry.63.1708612607713; Thu, 22 Feb 2024 06:36:47 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id cl2-20020a5d5f02000000b0033d4dab14a8sm14720330wrb.22.2024.02.22.06.36.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 06:36:47 -0800 (PST) Message-ID: <11b9cd8c5da5e6792ce940ea29d2e93e57731555.1708612605.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 22 Feb 2024 14:36:41 +0000 Subject: [PATCH v3 1/5] merge-tree: fail with a non-zero exit code on missing tree objects Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Patrick Steinhardt , Eric Sunshine , Johannes Schindelin , Johannes Schindelin From: Johannes Schindelin From: Johannes Schindelin When `git merge-tree` encounters a missing tree object, it should error out and not continue quietly as if nothing had happened. However, as of time of writing, `git merge-tree` _does_ continue, and then offers the empty tree as result. Let's fix this. Signed-off-by: Johannes Schindelin --- merge-ort.c | 7 ++++--- t/t4301-merge-tree-write-tree.sh | 11 +++++++++++ 2 files changed, 15 insertions(+), 3 deletions(-) diff --git a/merge-ort.c b/merge-ort.c index 6491070d965..c37fc035f13 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -1659,9 +1659,10 @@ static int collect_merge_info(struct merge_options *opt, info.data = opt; info.show_all_errors = 1; - parse_tree(merge_base); - parse_tree(side1); - parse_tree(side2); + if (parse_tree(merge_base) < 0 || + parse_tree(side1) < 0 || + parse_tree(side2) < 0) + return -1; init_tree_desc(t + 0, merge_base->buffer, merge_base->size); init_tree_desc(t + 1, side1->buffer, side1->size); init_tree_desc(t + 2, side2->buffer, side2->size); diff --git a/t/t4301-merge-tree-write-tree.sh b/t/t4301-merge-tree-write-tree.sh index 7d0fa74da74..908c9b540c8 100755 --- a/t/t4301-merge-tree-write-tree.sh +++ b/t/t4301-merge-tree-write-tree.sh @@ -951,4 +951,15 @@ test_expect_success '--merge-base with tree OIDs' ' test_cmp with-commits with-trees ' +test_expect_success 'error out on missing tree objects' ' + git init --bare missing-tree.git && + git rev-list side3 >list && + git rev-parse side3^: >>list && + git pack-objects missing-tree.git/objects/pack/side3-tree-is-missing actual 2>err && + test_grep "Could not read $(git rev-parse $side3:)" err && + test_must_be_empty actual +' + test_done From patchwork Thu Feb 22 14:36:42 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13567423 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 2B7923E498 for ; Thu, 22 Feb 2024 14:36:49 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708612611; cv=none; b=MOPu/Phvn3BfVZOyglPgLvkmsKtQNqDBtarTnuMOFV3+dZ/atdK+ySfyu6EGJ9Mfa2WkrNyXAg+WkmCl61zdgunZmgoSjWWFHdFF8bFafih3w4TvzJONL1uD2uL8QQRU+9V6nSExTiiClIlLEXIxZdgCfAK3eX/SEM0rRDNPSqo= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708612611; c=relaxed/simple; bh=Xq7WRXhxo0C1kRAmZ99K0pnF6HJm4Bw5bwfBCsQ5cn4=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=Yt7hLiUdsYaeOksoroOIK7ivMBKcVUNzxp+nsF/pFJPNQeOZd6/rqZksGRJBEyv4oQq5+zTZieSpiVk8gceuItV70oo0wRJfVAMBc5TBsK42bBTqzbLT9UwDdbp6CrGx5RaJ67MdjE3WnHyhWVqGIjHsYUNIixizygX5Rb/LH3g= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ksog571R; arc=none smtp.client-ip=209.85.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ksog571R" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-4128cfb6c1aso2998555e9.0 for ; Thu, 22 Feb 2024 06:36:49 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708612608; x=1709217408; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=3+i8PkXYJCTRN8cYGZeTF3cwl+HgYBrV1XX86X8PXc4=; b=ksog571R38PSxa+r/UISpZDV5p9U3lJUgSDqksJdJcRDnWvoG20jlBYH8tYyQu6Jaw 7lr4VeuaD5SuQrRPlC7wgoq/ZdfnJjf/CWHy0mT3UP1XM1qGaN/0Mful8UD3v+Rz8pfs XS3OfFG3scUuiG61CldXf2EcmkIN/xot3pc+sBdDTyhqcyIMCGFuDArspXsBOkNIOpps R8NOcdna66pbW6TKSc71ypG7nd9GXeBmQM/lbWKQY5aIMxFrBeGLVS5ANpDB23AnTcr7 eHAuf9nZGoECXxquU7jMqcTluDZDtQkHROT7oThhc8OoFY0Ls9gyiT20MiulKm1bvCE7 ha7A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708612608; x=1709217408; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=3+i8PkXYJCTRN8cYGZeTF3cwl+HgYBrV1XX86X8PXc4=; b=J3A1fI2T7U86lqm8gjFHabH4dh72WhfvAzMYUmh7Q6vWcfefcb+hH7t4FPvsgzVUlN YO4WvkST1P134MLEQG+d/mAGt2RrQsiS6FmA7x+EegZPbgAbI1yGNXJoQxgQMUVVC/fW 7JqRGfYnAIpfF+2aSk9pI/qgRs0srN8unvYwCDB0H8kDzoXVosyjrI2sVjwAYUj/GPdi rPpT6mVEDBrOIDsojVhT3HgvnCQZpR09v4g60Lp7VBj04ubYNLohlptPzckx1hEl7stm Ja69xi8QHyXY8nbV7HwuCMYXLuRlL2G17jcwA7h3ra9OSpLIpMNqZXvLWFQVF/TMXR/Y lirw== X-Gm-Message-State: AOJu0YzrfKpJ5M+dXgT/DKUsAr9pmbix4hBMVJ3qy0s3DxqaZaRwFeQx O+Wc1s9kaCBZg9e48HCMI0TdNRNETwwonTvYb9y1ZwxFGn4zmD2sJNc+khUf X-Google-Smtp-Source: AGHT+IFRAF0SPfd+D3ScagUUGz8Dbcucn9fPxLsyJLcazJYeMQ11p0IeCTCgU1gUbEx4TFzL4Yc60A== X-Received: by 2002:a05:600c:154b:b0:412:5eba:c155 with SMTP id f11-20020a05600c154b00b004125ebac155mr2516797wmg.11.1708612608326; Thu, 22 Feb 2024 06:36:48 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id jw3-20020a05600c574300b0040d5ae2906esm6391819wmb.30.2024.02.22.06.36.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 06:36:48 -0800 (PST) Message-ID: In-Reply-To: References: Date: Thu, 22 Feb 2024 14:36:42 +0000 Subject: [PATCH v3 2/5] merge-ort: do check `parse_tree()`'s return value Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Patrick Steinhardt , Eric Sunshine , Johannes Schindelin , Johannes Schindelin From: Johannes Schindelin From: Johannes Schindelin The previous commit fixed a bug where a missing tree was reported, but not treated as an error. This patch addresses the same issue for the remaining two callers of `parse_tree()`. This change is not accompanied by a regression test because the code in question is only reached at the `checkout` stage, i.e. after the merge has happened (and therefore the tree objects could only be missing if the disk had gone bad in that short time window, or something similarly tricky to recreate in the test suite). Signed-off-by: Johannes Schindelin --- merge-ort.c | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/merge-ort.c b/merge-ort.c index c37fc035f13..79d9e18f63d 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -4379,9 +4379,11 @@ static int checkout(struct merge_options *opt, unpack_opts.verbose_update = (opt->verbosity > 2); unpack_opts.fn = twoway_merge; unpack_opts.preserve_ignored = 0; /* FIXME: !opts->overwrite_ignore */ - parse_tree(prev); + if (parse_tree(prev) < 0) + return -1; init_tree_desc(&trees[0], prev->buffer, prev->size); - parse_tree(next); + if (parse_tree(next) < 0) + return -1; init_tree_desc(&trees[1], next->buffer, next->size); ret = unpack_trees(2, trees, &unpack_opts); From patchwork Thu Feb 22 14:36:43 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13567424 Received: from mail-wm1-f49.google.com (mail-wm1-f49.google.com [209.85.128.49]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 38F8353364 for ; Thu, 22 Feb 2024 14:36:51 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.49 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708612612; cv=none; b=sD1tvkHIhY8Dbjw04vorV2CJN/aSv24SAxL9TH1gkPu6NhopRFioe4+0hc+m37KkoRL97hgFawOWnvXO79GFq4AScjf+SGqE8mF3rgexigWX0gJJ69vdd3U8OlnSD9BwzKVOIxWQwff3flYjmOBtvIFBrypazqTuIn6/A+ohgf8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708612612; c=relaxed/simple; bh=C05rXEareOoDG82WPd99xJmYGLU1fbzABBWmtXJTWMY=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=P17I7reFWYwbZL/ILGCwFk0msgjcLOMLUWR/24RiDi7rNDstZwWPgaiptNCZ+0jeVSsjcvs3dZpz5huan902B1NkruJMvHr4Tynl804S2+/LcIxPNL2QpuCNn+9CbPwhY64ddNC9aJjHQ8arMZ9B6I65ciUJGfciydBXhSBd9Xk= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=Tv+A7Pjy; arc=none smtp.client-ip=209.85.128.49 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="Tv+A7Pjy" Received: by mail-wm1-f49.google.com with SMTP id 5b1f17b1804b1-41278553016so13759555e9.2 for ; Thu, 22 Feb 2024 06:36:50 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708612609; x=1709217409; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=zzXXrTR1654PTduFx3oEOukzzhnQP7ss3KpbX4fLdqU=; b=Tv+A7Pjyk7MvMa8l5x+sOUmSeBcK5vnRn29CrhyjH5ofuLDwekH2eU8kAc/Ygmro79 73/EWIR/WkyWjDOs7PULRcUX/2/q0nv1MM0xN8jsgIF6gYU+nT/f+DWwR8latHZnG06e 4CtKnsH9PanzQfN0Wb7JPJmHH6yIF2kcgHvRrzZrZqjGo6YTI3CiOVazTiUqXB/vW3IT Ww4mY/kVqIHNlKqsi8j1/wViz/jE57wcZh549ShbB8Bh1cleBrmZRoC9u+GJgk80fPC9 t5l6Cw18z78Juc/KqpVbgfq+jSB5qIdafRNW7FoULOSsh4GqxoSOg+ZBClOsi5bMOlvO NMfg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708612609; x=1709217409; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zzXXrTR1654PTduFx3oEOukzzhnQP7ss3KpbX4fLdqU=; b=ToSs9pQ5BqeCrHBl1uLM2Olp+1sTQxAOgzMLv/M7qu0GQpSH7sEcoLTTQNsONyphDK ckhh4LMHLX0sNIK4z9/5lqJcSU9AgNUjFjJIC6AToC/FD+gh0Nkhnj4dR9okH1aPb+iv c8cAJD9EV+6M2RAnUGMz4KK+Ljy2gNuKsOSRuDqKyZI7Ege3GpOY5erDx3APn9YMz5mV seTpH9vVtPay4Q9bctksC90ylRM9xuHndbdHR8iFqfVZg/B+6AHGY6S44IG+vHGp54t9 w3HfxgUyKx7MWpok7N7yw8dn8oTq3uYYZcaHzq4RlHrxHS/D/Zo/iua3nGICn0cIOlXN N0XQ== X-Gm-Message-State: AOJu0YzeEHphic53cWENOeeOgx/I1DD07TYYtPyy++9y5ohA1C5kc9cq 9bHYxWtqrS/INoFuCYWE1vcjviPkPodsPiC0tYc8RuQYDhFTwWRKz/lLB/El X-Google-Smtp-Source: AGHT+IHkSJZPmXj3Qwr/RZLSrs66Pwmg3IpXPzSm58vcsUr0UQcRAC2C2qHKfHtW7OCzbxUMMyKlLg== X-Received: by 2002:a05:600c:314b:b0:412:71fb:7732 with SMTP id h11-20020a05600c314b00b0041271fb7732mr4839559wmo.38.1708612609077; Thu, 22 Feb 2024 06:36:49 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id co3-20020a0560000a0300b0033d70dd0e04sm8625414wrb.8.2024.02.22.06.36.48 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 06:36:48 -0800 (PST) Message-ID: In-Reply-To: References: Date: Thu, 22 Feb 2024 14:36:43 +0000 Subject: [PATCH v3 3/5] t4301: verify that merge-tree fails on missing blob objects Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Patrick Steinhardt , Eric Sunshine , Johannes Schindelin , Johannes Schindelin From: Johannes Schindelin From: Johannes Schindelin We just fixed a problem where `merge-tree` would not fail on missing tree objects. Let's ensure that that problem does not occur with blob objects (and won't, in the future, either). Signed-off-by: Johannes Schindelin --- t/t4301-merge-tree-write-tree.sh | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/t/t4301-merge-tree-write-tree.sh b/t/t4301-merge-tree-write-tree.sh index 908c9b540c8..d4463a45706 100755 --- a/t/t4301-merge-tree-write-tree.sh +++ b/t/t4301-merge-tree-write-tree.sh @@ -962,4 +962,20 @@ test_expect_success 'error out on missing tree objects' ' test_must_be_empty actual ' +test_expect_success 'error out on missing blob objects' ' + echo 1 | git hash-object -w --stdin >blob1 && + echo 2 | git hash-object -w --stdin >blob2 && + echo 3 | git hash-object -w --stdin >blob3 && + printf "100644 blob $(cat blob1)\tblob\n" | git mktree >tree1 && + printf "100644 blob $(cat blob2)\tblob\n" | git mktree >tree2 && + printf "100644 blob $(cat blob3)\tblob\n" | git mktree >tree3 && + git init --bare missing-blob.git && + cat blob1 blob3 tree1 tree2 tree3 | + git pack-objects missing-blob.git/objects/pack/side1-whatever-is-missing && + test_must_fail git --git-dir=missing-blob.git >actual 2>err \ + merge-tree --merge-base=$(cat tree1) $(cat tree2) $(cat tree3) && + test_grep "unable to read blob object $(cat blob2)" err && + test_must_be_empty actual +' + test_done From patchwork Thu Feb 22 14:36:44 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13567425 Received: from mail-wm1-f41.google.com (mail-wm1-f41.google.com [209.85.128.41]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 470DA1487DD for ; Thu, 22 Feb 2024 14:36:52 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.128.41 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708612614; cv=none; b=V4Ygy/88gkOU6A5qdhuJ72Y+Rc018MTrPnXWYxb4fB3AM1HGRNp3IRzh9ordYmFanHtskdKnPatXq+YuEMzG0TBwdc5OwUamYm/H4Abp8u4QUytsGxY0229MHIsKiOJQY7Lls3Kiqp0wX9m5gdXOIZDMFK3zK1t8qi5Ji1x+fE8= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708612614; c=relaxed/simple; bh=6aEUjPpwEbnaYV3kXz/jrdo3l6oDJIDXkOyJXDDAdhY=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=ScotQl8NnkQVsveSs5TyBYiPzyFVzEvS26Ux7C2eIchGyoDlp6ld1YPh8WOnsyO1fB4b5hZrNsDqd4y3gTFbENEzCib4hY86mdstGKCfTotaugGg3LDGWAp0irOvr46ZqmYfU94eXl6G1JaMX8hbOWAlPvY7Zb2bqH+tv9y4HKw= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=ZKljunDe; arc=none smtp.client-ip=209.85.128.41 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ZKljunDe" Received: by mail-wm1-f41.google.com with SMTP id 5b1f17b1804b1-412698ac6f9so5834255e9.0 for ; Thu, 22 Feb 2024 06:36:51 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708612610; x=1709217410; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=Ad2cPhi69GjEqH2CIRTbzXTU/IPqUZKRLZ5wvFohiWs=; b=ZKljunDeZd6O8P+05pCQlocgcQnQkCTnPO3JG5SZj81IbO/VvZKZydoo9GyU8elAPN dUqaAROQ/yg4MTl2I7qJDBf3B7eRlRyCaxiTG5p3NbxSvTlHPUZU2x+6oZw17a1IQ7FD VAMs8KO38Bmis1Qje9LECbOOCzXvz+onexwIxF6bNE1QxZU+cmOFoM46o17y0gtweF9q PbeG3VRjZSehUmjTZvJLgOr3MH6b4QA9Q5HudVoQRH9jJfvgtZ81Lkpu5JgRL6+VtQ6s WupSyWgJmfPuXTsq/kFuMd3KznV3l3BaPjSSTh9q7k2GApHT709EEpBShHhvO4rmZx3v hWEg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708612610; x=1709217410; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=Ad2cPhi69GjEqH2CIRTbzXTU/IPqUZKRLZ5wvFohiWs=; b=hYyBM2JmKBwFURpvJp1gDpmqxjGOZkLEfQNpdgGP1UbAro8jBM9MpZw3u/q6OHOp49 FcoTp8T/73MH3tdtyAEmIIrtswOQN8g3QgX1+77IiBiUjtgYt3F5vIe1lObpvTZKXXM8 lF7zFj6dmkt5J+zfAt7R6cpFCst73m9NEbqUGg5pewnxGy7LSudOinRxtvqEhF8BfFXK 0Hh3wdYWciK0XBM1kkJ4qhPoi7j6ADp1jhAAKK+9aGG00HUuUE/9uD3EVNm+frp+Jugy YU0lr8arZy+7A7hcJiEo0x3uGe1DOXeyW7+lffhmvlXuqVluf3IH/iW7DxxE95PAPkQg g4zg== X-Gm-Message-State: AOJu0Yy6P+LKBCiTr8wFZQC58T/n2H0r9U89EuMVzNURSUazfIM3mjUE JkKbmPLlaNvUrtdYBS+4Ke+RquSvK1yS4EtgL/U5p0VLQT0JHm8whwjL92Iz X-Google-Smtp-Source: AGHT+IEhv9HUC2eOmEAWFpsRlT6UWNBsNUA79CMGHfAi1x3s+iVIq5k1ziSk/JGZhaHNCt/HzH6eSw== X-Received: by 2002:a05:600c:468b:b0:412:1d7d:6c82 with SMTP id p11-20020a05600c468b00b004121d7d6c82mr2402287wmo.9.1708612610258; Thu, 22 Feb 2024 06:36:50 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id bn7-20020a056000060700b0033d3ff1cb67sm15443245wrb.66.2024.02.22.06.36.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 06:36:49 -0800 (PST) Message-ID: <9e4dc94ef036882c3ce27208ca9fa545d018f199.1708612605.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 22 Feb 2024 14:36:44 +0000 Subject: [PATCH v3 4/5] Always check `parse_tree*()`'s return value Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Patrick Steinhardt , Eric Sunshine , Johannes Schindelin , Johannes Schindelin From: Johannes Schindelin From: Johannes Schindelin Otherwise we may easily run into serious crashes: For example, if we run `init_tree_desc()` directly after a failed `parse_tree()`, we are accessing uninitialized data or trying to dereference `NULL`. Note that the `parse_tree()` function already takes care of showing an error message. The `parse_tree_indirectly()` and `repo_get_commit_tree()` functions do not, therefore those latter call sites need to show a useful error message while the former do not. Signed-off-by: Johannes Schindelin --- builtin/checkout.c | 19 ++++++++++++++++--- builtin/clone.c | 3 ++- builtin/commit.c | 3 ++- builtin/merge-tree.c | 6 ++++++ builtin/read-tree.c | 3 ++- builtin/reset.c | 4 ++++ cache-tree.c | 4 ++-- merge-ort.c | 3 +++ merge-recursive.c | 3 ++- merge.c | 5 ++++- reset.c | 5 +++++ sequencer.c | 4 ++++ 12 files changed, 52 insertions(+), 10 deletions(-) diff --git a/builtin/checkout.c b/builtin/checkout.c index f02434bc155..84108ec3635 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -707,7 +707,8 @@ static int reset_tree(struct tree *tree, const struct checkout_opts *o, init_checkout_metadata(&opts.meta, info->refname, info->commit ? &info->commit->object.oid : null_oid(), NULL); - parse_tree(tree); + if (parse_tree(tree) < 0) + return 128; init_tree_desc(&tree_desc, tree->buffer, tree->size); switch (unpack_trees(1, &tree_desc, &opts)) { case -2: @@ -786,9 +787,15 @@ static int merge_working_tree(const struct checkout_opts *opts, if (new_branch_info->commit) BUG("'switch --orphan' should never accept a commit as starting point"); new_tree = parse_tree_indirect(the_hash_algo->empty_tree); - } else + if (!new_tree) + BUG("unable to read empty tree"); + } else { new_tree = repo_get_commit_tree(the_repository, new_branch_info->commit); + if (!new_tree) + return error(_("unable to read tree %s"), + oid_to_hex(&new_branch_info->commit->object.oid)); + } if (opts->discard_changes) { ret = reset_tree(new_tree, opts, 1, writeout_error, new_branch_info); if (ret) @@ -823,7 +830,8 @@ static int merge_working_tree(const struct checkout_opts *opts, oid_to_hex(old_commit_oid)); init_tree_desc(&trees[0], tree->buffer, tree->size); - parse_tree(new_tree); + if (parse_tree(new_tree) < 0) + exit(128); tree = new_tree; init_tree_desc(&trees[1], tree->buffer, tree->size); @@ -1239,10 +1247,15 @@ static void setup_new_branch_info_and_source_tree( if (!new_branch_info->commit) { /* not a commit */ *source_tree = parse_tree_indirect(rev); + if (!*source_tree) + die(_("unable to read tree %s"), oid_to_hex(rev)); } else { parse_commit_or_die(new_branch_info->commit); *source_tree = repo_get_commit_tree(the_repository, new_branch_info->commit); + if (!*source_tree) + die(_("unable to read tree %s"), + oid_to_hex(&new_branch_info->commit->object.oid)); } } diff --git a/builtin/clone.c b/builtin/clone.c index c6357af9498..4410b55be98 100644 --- a/builtin/clone.c +++ b/builtin/clone.c @@ -736,7 +736,8 @@ static int checkout(int submodule_progress, int filter_submodules) tree = parse_tree_indirect(&oid); if (!tree) die(_("unable to parse commit %s"), oid_to_hex(&oid)); - parse_tree(tree); + if (parse_tree(tree) < 0) + exit(128); init_tree_desc(&t, tree->buffer, tree->size); if (unpack_trees(1, &t, &opts) < 0) die(_("unable to checkout working tree")); diff --git a/builtin/commit.c b/builtin/commit.c index 781af2e206c..0723f06de7a 100644 --- a/builtin/commit.c +++ b/builtin/commit.c @@ -339,7 +339,8 @@ static void create_base_index(const struct commit *current_head) tree = parse_tree_indirect(¤t_head->object.oid); if (!tree) die(_("failed to unpack HEAD tree object")); - parse_tree(tree); + if (parse_tree(tree) < 0) + exit(128); init_tree_desc(&t, tree->buffer, tree->size); if (unpack_trees(1, &t, &opts)) exit(128); /* We've already reported the error, finish dying */ diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c index 2d4ce5b3886..ba84d00deee 100644 --- a/builtin/merge-tree.c +++ b/builtin/merge-tree.c @@ -447,12 +447,18 @@ static int real_merge(struct merge_tree_options *o, if (repo_get_oid_treeish(the_repository, merge_base, &base_oid)) die(_("could not parse as tree '%s'"), merge_base); base_tree = parse_tree_indirect(&base_oid); + if (!base_tree) + die(_("unable to read tree %s"), oid_to_hex(&base_oid)); if (repo_get_oid_treeish(the_repository, branch1, &head_oid)) die(_("could not parse as tree '%s'"), branch1); parent1_tree = parse_tree_indirect(&head_oid); + if (!parent1_tree) + die(_("unable to read tree %s"), oid_to_hex(&head_oid)); if (repo_get_oid_treeish(the_repository, branch2, &merge_oid)) die(_("could not parse as tree '%s'"), branch2); parent2_tree = parse_tree_indirect(&merge_oid); + if (!parent2_tree) + die(_("unable to read tree %s"), oid_to_hex(&merge_oid)); opt.ancestor = merge_base; merge_incore_nonrecursive(&opt, base_tree, parent1_tree, parent2_tree, &result); diff --git a/builtin/read-tree.c b/builtin/read-tree.c index 8196ca9dd85..5923ed36893 100644 --- a/builtin/read-tree.c +++ b/builtin/read-tree.c @@ -263,7 +263,8 @@ int cmd_read_tree(int argc, const char **argv, const char *cmd_prefix) cache_tree_free(&the_index.cache_tree); for (i = 0; i < nr_trees; i++) { struct tree *tree = trees[i]; - parse_tree(tree); + if (parse_tree(tree) < 0) + return 128; init_tree_desc(t+i, tree->buffer, tree->size); } if (unpack_trees(nr_trees, t, &opts)) diff --git a/builtin/reset.c b/builtin/reset.c index 4b018d20e3b..f030f57f4e9 100644 --- a/builtin/reset.c +++ b/builtin/reset.c @@ -119,6 +119,10 @@ static int reset_index(const char *ref, const struct object_id *oid, int reset_t if (reset_type == MIXED || reset_type == HARD) { tree = parse_tree_indirect(oid); + if (!tree) { + error(_("unable to read tree %s"), oid_to_hex(oid)); + goto out; + } prime_cache_tree(the_repository, the_repository->index, tree); } diff --git a/cache-tree.c b/cache-tree.c index 641427ed410..c6508b64a5c 100644 --- a/cache-tree.c +++ b/cache-tree.c @@ -779,8 +779,8 @@ static void prime_cache_tree_rec(struct repository *r, struct cache_tree_sub *sub; struct tree *subtree = lookup_tree(r, &entry.oid); - if (!subtree->object.parsed) - parse_tree(subtree); + if (!subtree->object.parsed && parse_tree(subtree) < 0) + exit(128); sub = cache_tree_sub(it, entry.path); sub->cache_tree = cache_tree(); diff --git a/merge-ort.c b/merge-ort.c index 79d9e18f63d..534ddaf16ba 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -4983,6 +4983,9 @@ static void merge_ort_nonrecursive_internal(struct merge_options *opt, if (result->clean >= 0) { result->tree = parse_tree_indirect(&working_tree_oid); + if (!result->tree) + die(_("unable to read tree %s"), + oid_to_hex(&working_tree_oid)); /* existence of conflicted entries implies unclean */ result->clean &= strmap_empty(&opt->priv->conflicted); } diff --git a/merge-recursive.c b/merge-recursive.c index e3beb0801b1..10d41bfd487 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -410,7 +410,8 @@ static inline int merge_detect_rename(struct merge_options *opt) static void init_tree_desc_from_tree(struct tree_desc *desc, struct tree *tree) { - parse_tree(tree); + if (parse_tree(tree) < 0) + exit(128); init_tree_desc(desc, tree->buffer, tree->size); } diff --git a/merge.c b/merge.c index b60925459c2..14a7325859d 100644 --- a/merge.c +++ b/merge.c @@ -80,7 +80,10 @@ int checkout_fast_forward(struct repository *r, return -1; } for (i = 0; i < nr_trees; i++) { - parse_tree(trees[i]); + if (parse_tree(trees[i]) < 0) { + rollback_lock_file(&lock_file); + return -1; + } init_tree_desc(t+i, trees[i]->buffer, trees[i]->size); } diff --git a/reset.c b/reset.c index 48da0adf851..a93fdbc12e3 100644 --- a/reset.c +++ b/reset.c @@ -158,6 +158,11 @@ int reset_head(struct repository *r, const struct reset_head_opts *opts) } tree = parse_tree_indirect(oid); + if (!tree) { + ret = error(_("unable to read tree %s"), oid_to_hex(oid)); + goto leave_reset_head; + } + prime_cache_tree(r, r->index, tree); if (write_locked_index(r->index, &lock, COMMIT_LOCK) < 0) { diff --git a/sequencer.c b/sequencer.c index d584cac8ed9..407473bab28 100644 --- a/sequencer.c +++ b/sequencer.c @@ -715,6 +715,8 @@ static int do_recursive_merge(struct repository *r, o.show_rename_progress = 1; head_tree = parse_tree_indirect(head); + if (!head_tree) + return error(_("unable to read tree %s"), oid_to_hex(head)); next_tree = next ? repo_get_commit_tree(r, next) : empty_tree(r); base_tree = base ? repo_get_commit_tree(r, base) : empty_tree(r); @@ -3887,6 +3889,8 @@ static int do_reset(struct repository *r, } tree = parse_tree_indirect(&oid); + if (!tree) + return error(_("unable to read tree %s"), oid_to_hex(&oid)); prime_cache_tree(r, r->index, tree); if (write_locked_index(r->index, &lock, COMMIT_LOCK) < 0) From patchwork Thu Feb 22 14:36:45 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Johannes Schindelin X-Patchwork-Id: 13567426 Received: from mail-lj1-f171.google.com (mail-lj1-f171.google.com [209.85.208.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by smtp.subspace.kernel.org (Postfix) with ESMTPS id 8706714901F for ; Thu, 22 Feb 2024 14:36:53 +0000 (UTC) Authentication-Results: smtp.subspace.kernel.org; arc=none smtp.client-ip=209.85.208.171 ARC-Seal: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708612615; cv=none; b=QsN7rofPnu34czfxIysUsed/SBuCEbQNYAuip7PxBlCh9wf5aYNX3TXkMcGWyWbb6VmeD+YQ5Wm1GXyZR84RKSppgQvuIA2hEmBpVltBmzlOxO7BFVbK7lpbeewkNc5rlsGNP2am6xLrZRm1kkplKt7zbJnNbNSOOfiP8pUnIPg= ARC-Message-Signature: i=1; a=rsa-sha256; d=subspace.kernel.org; s=arc-20240116; t=1708612615; c=relaxed/simple; bh=QSb/Qh/k/jtO5PpkL3y6lTEdSq/J5NWkFsE0nmeVhaY=; h=Message-ID:In-Reply-To:References:From:Date:Subject:Content-Type: MIME-Version:To:Cc; b=dHxbK6u1L1i3FqUsHyBZgh0KoWVWflmnqak4n65fmY2UxPRZbl3oe6UkluoEyn4FRjjhSaQ8HCq9LIkq9bWwjD4jFia2Bq0596vSMUZWw1D/4PFT6ad1ZSeJQYLh+H2XsDM3OuYTOpKQG8cB8UoOxZ/24PukYn+T56tGZ9CeAYQ= ARC-Authentication-Results: i=1; smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com; spf=pass smtp.mailfrom=gmail.com; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b=CeEkghhW; arc=none smtp.client-ip=209.85.208.171 Authentication-Results: smtp.subspace.kernel.org; dmarc=pass (p=none dis=none) header.from=gmail.com Authentication-Results: smtp.subspace.kernel.org; spf=pass smtp.mailfrom=gmail.com Authentication-Results: smtp.subspace.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="CeEkghhW" Received: by mail-lj1-f171.google.com with SMTP id 38308e7fff4ca-2d220ad10b3so75148751fa.1 for ; Thu, 22 Feb 2024 06:36:53 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1708612611; x=1709217411; darn=vger.kernel.org; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:from:to:cc:subject:date :message-id:reply-to; bh=y2HklqQzwQdN85hogz+D0Bk5KjHPdNYbw/bviEKo8cw=; b=CeEkghhWb2VStuo18LVW64J4q3XjJlVU3OOQ0IBNmtf5ZYJB5z6Uy4RDdEixm4entA GQ6hTzKwYzBq4guriQ06Y5YYFc5wV6TFQI2j2oDzvTqwKJJ+sMkevTR2kovbH+vCqfsT DiOKfKgMNaJIIL3qrQWrJgxVN6I4CVKsbKKsNn65ADMiCj9LbqHoY9/hGMq8+iVumCSg Nnrtj13dY8puLe5/ugeA8jAvQpy3+NLFA+C5aeklHbk9GH1tKuQSpj0xT7JY7ldUppAb 8LKSEdhL0wgi4vvJ3tykYdaqixSCJHna9SwSBtAkQWAA4cSVu+MgZZsFiYVvAwe0cVei 4LXw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1708612611; x=1709217411; h=cc:to:mime-version:content-transfer-encoding:fcc:subject:date:from :references:in-reply-to:message-id:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=y2HklqQzwQdN85hogz+D0Bk5KjHPdNYbw/bviEKo8cw=; b=YdHUusXo4SOwkxA0dFsU4NYThhswSGJFwrS63HOTOE28eV6ec5pU7NXxu0h6a05Rfn cUa0gkQK+GnBIzM30kFVGmzUobtcqnKY/gPNu4IyChx5UOslQj0Thfux7N4EYWus58++ bMhZ5vyI1jxaMd579jREQVKTQVYSd/kFHbQ1yG7IRITTCDIZvoqimZKDzXg8MyvpHFkI rXAlBzVkNEmYq10OfUSf5r5o58s6hH2thsdVR/sDunUL0X5GGL6gRR8I4v5huOhznkoW 3vfGOc8n2jx7dWmWximQ59i63CvpFY4PW2gkDHFqNcm6M/KECVY+0fICujpeXkq/SxqR 55Wg== X-Gm-Message-State: AOJu0YwyWeAhO/gUvOSTgfpjoniQ6smAgAPK2qBwZbbppXY8jrQ350aH LtjBkNkRPXJuAT/xkLsLFwuF5iVri6M2Nbr5K//YGT7vWpJ5n+j8SrE++VCU X-Google-Smtp-Source: AGHT+IHmRWqkZ/V88OKcKnlRebD9/DUwFdhx9+IDvfJwiV0+uEtXC2oOz/r56HfyZ1V2FBKI7wliIA== X-Received: by 2002:a2e:870a:0:b0:2d2:35af:e8a5 with SMTP id m10-20020a2e870a000000b002d235afe8a5mr9006971lji.24.1708612611179; Thu, 22 Feb 2024 06:36:51 -0800 (PST) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id bx9-20020a5d5b09000000b0033d202abf01sm5906201wrb.28.2024.02.22.06.36.50 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 22 Feb 2024 06:36:50 -0800 (PST) Message-ID: <91dc4ccd04e3a6cc50ed389edb6814e1e7a0c4dc.1708612605.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Thu, 22 Feb 2024 14:36:45 +0000 Subject: [PATCH v3 5/5] cache-tree: avoid an unnecessary check Fcc: Sent Precedence: bulk X-Mailing-List: git@vger.kernel.org List-Id: List-Subscribe: List-Unsubscribe: MIME-Version: 1.0 To: git@vger.kernel.org Cc: Patrick Steinhardt , Eric Sunshine , Johannes Schindelin , Johannes Schindelin From: Johannes Schindelin From: Johannes Schindelin The first thing the `parse_tree()` function does is to return early if the tree has already been parsed. Therefore we do not need to guard the `parse_tree()` call behind a check of that flag. As of time of writing, there are no other instances of this in Git's code bases: whenever the `parsed` flag guards a `parse_tree()` call, it guards more than just that call. Suggested-by: Patrick Steinhardt Signed-off-by: Johannes Schindelin --- cache-tree.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cache-tree.c b/cache-tree.c index c6508b64a5c..78d6ba92853 100644 --- a/cache-tree.c +++ b/cache-tree.c @@ -779,7 +779,7 @@ static void prime_cache_tree_rec(struct repository *r, struct cache_tree_sub *sub; struct tree *subtree = lookup_tree(r, &entry.oid); - if (!subtree->object.parsed && parse_tree(subtree) < 0) + if (parse_tree(subtree) < 0) exit(128); sub = cache_tree_sub(it, entry.path); sub->cache_tree = cache_tree();