From patchwork Wed Mar 16 20:12:00 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12783139 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0D200C433FE for ; Wed, 16 Mar 2022 20:12:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1357533AbiCPUNX (ORCPT ); Wed, 16 Mar 2022 16:13:23 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60870 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356184AbiCPUNV (ORCPT ); Wed, 16 Mar 2022 16:13:21 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 865846E37D for ; Wed, 16 Mar 2022 13:12:06 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id u10so4514212wra.9 for ; Wed, 16 Mar 2022 13:12:06 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=Y3kmhBiIfQZuWnSQxBg2UxN/8HabZZOuizQ279yE4JQ=; b=ZpMq/UL5IoLNSLEbJPSPSa074BJcdzh70WglYJUUr8wM38GhqBaoqCjioMCVt9rO6u vAZTt40SnXfesNBIvbAocOJfW5yVNak09sHkJZQ3JgBarYqrzGwHSe93FUozfLbIW1w6 dbniFAuOuHli/3Gn+eDd6XoYrNFhSVDwcm3w2cELvW8UW1YXJqPGldovPRPOGSUqJXSS zlu4GjHooZh4mNi8mLjUtW3XQ4FA3pHlxSH9iqu5BR5ubsTeCNJRBiDRECS3h/RRu5Kx HR+TOsG9l3Ww+1QZ4BdKgyW6wT2wA9lnxw/izXWD2l/gljyTIamDTsjUBR1UcMSRycYg lVGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=Y3kmhBiIfQZuWnSQxBg2UxN/8HabZZOuizQ279yE4JQ=; b=wOongBG3RZP/aGbD7ocxn5WsUlQAoHfuBUmFsBBPkO7GWwsFmreMTjZLUsKoaIKStu pJjbWRTgpaRO7dkPLRbonODh2lnrhJ2JdwBh5iZsfqjdeMtzk2PZ3AR2rCVqtQh1dnpK biD/Z3BnSJJngUsTde72urXyKjQ+5FQHrvkNQ7I5OWodC0ds+QlQDvPjLPt8dSE6tFey xMo250cmcMdqSFvpoxcLFTwzNgP94gbnlr8H8koNaU+wxnv9MIF++hsokcEvw2zhBnCQ GhIQ3vaigN1/JFDM4ji75iX3PLFAbKMrscpZxAH5/S8Yc8upFvriY6uQnypT0kCnJxPB 8xgA== X-Gm-Message-State: AOAM533nBQnh/mwM0boADU3hMxKnhHyNCv7aQ0kUP9NYYKwAE4uknLDn WeYC2rkgmwZmcPjaOW8xcqvULiaRdaw= X-Google-Smtp-Source: ABdhPJzJxrwUk638F5AYO0Tx4XjlOo+LtgI6iz4OkeOKBoLNgqi0/AvRimtpE62+pNLBxak2nm0jOg== X-Received: by 2002:adf:90e2:0:b0:1e3:f5a:553c with SMTP id i89-20020adf90e2000000b001e30f5a553cmr1220415wri.476.1647461524899; Wed, 16 Mar 2022 13:12:04 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id r1-20020a5d4941000000b001ed89dcacbbsm2419085wrs.23.2022.03.16.13.12.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 13:12:04 -0700 (PDT) Message-Id: <726b947bcbfa8ff10dba0241460cbf1a0cbcd7e4.1647461522.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 16 Mar 2022 20:12:00 +0000 Subject: [PATCH 1/3] t1092: add sparse directory before cone in test repo Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: derrickstolee@github.com, gitster@pobox.com, newren@gmail.com, Victoria Dye , Victoria Dye Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Victoria Dye From: Victoria Dye Add a sparse directory 'before/' containing files 'a' and 'b' to the test repo used in 't/t1092-sparse-checkout-compatibility.sh'. This is meant to ensure that no sparse index integrations rely on the in-cone path(s) being lexicographically first in the repo. Unfortunately, some existing tests do not handle this repo architecture properly: * 'add outside sparse cone' * 'status/add: outside sparse cone' * 'reset with pathspecs inside sparse definition' All three of these are due to the incorrect handling of the 'unpack_trees_options.cache_bottom' when performing a cache diff via 'unpack_trees'. This will be corrected in a future patch; in the meantime, mark the tests with 'test_expect_failure'. Finally, update the 'ls-files' test to include the 'before/' directory in its expected results. Co-authored-by: Derrick Stolee Signed-off-by: Victoria Dye --- t/t1092-sparse-checkout-compatibility.sh | 12 ++++++++---- 1 file changed, 8 insertions(+), 4 deletions(-) diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh index 2a04b532f91..11141221b4d 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -16,7 +16,9 @@ test_expect_success 'setup' ' echo "after deep" >e && echo "after folder1" >g && echo "after x" >z && - mkdir folder1 folder2 deep x && + mkdir folder1 folder2 deep before x && + echo "before deep" >before/a && + echo "before deep again" >before/b && mkdir deep/deeper1 deep/deeper2 deep/before deep/later && mkdir deep/deeper1/deepest && mkdir deep/deeper1/deepest2 && @@ -312,7 +314,7 @@ test_expect_success 'deep changes during checkout' ' test_all_match git checkout base ' -test_expect_success 'add outside sparse cone' ' +test_expect_failure 'add outside sparse cone' ' init_repos && run_on_sparse mkdir folder1 && @@ -354,7 +356,7 @@ test_expect_success 'commit including unstaged changes' ' test_all_match git status --porcelain=v2 ' -test_expect_success 'status/add: outside sparse cone' ' +test_expect_failure 'status/add: outside sparse cone' ' init_repos && # folder1 is at HEAD, but outside the sparse cone @@ -565,7 +567,7 @@ test_expect_success 'checkout and reset (keep)' ' test_all_match test_must_fail git reset --keep deepest ' -test_expect_success 'reset with pathspecs inside sparse definition' ' +test_expect_failure 'reset with pathspecs inside sparse definition' ' init_repos && write_script edit-contents <<-\EOF && @@ -1311,6 +1313,7 @@ test_expect_success 'ls-files' ' cat >expect <<-\EOF && a + before/ deep/ e folder1- @@ -1358,6 +1361,7 @@ test_expect_success 'ls-files' ' cat >expect <<-\EOF && a + before/ deep/ e folder1- From patchwork Wed Mar 16 20:12:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12783140 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id EF583C433F5 for ; Wed, 16 Mar 2022 20:12:21 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240617AbiCPUNb (ORCPT ); Wed, 16 Mar 2022 16:13:31 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60920 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1356732AbiCPUNW (ORCPT ); Wed, 16 Mar 2022 16:13:22 -0400 Received: from mail-wr1-x436.google.com (mail-wr1-x436.google.com [IPv6:2a00:1450:4864:20::436]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AB36C6E4C1 for ; Wed, 16 Mar 2022 13:12:07 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id h15so4528763wrc.6 for ; Wed, 16 Mar 2022 13:12:07 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=a9AtQavLTw02jgTKNRQQ6rCtDH9TTkehw1UKIDyxuEU=; b=VOP+jvQw4yhENu4/4YRxPGwJcEg3fu/+fn7eG7xXSieZMz+Cq4AjauAEZ82/LWwp3q mS2nyU434ieumkd/2humNVpnpCju0jL3yuyoXFNqXObv//A7kCRfNH/zrS4rZqLWXkaR ioumu6sYxq4+/+RAFQdU5orKOW1hM/2gKumIVYLTTc7vyBdVFL3Fn41ylFy0xGGuPfmI WAkHh0C2yjjR0IkZQjfSS28xAc+bcuRjLm8WKSqb6yJqxRgkTrShenwOjGI+KaRPfydv PX8kxfmrgp+Ox2tSSgQpPLafKWVew4BQ6Qar7vxV2l9ejW+wWV9H8NuA3uJzUTJjUhTe IP6g== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=a9AtQavLTw02jgTKNRQQ6rCtDH9TTkehw1UKIDyxuEU=; b=blrRXayn9OZAnKOfPfowRKzG5VTANgz3Pt9J9WBAUslt5dflJSsuAKS6WhYLb9U26C YIJiLRxvw+TpOYNd1avfKk0VA1w/L8n3D/sSENJd84FWowJuTsy0HpSNtQrX1TPPfKiA 06C+aPnwoeZMC1KKv2eJjf3fZKczBpLdUYl13pqshg6ReqFNT5v821r7jh4WETXgLLWE NuPNxLSlz8GrAUUFOn1NOTZVRyuLZ497/H/3Mqw2pPiXOkEp0yGLcxrjmaO1IswCYynQ Plne4HsNxu5UzZJSbn1Jg0kB9VxgE1XZf1pLLmLwtjp5vWYv/vIMKz6kFdMbLDTby6Ve LCBw== X-Gm-Message-State: AOAM5328ymGxAiZGT9ooo+QlcmW89wmFszZflSwld+aN0eh7hzlPQyMT pYqdjkRUymWMhsjVkZ7/wCAxwD46meM= X-Google-Smtp-Source: ABdhPJyLGl8LLcJp0FQlNgLF8ItYjK6NJl9uM/KYvn7jplU7mQdiaUeI6E7VMsF2uLzoLpfisbbs5w== X-Received: by 2002:a5d:4a0f:0:b0:1ed:d377:288a with SMTP id m15-20020a5d4a0f000000b001edd377288amr1194958wrq.3.1647461525899; Wed, 16 Mar 2022 13:12:05 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id i15-20020a05600011cf00b001edc2966dd4sm2291457wrx.47.2022.03.16.13.12.05 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 13:12:05 -0700 (PDT) Message-Id: <8ebfebcc3473e6a5d1052b14b3e9d43036cb6857.1647461522.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Wed, 16 Mar 2022 20:12:01 +0000 Subject: [PATCH 2/3] unpack-trees: increment cache_bottom for sparse directories Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: derrickstolee@github.com, gitster@pobox.com, newren@gmail.com, Victoria Dye , Victoria Dye Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Victoria Dye From: Victoria Dye Correct tracking of the 'cache_bottom' for cases where sparse directories are present in the index. BACKGROUND ---------- The 'unpack_trees_options.cache_bottom' is a variable that tracks the in-progress "bottom" of the cache as 'unpack_trees()' iterates through the contents of the index. Most importantly, this value informs the sequential return values of 'next_cache_entry()' which, in the "diff cache" usage of 'unpack_callback()', are either unpacked as-is or are passed into the diff machinery. The 'cache_bottom' is intended to track the position of the first entry in the index that has not yet been diffed or unpacked. It is advanced in two main ways: either it is incremented when an index entry is marked as "used" (in 'mark_ce_used()'), indicating that it was unpacked or diffed, or when a directory is unpacked, in which case it is increased by an amount equaling the number of index entries inside that tree. In 17a1bb570b (unpack-trees: preserve cache_bottom, 2021-07-14), it was identified that sparse directories posed a problem to the above 'cache_bottom' advancement logic - because a sparse directory was both an index entry that could be "used" and a directory that can be unpacked, the 'cache_bottom' would be incremented too many times. To solve this problem, the 'mark_ce_used()' advancement of 'cache_bottom' was skipped for sparse directories. INCORRECT CACHE_BOTTOM TRACKING ------------------------------- Skipping the 'cache_bottom' advancement for sparse directories in 'mark_ce_used()' breaks down in two cases: 1. When the 'unpack_trees()' operation is *not* a "cache diff" (because the directory contents-based incrementing of 'cache_bottom' does not happen). 2. When a cache diff is performed with a pathspec (because 'unpack_index_entry()' will unpack a sparse directory not matched by the pathspec without performing the directory contents-based increment). The former luckily does not appear to affect 'git' behavior, likely because 'cache_bottom' is largely unused (non-"cache diff" 'unpack_trees()' uses 'find_index_entry()' - rather than 'next_cache_entry()' - to find the index entries to unpack). The latter, however, causes 'cache_bottom' to "lag behind" its intended position by an amount equal to the number of sparse directories unpacked so far with 'unpack_index_entry()'. If a repository is structured such that any sparse directories are ordered lexicographically *after* any pathspec-matching directories, though, this issue won't present any adverse behavior. This was the case with the 't1092-sparse-checkout-compatibility.sh' tests before the addition of the 'before/' sparse directory (ordered *before* the in-cone 'deep/' directory), therefore sidestepping the issue. Once the 'before/' directory was added, though, 'cache_bottom' began to lag behind its intended position, causing 'next_cache_entry()' to return index entries it had already processed and, ultimately, an incorrect diff. CORRECTING CACHE_BOTTOM ----------------------- The problems observed in 't1092' come from 'cache_bottom' lagging behind in cases where the cache tree-based advancement doesn't occur. To solve this, then, the fix in 17a1bb570b is "reversed"; rather than skipping 'cache_bottom' advancement in 'mark_ce_used()', we skip the directory contents-based advancement for sparse directories. Now, every index entry can be accounted for in 'cache_bottom': * if you're working with a single index entry, 'cache_bottom' is incremented in 'mark_ce_used()' * if you're working with a directory that contains index entries (but is not one itself), 'cache_bottom' is incremented by the number of entries in that directory. Finally, change the 'test_expect_failure' tests in 't1092' failing due to this bug back to 'test_expect_success'. Signed-off-by: Victoria Dye --- t/t1092-sparse-checkout-compatibility.sh | 6 +++--- unpack-trees.c | 16 ++++++++-------- 2 files changed, 11 insertions(+), 11 deletions(-) diff --git a/t/t1092-sparse-checkout-compatibility.sh b/t/t1092-sparse-checkout-compatibility.sh index 11141221b4d..e9533832aab 100755 --- a/t/t1092-sparse-checkout-compatibility.sh +++ b/t/t1092-sparse-checkout-compatibility.sh @@ -314,7 +314,7 @@ test_expect_success 'deep changes during checkout' ' test_all_match git checkout base ' -test_expect_failure 'add outside sparse cone' ' +test_expect_success 'add outside sparse cone' ' init_repos && run_on_sparse mkdir folder1 && @@ -356,7 +356,7 @@ test_expect_success 'commit including unstaged changes' ' test_all_match git status --porcelain=v2 ' -test_expect_failure 'status/add: outside sparse cone' ' +test_expect_success 'status/add: outside sparse cone' ' init_repos && # folder1 is at HEAD, but outside the sparse cone @@ -567,7 +567,7 @@ test_expect_success 'checkout and reset (keep)' ' test_all_match test_must_fail git reset --keep deepest ' -test_expect_failure 'reset with pathspecs inside sparse definition' ' +test_expect_success 'reset with pathspecs inside sparse definition' ' init_repos && write_script edit-contents <<-\EOF && diff --git a/unpack-trees.c b/unpack-trees.c index 96525d2ec26..aac927faf08 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -595,13 +595,6 @@ static void mark_ce_used(struct cache_entry *ce, struct unpack_trees_options *o) { ce->ce_flags |= CE_UNPACKED; - /* - * If this is a sparse directory, don't advance cache_bottom. - * That will be advanced later using the cache-tree data. - */ - if (S_ISSPARSEDIR(ce->ce_mode)) - return; - if (o->cache_bottom < o->src_index->cache_nr && o->src_index->cache[o->cache_bottom] == ce) { int bottom = o->cache_bottom; @@ -1442,7 +1435,14 @@ static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str * it does not do any look-ahead, so this is safe. */ if (matches) { - o->cache_bottom += matches; + /* + * Only increment the cache_bottom if the + * directory isn't a sparse directory index + * entry (if it is, it was already incremented) + * in 'mark_ce_used()' + */ + if (!src[0] || !S_ISSPARSEDIR(src[0]->ce_mode)) + o->cache_bottom += matches; return mask; } } From patchwork Wed Mar 16 20:12:02 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Victoria Dye X-Patchwork-Id: 12783141 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id C8350C433EF for ; Wed, 16 Mar 2022 20:12:24 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S240683AbiCPUNf (ORCPT ); Wed, 16 Mar 2022 16:13:35 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:60938 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1357363AbiCPUNX (ORCPT ); Wed, 16 Mar 2022 16:13:23 -0400 Received: from mail-wr1-x42a.google.com (mail-wr1-x42a.google.com [IPv6:2a00:1450:4864:20::42a]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 846B96E37D for ; Wed, 16 Mar 2022 13:12:08 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id h23so3918507wrb.8 for ; Wed, 16 Mar 2022 13:12:08 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20210112; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=Xrp8MT8ACTXGNJUVhneG1R5rYubVZNSKTK4YRPw0Nmw=; b=qCG8S7ZOZOa7MD9/N2PH5fyyrPg+UT+kbT1D4kdHdUrA3TCr0vtLZwffl8UTIgtOEo dauiUm/vAcBR6ejQ+tigbSUU4IjehK3GEAmmG/O9A3k+XlDDmLVeYBHtZxWFglbQy/pe N+/oRR5JVFyNZ31GLa4XVr8vVLj6jgOApHCEQ4RTLYr6AyOUOdzfQJ9YIT0i/lb37kgl U14OKl85Iipi3BPeD0v2I24WxSQqyPUKQtrerX07SYuvFmItvPToyNG+TjDjwTh9NOIf h1buVOB7oHvk6m7bTV/lMFFXzYMrBJD4qAXVOltpOZ7Mm9gxn5eVhT66ciuTbgnAOjS0 /pDw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=Xrp8MT8ACTXGNJUVhneG1R5rYubVZNSKTK4YRPw0Nmw=; b=NMSOoaV8HjQCnIPWwclH2nj95LpzEeMZcTNoO/EvgbHWH4OMs2JC49YSj09KxaECQK 4bIS285kVB0GmaJAkJPWPQWCiZlvVcKL9Ejh9KVQlp1M+9GUopiF57KECuRZXFUwyyTW pj5iuIXNDoPB56ueiVqXOFurnDkiqhfPBo/LXuu1F7P2JxEX/8py8loz3LnMG9yWrDZ6 Rc2YWa15etXXb9tj8wafqOT/BkhFqv2jF9V/ZUp9YCZiLsoxXkKcJJMa8SAAI4dchW2A eEkvPfIwLNdbHyHP2bvHGxr2h/WrtvRVQP8xP9idn0IEqDqep7Plkf0NZsAfbFL/9xVH cHGQ== X-Gm-Message-State: AOAM533cb2lAxk+5iy58c+ir1ry+cZuhYAb6S/GjY169xydtBEQ20FbO z1d2KmXqcUPaD7ncBiZtf/0XAy7WnA0= X-Google-Smtp-Source: ABdhPJxx1iAPCRh734fKNUkslZqdWDilToXvjrDVrEk3Q1j5cB9utjBh6kFcMjPPfUu9sq/xes4TcQ== X-Received: by 2002:a5d:6d44:0:b0:1e4:9a6d:c171 with SMTP id k4-20020a5d6d44000000b001e49a6dc171mr1303890wri.468.1647461526921; Wed, 16 Mar 2022 13:12:06 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id h18-20020a05600c351200b0038c6d38b42fsm2800590wmq.36.2022.03.16.13.12.06 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 16 Mar 2022 13:12:06 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Wed, 16 Mar 2022 20:12:02 +0000 Subject: [PATCH 3/3] Revert "unpack-trees: improve performance of next_cache_entry" Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: derrickstolee@github.com, gitster@pobox.com, newren@gmail.com, Victoria Dye , Victoria Dye Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Victoria Dye From: Victoria Dye This reverts commit f2a454e0a5 (unpack-trees: improve performance of next_cache_entry, 2021-11-29). The "hint" value was originally needed to improve performance in 'git reset -- ' caused by 'cache_bottom' lagging behind its correct value when using a sparse index. The 'cache_bottom' tracking has since been corrected, removing the need for an additional "pseudo-cache_bottom" tracking variable. Signed-off-by: Victoria Dye --- unpack-trees.c | 23 ++++++----------------- 1 file changed, 6 insertions(+), 17 deletions(-) diff --git a/unpack-trees.c b/unpack-trees.c index aac927faf08..7e5715c42b3 100644 --- a/unpack-trees.c +++ b/unpack-trees.c @@ -644,24 +644,17 @@ static void mark_ce_used_same_name(struct cache_entry *ce, } } -static struct cache_entry *next_cache_entry(struct unpack_trees_options *o, int *hint) +static struct cache_entry *next_cache_entry(struct unpack_trees_options *o) { const struct index_state *index = o->src_index; int pos = o->cache_bottom; - if (*hint > pos) - pos = *hint; - while (pos < index->cache_nr) { struct cache_entry *ce = index->cache[pos]; - if (!(ce->ce_flags & CE_UNPACKED)) { - *hint = pos + 1; + if (!(ce->ce_flags & CE_UNPACKED)) return ce; - } pos++; } - - *hint = pos; return NULL; } @@ -1373,13 +1366,12 @@ static int unpack_callback(int n, unsigned long mask, unsigned long dirmask, str /* Are we supposed to look at the index too? */ if (o->merge) { - int hint = -1; while (1) { int cmp; struct cache_entry *ce; if (o->diff_index_cached) - ce = next_cache_entry(o, &hint); + ce = next_cache_entry(o); else ce = find_cache_entry(info, p); @@ -1706,7 +1698,7 @@ static int verify_absent(const struct cache_entry *, int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options *o) { struct repository *repo = the_repository; - int i, hint, ret; + int i, ret; static struct cache_entry *dfc; struct pattern_list pl; int free_pattern_list = 0; @@ -1795,15 +1787,13 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options info.pathspec = o->pathspec; if (o->prefix) { - hint = -1; - /* * Unpack existing index entries that sort before the * prefix the tree is spliced into. Note that o->merge * is always true in this case. */ while (1) { - struct cache_entry *ce = next_cache_entry(o, &hint); + struct cache_entry *ce = next_cache_entry(o); if (!ce) break; if (ce_in_traverse_path(ce, &info)) @@ -1824,9 +1814,8 @@ int unpack_trees(unsigned len, struct tree_desc *t, struct unpack_trees_options /* Any left-over entries in the index? */ if (o->merge) { - hint = -1; while (1) { - struct cache_entry *ce = next_cache_entry(o, &hint); + struct cache_entry *ce = next_cache_entry(o); if (!ce) break; if (unpack_index_entry(ce, o) < 0)