From patchwork Sat Mar 20 22:37:44 2021 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: 12152715 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 0DEBFC433E0 for ; Sat, 20 Mar 2021 22:39:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id D68D461934 for ; Sat, 20 Mar 2021 22:39:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229817AbhCTWii (ORCPT ); Sat, 20 Mar 2021 18:38:38 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44688 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229884AbhCTWiN (ORCPT ); Sat, 20 Mar 2021 18:38:13 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 70D57C061762 for ; Sat, 20 Mar 2021 15:38:13 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id 61so12735563wrm.12 for ; Sat, 20 Mar 2021 15:38:13 -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=wkikqtckOxxRMS9tyl7Rl5yFN9jrcYkDDHWAvlagGdE=; b=OxMsDWPcsq7iBEJc6zeWnm62JIaLWlSHD9VIbuJSDGfr2ecv81PCjy2co5eMlwgs7X JPk30XaY+x/8t+5lJor9IjLNLO9nQ/ZcEco9G75hdyIq2yrKFEYJjI08DXFaPfzxxqHm X29u+Q0vm9PC7sJSrLKDn4AbYrJX9hfB/yZ2F2aBtKeAadcC6aZ0i3mBZAAR9+RYG5kq 7jjSAfS9Y5hlVM/Qny/XzSjmedyeylyxRZFAiYLKqD+o0dGuJiRgV10OUI+oY6iOtubb XPx28wnDGYsW9+xfbiyqB+QThe/bcz9nsHAh9u4UsuYH/hdOY+p07eExcfB6YyE8YFTe nHRw== 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=wkikqtckOxxRMS9tyl7Rl5yFN9jrcYkDDHWAvlagGdE=; b=RojFyr/qzyCgjgwRXRcwxb+QdAgzbUXL9RTl4WLHLmAIAQtmyCssqk0/xloXw8o822 J61SWbzFHhSsrNbpZAX5v6hs8sK2kD5zrNDRwRjDSndHJqV2QN0tx0RMnE7g8/wFK0am MImltIpcFzKikt3QDWfqp5ZlkK97UeD4EZeAWsIuI/BIQmYLbAZrIMOf+N574f4Le7B2 Q5Jya/MuKCaXv7Hv1WanrYCduiKMREjqjnrbGWZZQZxD0h2ULQdDqeymgseqhDI0gGfg CylH9fuKNB60ltCGE95m/tqJPwJFmycP5hNeD+IL79TvG6KzByLIcLfwUkYCVgWhu2IP 7NPA== X-Gm-Message-State: AOAM531y6z/7a97UHbIPtMNEGsrviBTOvHWiPFO0qYydqMNjVIZGgapn lBEzHWkS93DuwS9xpLUaHCuLgkNeLTGhmQ== X-Google-Smtp-Source: ABdhPJzTFFPePROCDwKb83pSnn9XEaqD+i9pCrkQZezTrp8MHLhWJdOmtS8bjCIqyM1TNYImAG10Jg== X-Received: by 2002:a5d:6a87:: with SMTP id s7mr10979827wru.312.1616279891921; Sat, 20 Mar 2021 15:38:11 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v2sm21472697wmj.1.2021.03.20.15.38.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 15:38:11 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 1/8] show tests: add test for "git show " Date: Sat, 20 Mar 2021 23:37:44 +0100 Message-Id: X-Mailer: git-send-email 2.31.0.286.gc175f2cb894 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add missing tests for showing a tree with "git show". Let's test for showing a tree, two trees, and that doing so doesn't recurse. The only tests for this code added in 5d7eeee2ac6 (git-show: grok blobs, trees and tags, too, 2006-12-14) were the tests in t7701-repack-unpack-unreachable.sh added in ccc1297226b (repack: modify behavior of -A option to leave unreferenced objects unpacked, 2008-05-09). Let's add this common mode of operation to the "show" tests themselves. It's more obvious, and the tests in t7701-repack-unpack-unreachable.sh happily pass if we start buggily emitting trees recursively. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t7007-show.sh | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/t/t7007-show.sh b/t/t7007-show.sh index 42d3db62468..d6cc69e0f2c 100755 --- a/t/t7007-show.sh +++ b/t/t7007-show.sh @@ -38,6 +38,45 @@ test_expect_success 'showing two commits' ' test_cmp expect actual.filtered ' +test_expect_success 'showing a tree' ' + cat >expected <<-EOF && + tree main1: + + main1.t + EOF + git show main1: >actual && + test_cmp expected actual +' + +test_expect_success 'showing two trees' ' + cat >expected <<-EOF && + tree main1^{tree} + + main1.t + + tree main2^{tree} + + main1.t + main2.t + EOF + git show main1^{tree} main2^{tree} >actual && + test_cmp expected actual +' + +test_expect_success 'showing a trees is not recursive' ' + git worktree add not-recursive main1 && + mkdir not-recursive/a && + test_commit -C not-recursive a/file && + cat >expected <<-EOF && + tree HEAD^{tree} + + a/ + main1.t + EOF + git -C not-recursive show HEAD^{tree} >actual && + test_cmp expected actual +' + test_expect_success 'showing a range walks (linear)' ' cat >expect <<-EOF && commit $(git rev-parse main3) From patchwork Sat Mar 20 22:37:45 2021 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: 12152711 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.7 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id CBACCC433DB for ; Sat, 20 Mar 2021 22:39:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 9B4AB61933 for ; Sat, 20 Mar 2021 22:39:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229884AbhCTWij (ORCPT ); Sat, 20 Mar 2021 18:38:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44694 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229886AbhCTWiO (ORCPT ); Sat, 20 Mar 2021 18:38:14 -0400 Received: from mail-wr1-x434.google.com (mail-wr1-x434.google.com [IPv6:2a00:1450:4864:20::434]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 182BFC061574 for ; Sat, 20 Mar 2021 15:38:14 -0700 (PDT) Received: by mail-wr1-x434.google.com with SMTP id e18so12775834wrt.6 for ; Sat, 20 Mar 2021 15:38:14 -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=TfFpH1APGTzYe8SIfVB0K/XBicQpKKy1S9SsREAlGvc=; b=k/+2Rauxy9JQJbusqkYusXL+7uCVKBPXQmHbY30gITZ2u4NbPrAOMtaHGhDRVvC8Ly gy4CZcgiOwAV52GxcVd4MfrbhFxgCwGa3KdxK1pP5kCjPK1yHx3fW6dnzhcGsken2R/d L+WptzmijIgvqco0KLkeYtnOLf82y++hvv1YQi1SzR3QpRonYNJdezjOZ2Yu3EBriFRl egY2HPnV4/KtjD/JCvRik47+UOwQ4LkdWkuJJtFis4rCZKeOVbc3ae4tligrwHdNw5ly Znnv7z3ILVrdzNcAq0rsJ44EnQ7kvtndJz8ZRrtnbXfKU5oqZ9RWcEGWmMLg9uBhwsRu yzaQ== 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=TfFpH1APGTzYe8SIfVB0K/XBicQpKKy1S9SsREAlGvc=; b=BHRWGZQE+94pi3Wd46s3Lwdp0zH2CzMAXdDQSl6UGFH90iajQj1hUBgLXTL0IqNrkY JVxZlWP3S1s5u47v9psgvueL93SzKL5OODmkxbj3DQ6m05n2yRCY9Q9U50FlCI2P2UEf DkZbX51gVd30lwKQ0sRdZiRXFF/BiXeuV8ybdeD0W0zdzrBuoEwCSK6PWo8qv9HEhJrE jzDwYOQHkLAzeIsObzPCIkhVFH/RMxtyezosF7+ivRMedvSzP6uB/BxXhZWIDHvbpwXc Ddh+gV5k1fPsmHaBygjU/QEltwpyFreFZGHa+lwQbAzHZGeJ3j09m9UExmL1EbkWXdI5 +E7w== X-Gm-Message-State: AOAM532WLfQmtr0sCHUpIRPcw/9eNDjN+z7m+DuWZRUDTuXKCG4n9eYv pb8ChoUx1enM1L4GB8qPUzptLlWwCEUqPg== X-Google-Smtp-Source: ABdhPJzmpzQA/rB1tjtjKWHSrVEAHRJwRiyp9uvevWrl7sHxZOJsr5bH5c8C2x7yulXhzhqiX3PIhg== X-Received: by 2002:adf:fbce:: with SMTP id d14mr10697512wrs.44.1616279892562; Sat, 20 Mar 2021 15:38:12 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v2sm21472697wmj.1.2021.03.20.15.38.11 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 15:38:12 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 2/8] ls-files tests: add meaningful --with-tree tests Date: Sat, 20 Mar 2021 23:37:45 +0100 Message-Id: X-Mailer: git-send-email 2.31.0.286.gc175f2cb894 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Add tests for "ls-files --with-tree". There was effectively no coverage for any normal usage of this command, only the tests added in 54e1abce90e (Add test case for ls-files --with-tree, 2007-10-03) for an obscure bug. Signed-off-by: Ævar Arnfjörð Bjarmason --- t/t3060-ls-files-with-tree.sh | 41 +++++++++++++++++++++++++++++++++++ 1 file changed, 41 insertions(+) diff --git a/t/t3060-ls-files-with-tree.sh b/t/t3060-ls-files-with-tree.sh index 52ed665fcd2..b257c792a46 100755 --- a/t/t3060-ls-files-with-tree.sh +++ b/t/t3060-ls-files-with-tree.sh @@ -47,6 +47,12 @@ test_expect_success setup ' git add . ' +test_expect_success 'usage' ' + test_expect_code 128 git ls-files --with-tree=HEAD -u && + test_expect_code 128 git ls-files --with-tree=HEAD -s && + test_expect_code 128 git ls-files --recurse-submodules --with-tree=HEAD +' + test_expect_success 'git ls-files --with-tree should succeed from subdir' ' # We have to run from a sub-directory to trigger prune_path # Then we finally get to run our --with-tree test @@ -60,4 +66,39 @@ test_expect_success \ 'git ls-files --with-tree should add entries from named tree.' \ 'test_cmp expected output' +test_expect_success 'no duplicates in --with-tree output' ' + git ls-files --with-tree=HEAD >actual && + sort -u actual >expected && + test_cmp expected actual +' + +test_expect_success 'setup: output in a conflict' ' + test_create_repo conflict && + test_commit -C conflict BASE file && + test_commit -C conflict A file foo && + git -C conflict reset --hard BASE && + test_commit -C conflict B file bar +' + +test_expect_success 'output in a conflict' ' + test_must_fail git -C conflict merge A B && + cat >expected <<-\EOF && + file + file + file + file + EOF + git -C conflict ls-files --with-tree=HEAD >actual && + test_cmp expected actual +' + +test_expect_success 'output with removed .git/index' ' + cat >expected <<-\EOF && + file + EOF + rm conflict/.git/index && + git -C conflict ls-files --with-tree=HEAD >actual && + test_cmp expected actual +' + test_done From patchwork Sat Mar 20 22:37:46 2021 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: 12152719 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2EC98C433E1 for ; Sat, 20 Mar 2021 22:39:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 04F0061933 for ; Sat, 20 Mar 2021 22:39:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230233AbhCTWik (ORCPT ); Sat, 20 Mar 2021 18:38:40 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44700 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229903AbhCTWiP (ORCPT ); Sat, 20 Mar 2021 18:38:15 -0400 Received: from mail-wr1-x42b.google.com (mail-wr1-x42b.google.com [IPv6:2a00:1450:4864:20::42b]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D0575C061574 for ; Sat, 20 Mar 2021 15:38:14 -0700 (PDT) Received: by mail-wr1-x42b.google.com with SMTP id b9so12753179wrt.8 for ; Sat, 20 Mar 2021 15:38:14 -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=TT/xgXZlL5BvQfRSdgAIGqc2RRH7Q4ENWAoB0zNbJTY=; b=kMSmL22GguFgTHXDNIK46yjANXrDIqTJ4zVRN4MnQrcQv8v3NVU8yQBP/5YjIFMnwM FLX9fapd10mJZaTj79/cwUJrtdW6aUwUUttSM3OOy7tJsyvVQLi1uZiTuoBZElR3cF1A X+BeWc8aZ0c3m6+Ge9Y2ZzUAYqILSUxnHRICAYcx0zQGYoc8/08LBKoJWb217vemQ0TE jPlLIjYFJqGs/U4EYst3G8luyDyt62+UeH3p/BUYQo+0K4ZE4narouk7+dCRf+Hmw6vX LwB2vPnCRrc+yk3/WaSjiNWUa58olSLpaphMJK84o4XzredPcV/f2CP91DeYQ6JYK1/u bOfA== 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=TT/xgXZlL5BvQfRSdgAIGqc2RRH7Q4ENWAoB0zNbJTY=; b=RnGMSrBz4+JYbv08iPyq0g9Ledg9koWzEcw2pL1lyEsyxZ4k9XS1WuauqVSagvvF1+ Ah6LKeTniGy3YOupT0++oMYuCTncFxJB+Nknu20KM5YYHGB7EGHGD0Bgy06ppiC70Rp7 jaTtpePGvy1/pCoZpnU1AqD64V0fPv0+m4rz2vD4HS7qkyu9FnuzFEwKQkzOT5c6jD72 IvdvXzws+FBDMhWZGnxnsAyjxQnGd57DyltAoLSgVjHSY+Hs76ZEau2I227dBkZITuQ6 pYqSEWGbOXBkxh2OPjoAV0XdUBKC8vdgYtbmjig0mD5yBgp/e1eVH2pGJdNYqy3DJK+1 3HpA== X-Gm-Message-State: AOAM532Ub15E7lonwXh/cqDzag9iTPZtBy2TTfTZUtc+j3AfL5x967pS v7qp9GzYOPJAGzzVh1stFE04kw9dOfyWug== X-Google-Smtp-Source: ABdhPJx7y4TKXDiYPYi10BisEqofpWlVTFvEMn0vRXKpCSMhOShHLH2lV4teFQoBM1geBkUrKlbj0w== X-Received: by 2002:adf:9148:: with SMTP id j66mr11308924wrj.124.1616279893327; Sat, 20 Mar 2021 15:38:13 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v2sm21472697wmj.1.2021.03.20.15.38.12 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 15:38:12 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 3/8] tree.c API: move read_tree() into builtin/ls-files.c Date: Sat, 20 Mar 2021 23:37:46 +0100 Message-Id: <6291d8a1b5ebb537d3842713f22f038125f57b38.1616279653.git.avarab@gmail.com> X-Mailer: git-send-email 2.31.0.286.gc175f2cb894 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Since the read_tree() API was added around the same time as read_tree_recursive() in 94537c78a82 (Move "read_tree()" to "tree.c"[...], 2005-04-22) and b12ec373b8e ([PATCH] Teach read-tree about commit objects, 2005-04-20) things have gradually migrated over to the read_tree_recursive() version. Now builtin/ls-files.c is the last user of this code, let's move all the relevant code there. This allows for subsequent simplification of it, and an eventual move to read_tree_recursive(). Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/ls-files.c | 91 ++++++++++++++++++++++++++++++++++++++++++++++ cache.h | 2 +- tree.c | 89 --------------------------------------------- tree.h | 5 --- 4 files changed, 92 insertions(+), 95 deletions(-) diff --git a/builtin/ls-files.c b/builtin/ls-files.c index f6f9e483b27..a4458622813 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -12,6 +12,7 @@ #include "dir.h" #include "builtin.h" #include "tree.h" +#include "cache-tree.h" #include "parse-options.h" #include "resolve-undo.h" #include "string-list.h" @@ -420,6 +421,96 @@ static int get_common_prefix_len(const char *common_prefix) return common_prefix_len; } +static int read_one_entry_opt(struct index_state *istate, + const struct object_id *oid, + const char *base, int baselen, + const char *pathname, + unsigned mode, int stage, int opt) +{ + int len; + struct cache_entry *ce; + + if (S_ISDIR(mode)) + return READ_TREE_RECURSIVE; + + len = strlen(pathname); + ce = make_empty_cache_entry(istate, baselen + len); + + ce->ce_mode = create_ce_mode(mode); + ce->ce_flags = create_ce_flags(stage); + ce->ce_namelen = baselen + len; + memcpy(ce->name, base, baselen); + memcpy(ce->name + baselen, pathname, len+1); + oidcpy(&ce->oid, oid); + return add_index_entry(istate, ce, opt); +} + +static int read_one_entry(const struct object_id *oid, struct strbuf *base, + const char *pathname, unsigned mode, int stage, + void *context) +{ + struct index_state *istate = context; + return read_one_entry_opt(istate, oid, base->buf, base->len, pathname, + mode, stage, + ADD_CACHE_OK_TO_ADD|ADD_CACHE_SKIP_DFCHECK); +} + +/* + * This is used when the caller knows there is no existing entries at + * the stage that will conflict with the entry being added. + */ +static int read_one_entry_quick(const struct object_id *oid, struct strbuf *base, + const char *pathname, unsigned mode, int stage, + void *context) +{ + struct index_state *istate = context; + return read_one_entry_opt(istate, oid, base->buf, base->len, pathname, + mode, stage, + ADD_CACHE_JUST_APPEND); +} + + +static int read_tree(struct repository *r, struct tree *tree, int stage, + struct pathspec *match, struct index_state *istate) +{ + read_tree_fn_t fn = NULL; + int i, err; + + /* + * Currently the only existing callers of this function all + * call it with stage=1 and after making sure there is nothing + * at that stage; we could always use read_one_entry_quick(). + * + * But when we decide to straighten out git-read-tree not to + * use unpack_trees() in some cases, this will probably start + * to matter. + */ + + /* + * See if we have cache entry at the stage. If so, + * do it the original slow way, otherwise, append and then + * sort at the end. + */ + for (i = 0; !fn && i < istate->cache_nr; i++) { + const struct cache_entry *ce = istate->cache[i]; + if (ce_stage(ce) == stage) + fn = read_one_entry; + } + + if (!fn) + fn = read_one_entry_quick; + err = read_tree_recursive(r, tree, "", 0, stage, match, fn, istate); + if (fn == read_one_entry || err) + return err; + + /* + * Sort the cache entry -- we need to nuke the cache tree, though. + */ + cache_tree_free(&istate->cache_tree); + QSORT(istate->cache, istate->cache_nr, cmp_cache_name_compare); + return 0; +} + /* * Read the tree specified with --with-tree option * (typically, HEAD) into stage #1 and then diff --git a/cache.h b/cache.h index 6fda8091f11..c2f8a8eadf6 100644 --- a/cache.h +++ b/cache.h @@ -803,7 +803,7 @@ static inline int index_pos_to_insert_pos(uintmax_t pos) #define ADD_CACHE_OK_TO_ADD 1 /* Ok to add */ #define ADD_CACHE_OK_TO_REPLACE 2 /* Ok to replace file/directory */ #define ADD_CACHE_SKIP_DFCHECK 4 /* Ok to skip DF conflict checks */ -#define ADD_CACHE_JUST_APPEND 8 /* Append only; tree.c::read_tree() */ +#define ADD_CACHE_JUST_APPEND 8 /* Append only */ #define ADD_CACHE_NEW_ONLY 16 /* Do not replace existing ones */ #define ADD_CACHE_KEEP_CACHE_TREE 32 /* Do not invalidate cache-tree */ #define ADD_CACHE_RENORMALIZE 64 /* Pass along HASH_RENORMALIZE */ diff --git a/tree.c b/tree.c index a52479812ce..a6c12f2745a 100644 --- a/tree.c +++ b/tree.c @@ -11,54 +11,6 @@ const char *tree_type = "tree"; -static int read_one_entry_opt(struct index_state *istate, - const struct object_id *oid, - const char *base, int baselen, - const char *pathname, - unsigned mode, int stage, int opt) -{ - int len; - struct cache_entry *ce; - - if (S_ISDIR(mode)) - return READ_TREE_RECURSIVE; - - len = strlen(pathname); - ce = make_empty_cache_entry(istate, baselen + len); - - ce->ce_mode = create_ce_mode(mode); - ce->ce_flags = create_ce_flags(stage); - ce->ce_namelen = baselen + len; - memcpy(ce->name, base, baselen); - memcpy(ce->name + baselen, pathname, len+1); - oidcpy(&ce->oid, oid); - return add_index_entry(istate, ce, opt); -} - -static int read_one_entry(const struct object_id *oid, struct strbuf *base, - const char *pathname, unsigned mode, int stage, - void *context) -{ - struct index_state *istate = context; - return read_one_entry_opt(istate, oid, base->buf, base->len, pathname, - mode, stage, - ADD_CACHE_OK_TO_ADD|ADD_CACHE_SKIP_DFCHECK); -} - -/* - * This is used when the caller knows there is no existing entries at - * the stage that will conflict with the entry being added. - */ -static int read_one_entry_quick(const struct object_id *oid, struct strbuf *base, - const char *pathname, unsigned mode, int stage, - void *context) -{ - struct index_state *istate = context; - return read_one_entry_opt(istate, oid, base->buf, base->len, pathname, - mode, stage, - ADD_CACHE_JUST_APPEND); -} - static int read_tree_1(struct repository *r, struct tree *tree, struct strbuf *base, int stage, const struct pathspec *pathspec, @@ -154,47 +106,6 @@ int cmp_cache_name_compare(const void *a_, const void *b_) ce2->name, ce2->ce_namelen, ce_stage(ce2)); } -int read_tree(struct repository *r, struct tree *tree, int stage, - struct pathspec *match, struct index_state *istate) -{ - read_tree_fn_t fn = NULL; - int i, err; - - /* - * Currently the only existing callers of this function all - * call it with stage=1 and after making sure there is nothing - * at that stage; we could always use read_one_entry_quick(). - * - * But when we decide to straighten out git-read-tree not to - * use unpack_trees() in some cases, this will probably start - * to matter. - */ - - /* - * See if we have cache entry at the stage. If so, - * do it the original slow way, otherwise, append and then - * sort at the end. - */ - for (i = 0; !fn && i < istate->cache_nr; i++) { - const struct cache_entry *ce = istate->cache[i]; - if (ce_stage(ce) == stage) - fn = read_one_entry; - } - - if (!fn) - fn = read_one_entry_quick; - err = read_tree_recursive(r, tree, "", 0, stage, match, fn, istate); - if (fn == read_one_entry || err) - return err; - - /* - * Sort the cache entry -- we need to nuke the cache tree, though. - */ - cache_tree_free(&istate->cache_tree); - QSORT(istate->cache, istate->cache_nr, cmp_cache_name_compare); - return 0; -} - struct tree *lookup_tree(struct repository *r, const struct object_id *oid) { struct object *obj = lookup_object(r, oid); diff --git a/tree.h b/tree.h index 3eb0484cbf2..6b0b1dc211a 100644 --- a/tree.h +++ b/tree.h @@ -38,9 +38,4 @@ int read_tree_recursive(struct repository *r, const char *base, int baselen, int stage, const struct pathspec *pathspec, read_tree_fn_t fn, void *context); - -int read_tree(struct repository *r, struct tree *tree, - int stage, struct pathspec *pathspec, - struct index_state *istate); - #endif /* TREE_H */ From patchwork Sat Mar 20 22:37:47 2021 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: 12152717 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 19175C433E2 for ; Sat, 20 Mar 2021 22:39:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id EA13861936 for ; Sat, 20 Mar 2021 22:39:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230171AbhCTWij (ORCPT ); Sat, 20 Mar 2021 18:38:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44704 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229931AbhCTWiQ (ORCPT ); Sat, 20 Mar 2021 18:38:16 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id C5496C061574 for ; Sat, 20 Mar 2021 15:38:15 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id x13so12749109wrs.9 for ; Sat, 20 Mar 2021 15:38:15 -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=nyxaje9ys6MkoQA9Rd/2Rk3Kaj6Cp/0VCbzPfuZSTj0=; b=cxa0TXBKcA4Uh627LEUEARtQsh8CaokYhWIJWYnlGVQ7hn1b6GI3/d6L9XUP8EAbzk yb3o9HKP2tewR/P7RmHTLX/cums2GH0ynG8j90VW/gueTZdu66kd3Q1ekgJdPePVGJPH Eu5itIKi595E1bL2T2BVA/Oi1dQHxOSjOZu8jPpytSX4cIotzvcMkZwXqZ36ydJ3qhML I5WFzmNeQnoyrvR2zsttcmPXpsKS1a5zmQUCVvgMWLBD9my1Y8dJV5QoxrShngesyPwH lOw7/L1qcZnXf7bRimdqAO+izsmwoxP9ykt2zXln+q/feNUaEeu0N7BqG+IBL/mwFHEx pkfA== 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=nyxaje9ys6MkoQA9Rd/2Rk3Kaj6Cp/0VCbzPfuZSTj0=; b=ATm73HnHcf39yc8zmwfzw17/b/bWGAgInyxEwo42Sb4Tl5AfG9JlFXLOMopjJnf+dW TFjxdNklS995WPa1XkdDs9ArgW/syNVY4z1OKxundsdU0hIE2aYCCwuuw0JeuLg8TbbL r2Y4TWvAbGkigbB8zeVe/tp0IgMdblLM03w8DaBx/r7ei0Z1g0Xpd/btvk3cLWvebpBd TD8wTVH+1Z477lVg0cpPdXwEOKeVSpdDzMiNOEOcFyR9scR8uGYW9zpWlE7rQ2IiKL3z pmc26s23hCUJ2Qky3GvJoit9Aq1YUf5BXLtjZ5CXf26kKPbfom1COiQL0hXb/N0C3Mgg U0LQ== X-Gm-Message-State: AOAM533tii6B4wDFd6t3aNxE2iQcbrm4sfTzFaBy9eTAISzv1asyzte3 bB374I2Dh/OXxBCn7SZxdjpflDlLDiVdcQ== X-Google-Smtp-Source: ABdhPJwV8F1OqOrQAv1uj8juljuk4LmcV63J6Pdm9yMGWY4EIXRuKKwcml6fc8aGZLJQAL/Erwc1Vg== X-Received: by 2002:adf:ea8b:: with SMTP id s11mr11308354wrm.413.1616279894259; Sat, 20 Mar 2021 15:38:14 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v2sm21472697wmj.1.2021.03.20.15.38.13 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 15:38:13 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 4/8] ls-files: don't needlessly pass around stage variable Date: Sat, 20 Mar 2021 23:37:47 +0100 Message-Id: <466b518e915c6cf5bc1f61610a0a4ee41e875adb.1616279653.git.avarab@gmail.com> X-Mailer: git-send-email 2.31.0.286.gc175f2cb894 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Now that read_tree() has been moved to ls-files.c we can get rid of the stage != 1 case that'll never happen. Let's not use read_tree_recursive() as a pass-through to pass "stage = 1" either. For now we'll pass an unused "stage = 0" for consistency with other read_tree_recursive() callers, that argument will be removed in a follow-up commit. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/ls-files.c | 25 ++++++++----------------- 1 file changed, 8 insertions(+), 17 deletions(-) diff --git a/builtin/ls-files.c b/builtin/ls-files.c index a4458622813..3149a2769a3 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -425,7 +425,7 @@ static int read_one_entry_opt(struct index_state *istate, const struct object_id *oid, const char *base, int baselen, const char *pathname, - unsigned mode, int stage, int opt) + unsigned mode, int opt) { int len; struct cache_entry *ce; @@ -437,7 +437,7 @@ static int read_one_entry_opt(struct index_state *istate, ce = make_empty_cache_entry(istate, baselen + len); ce->ce_mode = create_ce_mode(mode); - ce->ce_flags = create_ce_flags(stage); + ce->ce_flags = create_ce_flags(1); ce->ce_namelen = baselen + len; memcpy(ce->name, base, baselen); memcpy(ce->name + baselen, pathname, len+1); @@ -451,7 +451,7 @@ static int read_one_entry(const struct object_id *oid, struct strbuf *base, { struct index_state *istate = context; return read_one_entry_opt(istate, oid, base->buf, base->len, pathname, - mode, stage, + mode, ADD_CACHE_OK_TO_ADD|ADD_CACHE_SKIP_DFCHECK); } @@ -465,26 +465,17 @@ static int read_one_entry_quick(const struct object_id *oid, struct strbuf *base { struct index_state *istate = context; return read_one_entry_opt(istate, oid, base->buf, base->len, pathname, - mode, stage, + mode, ADD_CACHE_JUST_APPEND); } -static int read_tree(struct repository *r, struct tree *tree, int stage, +static int read_tree(struct repository *r, struct tree *tree, struct pathspec *match, struct index_state *istate) { read_tree_fn_t fn = NULL; int i, err; - /* - * Currently the only existing callers of this function all - * call it with stage=1 and after making sure there is nothing - * at that stage; we could always use read_one_entry_quick(). - * - * But when we decide to straighten out git-read-tree not to - * use unpack_trees() in some cases, this will probably start - * to matter. - */ /* * See if we have cache entry at the stage. If so, @@ -493,13 +484,13 @@ static int read_tree(struct repository *r, struct tree *tree, int stage, */ for (i = 0; !fn && i < istate->cache_nr; i++) { const struct cache_entry *ce = istate->cache[i]; - if (ce_stage(ce) == stage) + if (ce_stage(ce) == 1) fn = read_one_entry; } if (!fn) fn = read_one_entry_quick; - err = read_tree_recursive(r, tree, "", 0, stage, match, fn, istate); + err = read_tree_recursive(r, tree, "", 0, 0, match, fn, istate); if (fn == read_one_entry || err) return err; @@ -549,7 +540,7 @@ void overlay_tree_on_index(struct index_state *istate, PATHSPEC_PREFER_CWD, prefix, matchbuf); } else memset(&pathspec, 0, sizeof(pathspec)); - if (read_tree(the_repository, tree, 1, &pathspec, istate)) + if (read_tree(the_repository, tree, &pathspec, istate)) die("unable to read tree entries %s", tree_name); for (i = 0; i < istate->cache_nr; i++) { From patchwork Sat Mar 20 22:37:48 2021 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: 12152721 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 37D96C433E4 for ; Sat, 20 Mar 2021 22:39:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 2406B61935 for ; Sat, 20 Mar 2021 22:39:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230237AbhCTWil (ORCPT ); Sat, 20 Mar 2021 18:38:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44710 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229933AbhCTWiQ (ORCPT ); Sat, 20 Mar 2021 18:38:16 -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 7CBF6C061574 for ; Sat, 20 Mar 2021 15:38:16 -0700 (PDT) Received: by mail-wr1-x436.google.com with SMTP id e9so12756715wrw.10 for ; Sat, 20 Mar 2021 15:38:16 -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=t0ENW6XsIibWSiV1sjw5lieszxwXektVEGr49xearz8=; b=MlOFjYu6yKFJ5JxvEEzmdq8fhBpcLMV5iqooFqam6jGZd7GaJIkTraZFLQBA1/RqK5 e8EIp2drMxISJJtqedj62xHimeTr2aL0MtV2Na0IEyz3J4TsBhEDWmLWseemRTZuEQdK 0NClYdo/yTnWTa/L4sV+sBJlAnV0Vo1B8JvyLuNV/A8Dd7wgFiwwBO6Hm/UO2HQelKhH Ra1I8HCZYRhWW/lDfDFIDJsA1/5yUucAAICCwmZySCThZvbH4XWeqHnCwIntfsfQFDKX APXWLQyfTCeUq4chVhb8YgPYz3nTJSh2a8wVA2O1XzbWR/goRJH2kTNOyjiAu3H7JdoJ zAAw== 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=t0ENW6XsIibWSiV1sjw5lieszxwXektVEGr49xearz8=; b=ltvVgefpZVThHrbN1RoXuZDyTKPE7SBBJ88OM70JeDVImuCaHCFbey5eJ72108D/5V V7/cjMB51lmgfWHMwJCJH84M3+4OAvMzdTyZbQ9asiGBHP3nJRDMvQTohNFD7xmyU8tL dar8Pt3VyWekqt3ToVmWkkyRMVSEQeygWfbGPwW7YJwCEQNj+GLrztoPAHBlA3mtUqQX yAl2PGoDI9lSf9+jv9rMGebf30S2Y1YuZNGGkDVQU9l0ePT3tunOopMGE240F9Afp5dX 2aJ+vGy6zugiHIJeaAEmldmte036QJdb+wVchp7D7JxJ7daSu3p6w7WYOiF90ToQV1Qr TpHQ== X-Gm-Message-State: AOAM531vGjan9qlO2Qrsir8TxkmQTiOV57fVHwiQf1qhO6E9OJO5eR2A FYPQuy6vqRnpavmN/xO9x5Sy6WQHosl2BQ== X-Google-Smtp-Source: ABdhPJzmud+Z8KErj9HJd26C0wlymG7bjS5icYP+83dDTDrH/fHVhBvk4KV3zeXTZXeebSyaiA5m4w== X-Received: by 2002:a5d:534e:: with SMTP id t14mr10837613wrv.202.1616279894983; Sat, 20 Mar 2021 15:38:14 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v2sm21472697wmj.1.2021.03.20.15.38.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 15:38:14 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 5/8] ls-files: refactor away read_tree() Date: Sat, 20 Mar 2021 23:37:48 +0100 Message-Id: <30c3abfe9b9af8202fb69bb67267cbbd5d09b60a.1616279653.git.avarab@gmail.com> X-Mailer: git-send-email 2.31.0.286.gc175f2cb894 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Refactor away the read_tree() function into its only user, overlay_tree_on_index(). First, change read_one_entry_opt() to use the strbuf parameter read_tree_recursive() passes down in place. This finishes up a partial refactoring started in 6a0b0b6de99 (tree.c: update read_tree_recursive callback to pass strbuf as base, 2014-11-30). Moving the rest into overlay_tree_on_index() makes this index juggling we're doing easier to read. Signed-off-by: Ævar Arnfjörð Bjarmason --- builtin/ls-files.c | 77 ++++++++++++++++++++-------------------------- 1 file changed, 34 insertions(+), 43 deletions(-) diff --git a/builtin/ls-files.c b/builtin/ls-files.c index 3149a2769a3..aa153423b80 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -423,7 +423,7 @@ static int get_common_prefix_len(const char *common_prefix) static int read_one_entry_opt(struct index_state *istate, const struct object_id *oid, - const char *base, int baselen, + struct strbuf *base, const char *pathname, unsigned mode, int opt) { @@ -434,13 +434,13 @@ static int read_one_entry_opt(struct index_state *istate, return READ_TREE_RECURSIVE; len = strlen(pathname); - ce = make_empty_cache_entry(istate, baselen + len); + ce = make_empty_cache_entry(istate, base->len + len); ce->ce_mode = create_ce_mode(mode); ce->ce_flags = create_ce_flags(1); - ce->ce_namelen = baselen + len; - memcpy(ce->name, base, baselen); - memcpy(ce->name + baselen, pathname, len+1); + ce->ce_namelen = base->len + len; + memcpy(ce->name, base->buf, base->len); + memcpy(ce->name + base->len, pathname, len+1); oidcpy(&ce->oid, oid); return add_index_entry(istate, ce, opt); } @@ -450,7 +450,7 @@ static int read_one_entry(const struct object_id *oid, struct strbuf *base, void *context) { struct index_state *istate = context; - return read_one_entry_opt(istate, oid, base->buf, base->len, pathname, + return read_one_entry_opt(istate, oid, base, pathname, mode, ADD_CACHE_OK_TO_ADD|ADD_CACHE_SKIP_DFCHECK); } @@ -464,42 +464,8 @@ static int read_one_entry_quick(const struct object_id *oid, struct strbuf *base void *context) { struct index_state *istate = context; - return read_one_entry_opt(istate, oid, base->buf, base->len, pathname, - mode, - ADD_CACHE_JUST_APPEND); -} - - -static int read_tree(struct repository *r, struct tree *tree, - struct pathspec *match, struct index_state *istate) -{ - read_tree_fn_t fn = NULL; - int i, err; - - - /* - * See if we have cache entry at the stage. If so, - * do it the original slow way, otherwise, append and then - * sort at the end. - */ - for (i = 0; !fn && i < istate->cache_nr; i++) { - const struct cache_entry *ce = istate->cache[i]; - if (ce_stage(ce) == 1) - fn = read_one_entry; - } - - if (!fn) - fn = read_one_entry_quick; - err = read_tree_recursive(r, tree, "", 0, 0, match, fn, istate); - if (fn == read_one_entry || err) - return err; - - /* - * Sort the cache entry -- we need to nuke the cache tree, though. - */ - cache_tree_free(&istate->cache_tree); - QSORT(istate->cache, istate->cache_nr, cmp_cache_name_compare); - return 0; + return read_one_entry_opt(istate, oid, base, pathname, + mode, ADD_CACHE_JUST_APPEND); } /* @@ -518,6 +484,8 @@ void overlay_tree_on_index(struct index_state *istate, struct pathspec pathspec; struct cache_entry *last_stage0 = NULL; int i; + read_tree_fn_t fn = NULL; + int err; if (get_oid(tree_name, &oid)) die("tree-ish %s not found.", tree_name); @@ -540,9 +508,32 @@ void overlay_tree_on_index(struct index_state *istate, PATHSPEC_PREFER_CWD, prefix, matchbuf); } else memset(&pathspec, 0, sizeof(pathspec)); - if (read_tree(the_repository, tree, &pathspec, istate)) + + /* + * See if we have cache entry at the stage. If so, + * do it the original slow way, otherwise, append and then + * sort at the end. + */ + for (i = 0; !fn && i < istate->cache_nr; i++) { + const struct cache_entry *ce = istate->cache[i]; + if (ce_stage(ce) == 1) + fn = read_one_entry; + } + + if (!fn) + fn = read_one_entry_quick; + err = read_tree_recursive(the_repository, tree, "", 0, 1, &pathspec, fn, istate); + if (err) die("unable to read tree entries %s", tree_name); + /* + * Sort the cache entry -- we need to nuke the cache tree, though. + */ + if (fn == read_one_entry_quick) { + cache_tree_free(&istate->cache_tree); + QSORT(istate->cache, istate->cache_nr, cmp_cache_name_compare); + } + for (i = 0; i < istate->cache_nr; i++) { struct cache_entry *ce = istate->cache[i]; switch (ce_stage(ce)) { From patchwork Sat Mar 20 22:37:49 2021 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: 12152723 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 688FAC433E3 for ; Sat, 20 Mar 2021 22:39:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3442B61936 for ; Sat, 20 Mar 2021 22:39:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230242AbhCTWio (ORCPT ); Sat, 20 Mar 2021 18:38:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44712 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229951AbhCTWiR (ORCPT ); Sat, 20 Mar 2021 18:38:17 -0400 Received: from mail-wm1-x32c.google.com (mail-wm1-x32c.google.com [IPv6:2a00:1450:4864:20::32c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 436F6C061574 for ; Sat, 20 Mar 2021 15:38:17 -0700 (PDT) Received: by mail-wm1-x32c.google.com with SMTP id g25so7392882wmh.0 for ; Sat, 20 Mar 2021 15:38:17 -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=AQ1zJhwHIJ7cjy6KjIaIobQ2Xqg8kbOZoXQJPv17mAY=; b=UvzxxzhYbcmMtXoAvVafojCPBCxVRxytZb1MWduyv4WYsezxe2rQ2LFcw0K8uVw+dH kA3XKofb+UfHr9liPTXVCQZRzzTgY+wZqYjIzEebgHcw5YUkadzMapd9SLQIGnWfXuks PbfyHeVTm4l08T7WZrE3AH5Mn3no6UfTXWc+/2T8UM7I6HsBRw/y4wj/wGNyO8v3fvWp BB7bfaozAEP/e1RkNORHi91uUDUhMFJcUR9/rZCAto6u5diqi9cFidKkUfdBy6nMqiA5 YQkDvN84EX/FLJru1WEavm16sup6XXdLaJsdu6UUKMTaJJCH3UXxPgjRjCxP3spHPFr0 lJEw== 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=AQ1zJhwHIJ7cjy6KjIaIobQ2Xqg8kbOZoXQJPv17mAY=; b=D2Y5oE9oH+4B2fmMQFBCJtw6bpc8QUOs93nqNYBWTXR1jR6zMuGQbOVXgJkHbt7PR3 J7uG8U2im5DM9welC+mp3A7bfGW/D1JWjrvXXW0qSHZka0qF1Lc1d2hVNgkpY/AJIv1r z4Z/3EpZ9YEuO+2f2tMkyaZOoIC0n2TXOCt9wie/mvghGYQi+lIpxYBPNf8T3uYnWOsP LrM2xfR8sSdQndyWdHlWcWq55ULzQN/hJACw/F2lFZweZ+8/5Lo80/UIAPxHNWegtuq5 DXhK/+phJJloYhqR5SAUuDLOWT/P9OCtGdep/S8MaNtUEjhCoFVqgtTYZKB85dbzwfue pTpg== X-Gm-Message-State: AOAM530qASF5DDg0lQIE/DZkmaPbOwQJT5FBrVpi8PZAGd+Jmro0e7MJ BULA9twXRPGciKuyPF13Wkl1uJeLy/oNgw== X-Google-Smtp-Source: ABdhPJx9kp5oXl8BUqNR1l+/txB4Nlf9r22XiKqyWUHMP6Aw787SML+yI+kkmneZVTbSpdZJrElySQ== X-Received: by 2002:a7b:c357:: with SMTP id l23mr9284208wmj.152.1616279895743; Sat, 20 Mar 2021 15:38:15 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v2sm21472697wmj.1.2021.03.20.15.38.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 15:38:15 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 6/8] archive: stop passing "stage" through read_tree_recursive() Date: Sat, 20 Mar 2021 23:37:49 +0100 Message-Id: <02c42be924953e7172639a82d8005bcb664bb8b4.1616279653.git.avarab@gmail.com> X-Mailer: git-send-email 2.31.0.286.gc175f2cb894 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org The "stage" variable being passed around in the archive code has only ever been an elaborate way to hardcode the value "0". This code was added in its original form in e4fbbfe9ecc (Add git-zip-tree, 2006-08-26), at which point a hardcoded "0" would be passed down through read_tree_recursive() to write_zip_entry(). It was then diligently added to the "struct directory" in ed22b4173bd (archive: support filtering paths with glob, 2014-09-21), but we were still not doing anything except passing it around as-is. Let's stop doing that in the code internal to archive.c, we'll still feed "0" to read_tree_recursive() itself, but won't use it. That we're providing it at all to read_tree_recursive() will be changed in a follow-up commit. Signed-off-by: Ævar Arnfjörð Bjarmason --- archive.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/archive.c b/archive.c index 5919d9e5050..4f271331543 100644 --- a/archive.c +++ b/archive.c @@ -107,7 +107,6 @@ struct directory { struct object_id oid; int baselen, len; unsigned mode; - int stage; char path[FLEX_ARRAY]; }; @@ -138,7 +137,7 @@ static int check_attr_export_subst(const struct attr_check *check) } static int write_archive_entry(const struct object_id *oid, const char *base, - int baselen, const char *filename, unsigned mode, int stage, + int baselen, const char *filename, unsigned mode, void *context) { static struct strbuf path = STRBUF_INIT; @@ -197,7 +196,7 @@ static int write_archive_entry(const struct object_id *oid, const char *base, static void queue_directory(const unsigned char *sha1, struct strbuf *base, const char *filename, - unsigned mode, int stage, struct archiver_context *c) + unsigned mode, struct archiver_context *c) { struct directory *d; size_t len = st_add4(base->len, 1, strlen(filename), 1); @@ -205,7 +204,6 @@ static void queue_directory(const unsigned char *sha1, d->up = c->bottom; d->baselen = base->len; d->mode = mode; - d->stage = stage; c->bottom = d; d->len = xsnprintf(d->path, len, "%.*s%s/", (int)base->len, base->buf, filename); hashcpy(d->oid.hash, sha1); @@ -224,7 +222,7 @@ static int write_directory(struct archiver_context *c) write_directory(c) || write_archive_entry(&d->oid, d->path, d->baselen, d->path + d->baselen, d->mode, - d->stage, c) != READ_TREE_RECURSIVE; + c) != READ_TREE_RECURSIVE; free(d); return ret ? -1 : 0; } @@ -256,14 +254,14 @@ static int queue_or_write_archive_entry(const struct object_id *oid, if (check_attr_export_ignore(check)) return 0; queue_directory(oid->hash, base, filename, - mode, stage, c); + mode, c); return READ_TREE_RECURSIVE; } if (write_directory(c)) return -1; return write_archive_entry(oid, base->buf, base->len, filename, mode, - stage, context); + context); } struct extra_file_info { @@ -377,8 +375,8 @@ struct path_exists_context { }; static int reject_entry(const struct object_id *oid, struct strbuf *base, - const char *filename, unsigned mode, - int stage, void *context) + const char *filename, unsigned mode, int stage, + void *context) { int ret = -1; struct path_exists_context *ctx = context; From patchwork Sat Mar 20 22:37:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= X-Patchwork-Id: 12152725 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE, SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 77555C433E5 for ; Sat, 20 Mar 2021 22:39:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 54FE061933 for ; Sat, 20 Mar 2021 22:39:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230240AbhCTWin (ORCPT ); Sat, 20 Mar 2021 18:38:43 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229991AbhCTWiS (ORCPT ); Sat, 20 Mar 2021 18:38:18 -0400 Received: from mail-wr1-x42e.google.com (mail-wr1-x42e.google.com [IPv6:2a00:1450:4864:20::42e]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 0096AC061762 for ; Sat, 20 Mar 2021 15:38:17 -0700 (PDT) Received: by mail-wr1-x42e.google.com with SMTP id 61so12735647wrm.12 for ; Sat, 20 Mar 2021 15:38:17 -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=zEuGGild4oP8e7gGPK2bLUkBdBnkIKme8qfGa0xYagI=; b=j5bQredPETDQUn54v1fZ/UBFNyYqv11DhV7aFY+X9PbeKUQ5H1aViMXPCFiIx1cA/V oeD2vFOnu/lDH9OcanVhaaKbre+VRKKqdOnDZ2d2hnT/48S3atKN7s6Y1NwlIdkqcmB1 0+A33TaXd+2yeEnyP/CK86XEgwDqPg9EvJhmNIZS+tdRwwdth1dHQuATDpBkrmihssEJ FdiNfJ6q47M0+5jkyTd3d2sSttIYI9kOBMyGhKt4muy9g5Xqh/8pIH2HfA4jtxLX4m1l pSfdF8TSth4g0OccoJGJNPCiOLfsKzdX0tB6RV9aEbRa/96Zvr6u2Tz6B1hvwTnIOI/d 389A== 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=zEuGGild4oP8e7gGPK2bLUkBdBnkIKme8qfGa0xYagI=; b=DoYder167iHrGqZ2TCSeO7Z7MGm3u56nIXxxI3Tsa1S7A2Yr1f+Dnm9uAH5ShKiZ1U 0kajTzetJ2SI7ufdoRDx8yCexj96FVMe268fcdMqqmDch5qFoW4bfUZA+Ou/eiW3qS+v /k+BELrgtUds5S7+7Ur5gJOgzJc247TZCw1rYZGxjk47zbcCWI20pt1FSD7oB6qhfPJo LruL8/zn4+WL2YCI5pfpzcKRaDijW3Oc4u5Zj7sgjGs4PBEb+Qt20qj6Kko6TK1z8BX9 x14GUhmFwjk0Z5ueup5AkI/7cSXMk5LFlf5oIuapcIO527ck1JS4K0jgK2RcReC8u3lM pDFQ== X-Gm-Message-State: AOAM531EZX1mOjCq60K3oQUvSYA9nx/zEBrxQwMxWdEz07/4Drl7N1Yc WNe+D0iHoFp561XqHTABzy8PJ9VwYOYlVA== X-Google-Smtp-Source: ABdhPJxMuA0CZB21MOoEjjLKhCtXcP/GmSFnmZobfWoPqsL5UgLvj+4GBU90Ta9NYqReKnShiFemgg== X-Received: by 2002:adf:b30f:: with SMTP id j15mr11204668wrd.132.1616279896572; Sat, 20 Mar 2021 15:38:16 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v2sm21472697wmj.1.2021.03.20.15.38.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 15:38:15 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 7/8] tree.h API: expose read_tree_1() as read_tree_at() Date: Sat, 20 Mar 2021 23:37:50 +0100 Message-Id: X-Mailer: git-send-email 2.31.0.286.gc175f2cb894 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Rename the static read_tree_1() function to read_tree_at(). This function works just like read_tree_recursive(), except you provide your own strbuf. This step doesn't make much sense now, but in follow-up commits I'll remove the base/baselen/stage arguments to read_tree_recursive(). At that point an anticipated in-tree user[1] for the old read_tree_recursive() couldn't provide a path to start the traversal. Let's give them a function to do so with an API that makes more sense for them, by taking a strbuf we should be able to avoid more casting and/or reallocations in the future. 1. https://lore.kernel.org/git/xmqqft106sok.fsf@gitster.g --- tree.c | 17 +++++++++-------- tree.h | 6 ++++++ 2 files changed, 15 insertions(+), 8 deletions(-) diff --git a/tree.c b/tree.c index a6c12f2745a..f67c2153054 100644 --- a/tree.c +++ b/tree.c @@ -11,10 +11,11 @@ const char *tree_type = "tree"; -static int read_tree_1(struct repository *r, - struct tree *tree, struct strbuf *base, - int stage, const struct pathspec *pathspec, - read_tree_fn_t fn, void *context) +int read_tree_at(struct repository *r, + struct tree *tree, struct strbuf *base, + int stage, + const struct pathspec *pathspec, + read_tree_fn_t fn, void *context) { struct tree_desc desc; struct name_entry entry; @@ -71,9 +72,9 @@ static int read_tree_1(struct repository *r, len = tree_entry_len(&entry); strbuf_add(base, entry.path, len); strbuf_addch(base, '/'); - retval = read_tree_1(r, lookup_tree(r, &oid), - base, stage, pathspec, - fn, context); + retval = read_tree_at(r, lookup_tree(r, &oid), + base, stage, pathspec, + fn, context); strbuf_setlen(base, oldlen); if (retval) return -1; @@ -91,7 +92,7 @@ int read_tree_recursive(struct repository *r, int ret; strbuf_add(&sb, base, baselen); - ret = read_tree_1(r, tree, &sb, stage, pathspec, fn, context); + ret = read_tree_at(r, tree, &sb, stage, pathspec, fn, context); strbuf_release(&sb); return ret; } diff --git a/tree.h b/tree.h index 6b0b1dc211a..123fc41efe6 100644 --- a/tree.h +++ b/tree.h @@ -33,6 +33,12 @@ int cmp_cache_name_compare(const void *a_, const void *b_); #define READ_TREE_RECURSIVE 1 typedef int (*read_tree_fn_t)(const struct object_id *, struct strbuf *, const char *, unsigned int, int, void *); +int read_tree_at(struct repository *r, + struct tree *tree, struct strbuf *base, + int stage, + const struct pathspec *pathspec, + read_tree_fn_t fn, void *context); + int read_tree_recursive(struct repository *r, struct tree *tree, const char *base, int baselen, From patchwork Sat Mar 20 22:37:51 2021 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: 12152727 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-15.8 required=3.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,FREEMAIL_FORGED_FROMDOMAIN,FREEMAIL_FROM, HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER,INCLUDES_PATCH, MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 894F3C433E6 for ; Sat, 20 Mar 2021 22:39:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 6393761935 for ; Sat, 20 Mar 2021 22:39:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230245AbhCTWip (ORCPT ); Sat, 20 Mar 2021 18:38:45 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44724 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230002AbhCTWiT (ORCPT ); Sat, 20 Mar 2021 18:38:19 -0400 Received: from mail-wr1-x433.google.com (mail-wr1-x433.google.com [IPv6:2a00:1450:4864:20::433]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DA949C061574 for ; Sat, 20 Mar 2021 15:38:18 -0700 (PDT) Received: by mail-wr1-x433.google.com with SMTP id b9so12753242wrt.8 for ; Sat, 20 Mar 2021 15:38:18 -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=HeKTJqhcuP+JV2yLp7cnLHTvUvV3LC//BWeGT4inAI0=; b=mOAzvpS5BY635WCKYDrIVJ5xPCg/CeaM8UuMlLPpLKTkXrofDIsHAiQ8ri00WbqVnW lZM84qP5/530B2Du76I/cV20zvnDKUQ9uZpzjAvyx8D2dSJw7zVre4zpw8rMqVL3kJtV GLk2tG8MkEOY+Q13yP2q8Pbv0+ivhK/rcwoteWYoONASN6i8uOQRTuUHvZ9Y4vjVnsDN E8vDgk/hKQxZeTs1hqnGMicBLCwQB5fidK3GIItNGceBr3KnkTmLf+IJyJfDXs/Zme4y R8NAa7+jW+BPqbebY2pw1p7xdsM0wbvcEkZ9F3DqWIhIsEem9c1kLdPXfjzb734WephU I1fw== 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=HeKTJqhcuP+JV2yLp7cnLHTvUvV3LC//BWeGT4inAI0=; b=Qe7d86aFfyPY2s8gwVDoU7gol2+VaLXbZrp0wY1qFKrDKp4eO3+bQAn6HcCIPMhDei NfQ6sXIaNrb3Ylx0UPXHJVJRWAq6QXY0062KfXjbHBcuq/2aCdqHAgAO6zsntfFic5Mc EUApfH9UsVH/LRCMNvCNQKC18j7A0JH0O3isYb5R/R215SV3pFcy6ZwguzcnIBTBXjWw LCKQZQhmOkO4q5wbIjNL0J0gZYGR0Nk6zB9vTqgDcwqEK4jcvBBeJlpnrBt76TfyYiii poGBWMurCUraZ1aYR4MBwOfq/SJrboRzDEu7THNhkSERjkPE8NgyixPNRYVIt1CjhruL UkRg== X-Gm-Message-State: AOAM532HJRDLyK71Ry1bTTDv4FjN08+Uu5lPrC51xudumhCFmg253hGg XTrDwJpUlziWmxg34Pz5LP7GZSH5osfe0A== X-Google-Smtp-Source: ABdhPJwkw359LixTbbqZ+piwx+nXJvErojQMQqPAWdMIV0EQZewrJo7KjdGdBF4fmLQhDDD1FzOQrQ== X-Received: by 2002:a05:6000:1363:: with SMTP id q3mr10987570wrz.74.1616279897288; Sat, 20 Mar 2021 15:38:17 -0700 (PDT) Received: from vm.nix.is (vm.nix.is. [2a01:4f8:120:2468::2]) by smtp.gmail.com with ESMTPSA id v2sm21472697wmj.1.2021.03.20.15.38.16 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Sat, 20 Mar 2021 15:38:16 -0700 (PDT) From: =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFybWFzb24=?= To: git@vger.kernel.org Cc: Junio C Hamano , Elijah Newren , Derrick Stolee , =?utf-8?b?w4Z2YXIgQXJuZmrDtnLDsCBCamFy?= =?utf-8?b?bWFzb24=?= Subject: [PATCH v5 8/8] tree.h API: simplify read_tree_recursive() signature Date: Sat, 20 Mar 2021 23:37:51 +0100 Message-Id: X-Mailer: git-send-email 2.31.0.286.gc175f2cb894 In-Reply-To: References: MIME-Version: 1.0 Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org Simplify the signature of read_tree_recursive() to omit the "base", "baselen" and "stage" arguments. No callers of it use these parameters for anything anymore. The last function to call read_tree_recursive() with a non-"" path was read_tree_recursive() itself, but that was changed in ffd31f661d5 (Reimplement read_tree_recursive() using tree_entry_interesting(), 2011-03-25). The last user of the "stage" parameter went away in the last commit, and even that use was mere boilerplate. So let's remove those and rename the read_tree_recursive() function to just read_tree(). We had another read_tree() function that I've refactored away in preceding commits, since all in-tree users read trees recursively with a callback we can change the name to signify that this is the norm. Signed-off-by: Ævar Arnfjörð Bjarmason --- archive.c | 18 +++++++++--------- builtin/checkout.c | 8 ++++---- builtin/log.c | 8 ++++---- builtin/ls-files.c | 6 +++--- builtin/ls-tree.c | 6 +++--- merge-recursive.c | 6 +++--- tree.c | 19 +++++++------------ tree.h | 13 ++++++------- 8 files changed, 39 insertions(+), 45 deletions(-) diff --git a/archive.c b/archive.c index 4f271331543..4921dc8a69f 100644 --- a/archive.c +++ b/archive.c @@ -229,7 +229,7 @@ static int write_directory(struct archiver_context *c) static int queue_or_write_archive_entry(const struct object_id *oid, struct strbuf *base, const char *filename, - unsigned mode, int stage, void *context) + unsigned mode, void *context) { struct archiver_context *c = context; @@ -314,10 +314,10 @@ int write_archive_entries(struct archiver_args *args, git_attr_set_direction(GIT_ATTR_INDEX); } - err = read_tree_recursive(args->repo, args->tree, "", - 0, 0, &args->pathspec, - queue_or_write_archive_entry, - &context); + err = read_tree(args->repo, args->tree, + &args->pathspec, + queue_or_write_archive_entry, + &context); if (err == READ_TREE_RECURSIVE) err = 0; while (context.bottom) { @@ -375,7 +375,7 @@ struct path_exists_context { }; static int reject_entry(const struct object_id *oid, struct strbuf *base, - const char *filename, unsigned mode, int stage, + const char *filename, unsigned mode, void *context) { int ret = -1; @@ -403,9 +403,9 @@ static int path_exists(struct archiver_args *args, const char *path) ctx.args = args; parse_pathspec(&ctx.pathspec, 0, 0, "", paths); ctx.pathspec.recursive = 1; - ret = read_tree_recursive(args->repo, args->tree, "", - 0, 0, &ctx.pathspec, - reject_entry, &ctx); + ret = read_tree(args->repo, args->tree, + &ctx.pathspec, + reject_entry, &ctx); clear_pathspec(&ctx.pathspec); return ret != 0; } diff --git a/builtin/checkout.c b/builtin/checkout.c index 2d6550bc3c8..0e663905200 100644 --- a/builtin/checkout.c +++ b/builtin/checkout.c @@ -114,7 +114,7 @@ static int post_checkout_hook(struct commit *old_commit, struct commit *new_comm } static int update_some(const struct object_id *oid, struct strbuf *base, - const char *pathname, unsigned mode, int stage, void *context) + const char *pathname, unsigned mode, void *context) { int len; struct cache_entry *ce; @@ -155,8 +155,8 @@ static int update_some(const struct object_id *oid, struct strbuf *base, static int read_tree_some(struct tree *tree, const struct pathspec *pathspec) { - read_tree_recursive(the_repository, tree, "", 0, 0, - pathspec, update_some, NULL); + read_tree(the_repository, tree, + pathspec, update_some, NULL); /* update the index with the given tree's info * for all args, expanding wildcards, and exit @@ -322,7 +322,7 @@ static void mark_ce_for_checkout_overlay(struct cache_entry *ce, * If it comes from the tree-ish, we already know it * matches the pathspec and could just stamp * CE_MATCHED to it from update_some(). But we still - * need ps_matched and read_tree_recursive (and + * need ps_matched and read_tree (and * eventually tree_entry_interesting) cannot fill * ps_matched yet. Once it can, we can avoid calling * match_pathspec() for _all_ entries when diff --git a/builtin/log.c b/builtin/log.c index f67b67d80ed..980de590638 100644 --- a/builtin/log.c +++ b/builtin/log.c @@ -599,7 +599,7 @@ static int show_tag_object(const struct object_id *oid, struct rev_info *rev) static int show_tree_object(const struct object_id *oid, struct strbuf *base, - const char *pathname, unsigned mode, int stage, void *context) + const char *pathname, unsigned mode, void *context) { FILE *file = context; fprintf(file, "%s%s\n", pathname, S_ISDIR(mode) ? "/" : ""); @@ -681,9 +681,9 @@ int cmd_show(int argc, const char **argv, const char *prefix) diff_get_color_opt(&rev.diffopt, DIFF_COMMIT), name, diff_get_color_opt(&rev.diffopt, DIFF_RESET)); - read_tree_recursive(the_repository, (struct tree *)o, "", - 0, 0, &match_all, show_tree_object, - rev.diffopt.file); + read_tree(the_repository, (struct tree *)o, + &match_all, show_tree_object, + rev.diffopt.file); rev.shown_one = 1; break; case OBJ_COMMIT: diff --git a/builtin/ls-files.c b/builtin/ls-files.c index aa153423b80..60a2913a01e 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -446,7 +446,7 @@ static int read_one_entry_opt(struct index_state *istate, } static int read_one_entry(const struct object_id *oid, struct strbuf *base, - const char *pathname, unsigned mode, int stage, + const char *pathname, unsigned mode, void *context) { struct index_state *istate = context; @@ -460,7 +460,7 @@ static int read_one_entry(const struct object_id *oid, struct strbuf *base, * the stage that will conflict with the entry being added. */ static int read_one_entry_quick(const struct object_id *oid, struct strbuf *base, - const char *pathname, unsigned mode, int stage, + const char *pathname, unsigned mode, void *context) { struct index_state *istate = context; @@ -522,7 +522,7 @@ void overlay_tree_on_index(struct index_state *istate, if (!fn) fn = read_one_entry_quick; - err = read_tree_recursive(the_repository, tree, "", 0, 1, &pathspec, fn, istate); + err = read_tree(the_repository, tree, &pathspec, fn, istate); if (err) die("unable to read tree entries %s", tree_name); diff --git a/builtin/ls-tree.c b/builtin/ls-tree.c index 7cad3f24ebd..3a442631c71 100644 --- a/builtin/ls-tree.c +++ b/builtin/ls-tree.c @@ -62,7 +62,7 @@ static int show_recursive(const char *base, int baselen, const char *pathname) } static int show_tree(const struct object_id *oid, struct strbuf *base, - const char *pathname, unsigned mode, int stage, void *context) + const char *pathname, unsigned mode, void *context) { int retval = 0; int baselen; @@ -185,6 +185,6 @@ int cmd_ls_tree(int argc, const char **argv, const char *prefix) tree = parse_tree_indirect(&oid); if (!tree) die("not a tree object"); - return !!read_tree_recursive(the_repository, tree, "", 0, 0, - &pathspec, show_tree, NULL); + return !!read_tree(the_repository, tree, + &pathspec, show_tree, NULL); } diff --git a/merge-recursive.c b/merge-recursive.c index b69e694d986..ed31f9496cb 100644 --- a/merge-recursive.c +++ b/merge-recursive.c @@ -453,7 +453,7 @@ static void unpack_trees_finish(struct merge_options *opt) static int save_files_dirs(const struct object_id *oid, struct strbuf *base, const char *path, - unsigned int mode, int stage, void *context) + unsigned int mode, void *context) { struct path_hashmap_entry *entry; int baselen = base->len; @@ -473,8 +473,8 @@ static void get_files_dirs(struct merge_options *opt, struct tree *tree) { struct pathspec match_all; memset(&match_all, 0, sizeof(match_all)); - read_tree_recursive(opt->repo, tree, "", 0, 0, - &match_all, save_files_dirs, opt); + read_tree(opt->repo, tree, + &match_all, save_files_dirs, opt); } static int get_tree_entry_if_blob(struct repository *r, diff --git a/tree.c b/tree.c index f67c2153054..410e3b477e5 100644 --- a/tree.c +++ b/tree.c @@ -13,7 +13,6 @@ const char *tree_type = "tree"; int read_tree_at(struct repository *r, struct tree *tree, struct strbuf *base, - int stage, const struct pathspec *pathspec, read_tree_fn_t fn, void *context) { @@ -39,7 +38,7 @@ int read_tree_at(struct repository *r, } switch (fn(&entry.oid, base, - entry.path, entry.mode, stage, context)) { + entry.path, entry.mode, context)) { case 0: continue; case READ_TREE_RECURSIVE: @@ -73,7 +72,7 @@ int read_tree_at(struct repository *r, strbuf_add(base, entry.path, len); strbuf_addch(base, '/'); retval = read_tree_at(r, lookup_tree(r, &oid), - base, stage, pathspec, + base, pathspec, fn, context); strbuf_setlen(base, oldlen); if (retval) @@ -82,17 +81,13 @@ int read_tree_at(struct repository *r, return 0; } -int read_tree_recursive(struct repository *r, - struct tree *tree, - const char *base, int baselen, - int stage, const struct pathspec *pathspec, - read_tree_fn_t fn, void *context) +int read_tree(struct repository *r, + struct tree *tree, + const struct pathspec *pathspec, + read_tree_fn_t fn, void *context) { struct strbuf sb = STRBUF_INIT; - int ret; - - strbuf_add(&sb, base, baselen); - ret = read_tree_at(r, tree, &sb, stage, pathspec, fn, context); + int ret = read_tree_at(r, tree, &sb, pathspec, fn, context); strbuf_release(&sb); return ret; } diff --git a/tree.h b/tree.h index 123fc41efe6..6efff003e21 100644 --- a/tree.h +++ b/tree.h @@ -31,17 +31,16 @@ struct tree *parse_tree_indirect(const struct object_id *oid); int cmp_cache_name_compare(const void *a_, const void *b_); #define READ_TREE_RECURSIVE 1 -typedef int (*read_tree_fn_t)(const struct object_id *, struct strbuf *, const char *, unsigned int, int, void *); +typedef int (*read_tree_fn_t)(const struct object_id *, struct strbuf *, const char *, unsigned int, void *); int read_tree_at(struct repository *r, struct tree *tree, struct strbuf *base, - int stage, const struct pathspec *pathspec, read_tree_fn_t fn, void *context); -int read_tree_recursive(struct repository *r, - struct tree *tree, - const char *base, int baselen, - int stage, const struct pathspec *pathspec, - read_tree_fn_t fn, void *context); +int read_tree(struct repository *r, + struct tree *tree, + const struct pathspec *pathspec, + read_tree_fn_t fn, void *context); + #endif /* TREE_H */