From patchwork Fri May 7 04:04:56 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12243939 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=-12.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,URIBL_BLOCKED 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 CE45AC433ED for ; Fri, 7 May 2021 04:05:07 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 982E16112F for ; Fri, 7 May 2021 04:05:07 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229666AbhEGEGF (ORCPT ); Fri, 7 May 2021 00:06:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58922 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229463AbhEGEGC (ORCPT ); Fri, 7 May 2021 00:06:02 -0400 Received: from mail-wr1-x429.google.com (mail-wr1-x429.google.com [IPv6:2a00:1450:4864:20::429]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 687A5C061761 for ; Thu, 6 May 2021 21:05:03 -0700 (PDT) Received: by mail-wr1-x429.google.com with SMTP id v12so7681015wrq.6 for ; Thu, 06 May 2021 21:05:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=v5loYWvSZoqGvlhAuSo5IwrvfMT/3yTkKMM6xGuLRpM=; b=gXP0fZ5Z2gSNnx7F5XOQiO3EUGz/wLQMvtvmEBea9NBDKBL7rOJakXYMjD1M1ftTmD D1kS1cBSENi2GaT/AwetMsWkDKqWG8+6EcWDdEO6Dedk9fUay0UL/d3YWU9E3EoW6VAq Cg1k6FJWtfedrjGNvCw3MoVFPX8z/pBq2HUBgwWL3LFGPu3bRuMEWdurKuVdJG0ii+WJ ikM3b18nD/oIwVaBpPcrzjzLHtDhDi/bG0gOluVNS2VC/xGq47svlAyO8DQm7FeOi9sx yuF33zTmRODU1AmYlqek2AEzfOrNSRfwpsJg+q6DRkY64+wXsb9qfL2+dFmAHO21/XGb PM8Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=v5loYWvSZoqGvlhAuSo5IwrvfMT/3yTkKMM6xGuLRpM=; b=lm+b3pU2rJV2Al19TJj7FoYTfX1tER1LgqNKVMXWqiNGSzq/rJ96Q4pw3+tmgS9t10 A07bmMk3DFCTCIo7LXtJ0B06yoOs7rcQe8IFQlJNw6M51Uu90jwKjJmNaQKTYSRjQWD6 hAPiQxrNDX2x8A8dBqXP5UiHyqloRZS+Hicx44oUegdFOCuo+2zLRkP4MQPSchCeSvrp ndWkH4VMhDUpIKWoX0KPSm6Rxc8R5toJy4PXoINcdJRdLLQ7BNejVf62edOdVQZrDnsi 5hZm/ezJLZ11PEI7VFw16KWyMotENa01LQe1JB4/gq1rfYetGVffQpmKB5ZWtHY7CgSj wwsw== X-Gm-Message-State: AOAM530Fq8rtWf/a9mMCm41nmTIVYEwTk3vtf51/kDeJBjXSeF9WbhrX PVdmkmzCUPiSOY74Z/i9WIm1S5itOWM= X-Google-Smtp-Source: ABdhPJxbpgeaSVt+BZADE6I+mSfmqLGkvA5kaMrH59IGTfCm/TDDYITQs2BUY9mewnDYpxlaEGcckQ== X-Received: by 2002:adf:fc42:: with SMTP id e2mr9680453wrs.302.1620360302236; Thu, 06 May 2021 21:05:02 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id b20sm6902657wmj.3.2021.05.06.21.05.01 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 May 2021 21:05:01 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Fri, 07 May 2021 04:04:56 +0000 Subject: [PATCH 1/5] t7300: add testcase showing unnecessary traversal into ignored directory Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren PNPM is apparently creating deeply nested (but ignored) directory structures; traversing them is costly performance-wise, unnecessary, and in some cases is even throwing warnings/errors because the paths are too long to handle on various platforms. Add a testcase that demonstrates this problem. Initial-test-by: Jason Gore Helped-by: brian m. carlson Signed-off-by: Elijah Newren --- t/t7300-clean.sh | 40 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh index a74816ca8b46..5f1dc397c11e 100755 --- a/t/t7300-clean.sh +++ b/t/t7300-clean.sh @@ -746,4 +746,44 @@ test_expect_success 'clean untracked paths by pathspec' ' test_must_be_empty actual ' +test_expect_failure 'avoid traversing into ignored directories' ' + test_when_finished rm -f output error && + test_create_repo avoid-traversing-deep-hierarchy && + ( + cd avoid-traversing-deep-hierarchy && + + >directory-random-file.txt && + # Put this file under directory400/directory399/.../directory1/ + depth=400 && + for x in $(test_seq 1 $depth); do + mkdir "tmpdirectory$x" && + mv directory* "tmpdirectory$x" && + mv "tmpdirectory$x" "directory$x" + done && + + git clean -ffdxn -e directory$depth >../output 2>../error && + + test_must_be_empty ../output && + # We especially do not want things like + # "warning: could not open directory " + # appearing in the error output. It is true that directories + # that are too long cannot be opened, but we should not be + # recursing into those directories anyway since the very first + # level is ignored. + test_must_be_empty ../error && + + # alpine-linux-musl fails to "rm -rf" a directory with such + # a deeply nested hierarchy. Help it out by deleting the + # leading directories ourselves. Super slow, but, what else + # can we do? Without this, we will hit a + # error: Tests passed but test cleanup failed; aborting + # so do this ugly manual cleanup... + while test ! -f directory-random-file.txt; do + name=$(ls -d directory*) && + mv $name/* . && + rmdir $name + done + ) +' + test_done From patchwork Fri May 7 04:04:57 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12243941 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=-12.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,URIBL_BLOCKED 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 530C8C43461 for ; Fri, 7 May 2021 04:05:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3044D613E3 for ; Fri, 7 May 2021 04:05:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229758AbhEGEGH (ORCPT ); Fri, 7 May 2021 00:06:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58924 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229652AbhEGEGD (ORCPT ); Fri, 7 May 2021 00:06:03 -0400 Received: from mail-wr1-x432.google.com (mail-wr1-x432.google.com [IPv6:2a00:1450:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id F1154C061763 for ; Thu, 6 May 2021 21:05:03 -0700 (PDT) Received: by mail-wr1-x432.google.com with SMTP id s8so7681903wrw.10 for ; Thu, 06 May 2021 21:05:03 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=/8i2rA0Y8K4hQ70lLLGfR6UfKhpltRjIYWd7MBEBp4s=; b=Jy6rWGW8k7K9NAXUhxmXUjiRuuzXvRg9/O/SenRyFJ1ScqLn1LgeR4VDcD18u8gKwm Y8qINneiud2lR1PUtGIz/NcFSIMyspCiDuakZjucpDI4ru80Z2uULehE2NNku7F4lihY 6Ojhf4aO/3KEXeG8dYvXf7AjSJH7cGDibjv8uaMyAPf59w+GPHhr1Pmt0gJlKHNUSMsP 2DSSjYa0O0AFNicZY+yog85fcynGSdhJDV1Fcidq/e/Hlhgy2NoHLlrTkGdG1FyOKeJY /Xaextzhps3SQDkM21/aK7DOZSf/5oKfeZG68ROvpvgeIjOHyCDkvN088Q/dxWsF7vk9 2jhA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=/8i2rA0Y8K4hQ70lLLGfR6UfKhpltRjIYWd7MBEBp4s=; b=PWjR9lu2hyxYneg1h4nrCXxypyepfWqsoSYHV/5xPgKFW2uHw5tQJNxTO8wZYbawah Md8qg2Qu6YkO5Fsh0kskycihbOu6nHnaQz048UA9BLygJXL0sm7fSVWoTE3Ubd0TQlPM IGt98BVngQEjxMI6NdD0w1cB5K+f0n50d4GxeDqJ/269f8bVMbGAHF2+1yzLRENyMso/ TR0UJWHIhtKQnLBER4HJ2TFsFVq+cJHUMvb25eVoInYWlfZc79cZu5ET5fbSuXV6S3FX /3VUqsOL5nrcgUFBBS+w6gXG5Lf7G2BOZfVyuc52Pypx9EDqwTNYDPf9OV2PDOSVGkhL eY0g== X-Gm-Message-State: AOAM533Y37ZkVVKn+1GIJBFQnOCPtt7rKXDoETDV5lEa77Er8Z50jQdf UCWgY/20wsb6lk+5lprfSvtIXEGYWqE= X-Google-Smtp-Source: ABdhPJzz7quWZ6BkhEIL+f2NznzfSQt2dfTijevSYbMv0TGnaVnsQ+Hf7AbANG7IEMaGt0G8qTWnDw== X-Received: by 2002:adf:e811:: with SMTP id o17mr9563023wrm.71.1620360302731; Thu, 06 May 2021 21:05:02 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id e18sm7574630wrc.85.2021.05.06.21.05.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 May 2021 21:05:02 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Fri, 07 May 2021 04:04:57 +0000 Subject: [PATCH 2/5] t3001, t7300: add testcase showcasing missed directory traversal Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren In the last commit, we added a testcase showing that the directory traversal machinery sometimes traverses into directories unnecessarily. Here we show that there are cases where it does the opposite: it does not traverse into directories, despite those directories having important files that need to be flagged. Add a testcase showing that `git ls-files -o -i --directory` can omit some of the files it should be listing, and another showing that `git clean -fX` can fail to clean out some of the expected files. Signed-off-by: Elijah Newren --- t/t3001-ls-files-others-exclude.sh | 5 +++++ t/t7300-clean.sh | 19 +++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/t/t3001-ls-files-others-exclude.sh b/t/t3001-ls-files-others-exclude.sh index 1ec7cb57c7a8..ac05d1a17931 100755 --- a/t/t3001-ls-files-others-exclude.sh +++ b/t/t3001-ls-files-others-exclude.sh @@ -292,6 +292,11 @@ EOF test_cmp expect actual ' +test_expect_failure 'ls-files with "**" patterns and --directory' ' + # Expectation same as previous test + git ls-files --directory -o -i --exclude "**/a.1" >actual && + test_cmp expect actual +' test_expect_success 'ls-files with "**" patterns and no slashes' ' git ls-files -o -i --exclude "one**a.1" >actual && diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh index 5f1dc397c11e..337f9af1d74b 100755 --- a/t/t7300-clean.sh +++ b/t/t7300-clean.sh @@ -786,4 +786,23 @@ test_expect_failure 'avoid traversing into ignored directories' ' ) ' +test_expect_failure 'traverse into directories that may have ignored entries' ' + test_when_finished rm -f output && + test_create_repo need-to-traverse-into-hierarchy && + ( + cd need-to-traverse-into-hierarchy && + mkdir -p modules/foobar/src/generated && + > modules/foobar/src/generated/code.c && + > modules/foobar/Makefile && + echo "/modules/**/src/generated/" >.gitignore && + + git clean -fX modules/foobar >../output && + + grep Removing ../output && + + test_path_is_missing modules/foobar/src/generated/code.c && + test_path_is_file modules/foobar/Makefile + ) +' + test_done From patchwork Fri May 7 04:04:58 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12243943 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=-12.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,URIBL_BLOCKED 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 CF80FC43462 for ; Fri, 7 May 2021 04:05:09 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id AA9F96112F for ; Fri, 7 May 2021 04:05:09 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229791AbhEGEGH (ORCPT ); Fri, 7 May 2021 00:06:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58926 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229664AbhEGEGE (ORCPT ); Fri, 7 May 2021 00:06:04 -0400 Received: from mail-wr1-x42d.google.com (mail-wr1-x42d.google.com [IPv6:2a00:1450:4864:20::42d]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 93D58C061761 for ; Thu, 6 May 2021 21:05:04 -0700 (PDT) Received: by mail-wr1-x42d.google.com with SMTP id m9so7702193wrx.3 for ; Thu, 06 May 2021 21:05:04 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=7bCsIv3hR/TUhuX0mUmDqE/q3hvqQQCp2a8FtFwo2KE=; b=bPqM/O4ceeO9ueCcGe/3L6X80mRbkP3rejdtCXqqhlcMWvy/60pnv8zs4b3BYzTZeC bYO3665q1/V0B8BMAdtgNrcNLsRd/ftxmvhB+GAEVRhug2OyqZfhyUHIxRUzZpyt9ocK b4PXAieCZdawO+0dUXkeziP8DuQ39u5d1Gr+dV0skWM7UfOWuNZP5EmaJvpjEIn1v8Pk vn/Y3AOP45pVTBmPXyxG4+GEEHEJOQbwoIRV3JPhUTf6vipH9VKsIy945a9CFyHF5fuh S0Fey91IOLm9CFiN3xhNUXAYld+oBMt9KuaKKzgWg1rJwY5WQ0o9a+t3BV6+jfE6hPS/ mwSQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=7bCsIv3hR/TUhuX0mUmDqE/q3hvqQQCp2a8FtFwo2KE=; b=BqndklXNYyFLbxg7TAq4Zj52SQhVlwqrxK3r7uLTwlF4o0Oa/z3GhUSpgO98JEkd6e PFqTXzGoCNvdyBaju/+bUg+SMjP1oNYb8B9ChkOCAMuPYYacEC4QgQg0CyoNImxBkK+a CyS3I/cYfNFYjKKoCOWnUGkz02EMpq0YBHnK7ou6Cm0+EyosGb5Dp1g/6q69NyT1CZ6o 07dZl6X/4gqjLzH1okUZXSd+hrorUrhMgs7eEdhcJFOsIGZPjx0GPU+RnnGeqFfY396y swDr67cEm2mwmvDFGSHmZPIlGB5XAqVb52i0St6oU/8RXUtQAxo2Ipw+e5+27WRt4ldj oPCQ== X-Gm-Message-State: AOAM531ped99FYf0xxC6Qq5RHsyTg84WmH66fF7UFrz3jbj1MlCD8XS5 ET4bCXmv7bYrD/KKgp3Ypud2CmIauvY= X-Google-Smtp-Source: ABdhPJwxAgc5fzoobib8IUjKM5OBq967/qrEOBo51t/nuqKs068raswSoBdUE12QJZyZ52xndjkTow== X-Received: by 2002:a5d:525c:: with SMTP id k28mr9400990wrc.158.1620360303309; Thu, 06 May 2021 21:05:03 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id c14sm7260728wrt.77.2021.05.06.21.05.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 May 2021 21:05:03 -0700 (PDT) Message-Id: <3c3f6111da13c885b341053a477d857bd897708f.1620360300.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 07 May 2021 04:04:58 +0000 Subject: [PATCH 3/5] dir: avoid unnecessary traversal into ignored directory Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren The show_other_directories case in treat_directory() tried to handle both excludes and untracked files with the same logic, and mishandled both the excludes and the untracked files in the process, in different ways. Split that logic apart, and then focus on the logic for the excludes; a subsequent commit will address the logic for untracked files. For show_other_directories, an excluded directory means that every path underneath that directory will also be excluded. Given that the calling code requested to just show directories when everything under a directory had the same state (that's what the "DIR_SHOW_OTHER_DIRECTORIES" flag means), we generally do not need to traverse into such directories and can just immediately mark them as ignored (i.e. as path_excluded). The only reason we cannot just immediately return path_excluded is the DIR_HIDE_EMPTY_DIRECTORIES flag and the possibility that the ignored directory is an empty directory. The code previously treated DIR_SHOW_IGNORED_TOO in most cases as an exception as well, which was wrong. It can sometimes reduce the number of cases where we need to recurse (namely if DIR_SHOW_IGNORED_TOO_MODE_MATCHING is also set), but should not be able to increase the number of cases where we need to recurse. Fix the logic accordingly. Some sidenotes about possible confusion with dir.c: * "ignored" often refers to an untracked ignore", i.e. a file which is not tracked which matches one of the ignore/exclusion rules. But you can also have a "tracked ignore", a tracked file that happens to match one of the ignore/exclusion rules and which dir.c has to worry about since "git ls-files -c -i" is supposed to list them. * The dir code often uses "ignored" and "excluded" interchangeably, which you need to keep in mind while reading the code. Sadly, though, it can get very confusing since ignore rules can have exclusions, as in the last of the following .gitignore rules: .gitignore *~ *.log !settings.log In the last entry above, (pathspec->items[3].magic & PATHSPEC_EXCLUDE) will be true due the the '!' negating the rule. Someone might refer to this as "excluded". That means the file 'settings.log' will not match, and thus not be ignored. So we won't return path_excluded for it. So it's an exclude rule that prevents the file from being an exclude. The non-excluded rules are the ones that result in files being excludes. Great fun, eh? Sometimes it feels like dir.c needs its own glossary with its many definitions, including the multiply-defined terms. Reported-by: Jason Gore Signed-off-by: Elijah Newren --- dir.c | 44 +++++++++++++++++++++++++++++--------------- t/t7300-clean.sh | 2 +- 2 files changed, 30 insertions(+), 16 deletions(-) diff --git a/dir.c b/dir.c index 3474e67e8f3c..4b183749843e 100644 --- a/dir.c +++ b/dir.c @@ -1844,6 +1844,7 @@ static enum path_treatment treat_directory(struct dir_struct *dir, } /* This is the "show_other_directories" case */ + assert(dir->flags & DIR_SHOW_OTHER_DIRECTORIES); /* * If we have a pathspec which could match something _below_ this @@ -1854,27 +1855,40 @@ static enum path_treatment treat_directory(struct dir_struct *dir, if (matches_how == MATCHED_RECURSIVELY_LEADING_PATHSPEC) return path_recurse; + /* Special cases for where this directory is excluded/ignored */ + if (excluded) { + /* + * In the show_other_directories case, if we're not + * hiding empty directories, there is no need to + * recurse into an ignored directory. + */ + if (!(dir->flags & DIR_HIDE_EMPTY_DIRECTORIES)) + return path_excluded; + + /* + * Even if we are hiding empty directories, we can still avoid + * recursing into ignored directories for DIR_SHOW_IGNORED_TOO + * if DIR_SHOW_IGNORED_TOO_MODE_MATCHING is also set. + */ + if ((dir->flags & DIR_SHOW_IGNORED_TOO) && + (dir->flags & DIR_SHOW_IGNORED_TOO_MODE_MATCHING)) + return path_excluded; + } + /* - * Other than the path_recurse case immediately above, we only need - * to recurse into untracked/ignored directories if either of the - * following bits is set: + * Other than the path_recurse case above, we only need to + * recurse into untracked directories if either of the following + * bits is set: * - DIR_SHOW_IGNORED_TOO (because then we need to determine if * there are ignored entries below) * - DIR_HIDE_EMPTY_DIRECTORIES (because we have to determine if * the directory is empty) */ - if (!(dir->flags & (DIR_SHOW_IGNORED_TOO | DIR_HIDE_EMPTY_DIRECTORIES))) - return excluded ? path_excluded : path_untracked; - - /* - * ...and even if DIR_SHOW_IGNORED_TOO is set, we can still avoid - * recursing into ignored directories if the path is excluded and - * DIR_SHOW_IGNORED_TOO_MODE_MATCHING is also set. - */ - if (excluded && - (dir->flags & DIR_SHOW_IGNORED_TOO) && - (dir->flags & DIR_SHOW_IGNORED_TOO_MODE_MATCHING)) - return path_excluded; + if (!excluded && + !(dir->flags & (DIR_SHOW_IGNORED_TOO | + DIR_HIDE_EMPTY_DIRECTORIES))) { + return path_untracked; + } /* * Even if we don't want to know all the paths under an untracked or diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh index 337f9af1d74b..00e5fa35dae3 100755 --- a/t/t7300-clean.sh +++ b/t/t7300-clean.sh @@ -746,7 +746,7 @@ test_expect_success 'clean untracked paths by pathspec' ' test_must_be_empty actual ' -test_expect_failure 'avoid traversing into ignored directories' ' +test_expect_success 'avoid traversing into ignored directories' ' test_when_finished rm -f output error && test_create_repo avoid-traversing-deep-hierarchy && ( From patchwork Fri May 7 04:04:59 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12243945 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=-12.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,URIBL_BLOCKED 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 BFF72C433B4 for ; Fri, 7 May 2021 04:05:10 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A0476613EB for ; Fri, 7 May 2021 04:05:10 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229952AbhEGEGI (ORCPT ); Fri, 7 May 2021 00:06:08 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58934 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229671AbhEGEGF (ORCPT ); Fri, 7 May 2021 00:06:05 -0400 Received: from mail-wm1-x332.google.com (mail-wm1-x332.google.com [IPv6:2a00:1450:4864:20::332]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 1D129C0613ED for ; Thu, 6 May 2021 21:05:05 -0700 (PDT) Received: by mail-wm1-x332.google.com with SMTP id u5-20020a7bc0450000b02901480e40338bso5755177wmc.1 for ; Thu, 06 May 2021 21:05:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=RCD1WrFJxMrytQ2QmONFIxMjkN4xZtTfbmf/jmcKbn0=; b=UrVo1IhoBazkvL1yUdT8RXHz7yxj1bk10RQg+Rcn79Rwhas5W81qa6TDiXfmSMEqfy XbeAtcm+kczCw80VZcCwABGuUeKz7uU85gV09uhx1+zYneqa5TKrs6Vi/dY8jl+HsQ6f laaE48TSYUtO46H+rVJWK8ID16aapyugC/XdlY47TD0BgVcObrCid9AJkHJCkdlxCRBW CWiljUWNl4oYxBSKWGYJAYuGwkxZgqJJpZkkUJhwSvxTCObZiVoCmrsy8eDY3GX1sNml xFq9YkvO4dSUfqEz0iyypDvyajXNxff4zvv/YZlpY6Sgeu5eDxdHlEDx02ljsicB0X/l TjNg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=RCD1WrFJxMrytQ2QmONFIxMjkN4xZtTfbmf/jmcKbn0=; b=AswtJSi2PpSjBIC3PYzpGul12Kms9MSLywo1FWtt0e1u25L9vZdd6WIa6UrxFaHZJG 0hxNdRdHpDTnHxjUPcudQ3ugBwMF3o1DsGLSUWPY6XB31UXODgapV+fMDBl0w5sYcoD0 sgI1essYDkAyIlXds9fR8xAgC57GtupAW7wpvfriO39fq8pBWyrsdVKiAYe8E8PrUMs4 5SNtDKJtdQ+OMbFPHfKlI6S8MgZm9H6z9iib8fXMGlWdRkt2U8CxrUeztPeRrvtxUKbY jwMjO9+2mWM0ttxtOAkrVi4gzjcdqiGLhdyBA3pJHr8BZ83oYiknxJFArIKrYitnE62l xtrg== X-Gm-Message-State: AOAM532dTwgyQ9TcS2nhattt4kw6oNzSB0D1fmSTak3azym76eZC2fjg ozxD+qiJIR+927/jXYMLQW+XJLFk47I= X-Google-Smtp-Source: ABdhPJxnUUVg5Cn8F2oS+doYvy6PenSYg+9US8S9mrwW2ve1f3m36MJfsAxqLtoka9iY9ck5/Rxbew== X-Received: by 2002:a1c:7501:: with SMTP id o1mr7717678wmc.65.1620360303878; Thu, 06 May 2021 21:05:03 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id z9sm5777116wmi.17.2021.05.06.21.05.03 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 May 2021 21:05:03 -0700 (PDT) Message-Id: In-Reply-To: References: Date: Fri, 07 May 2021 04:04:59 +0000 Subject: [PATCH 4/5] dir: traverse into untracked directories if they may have ignored subfiles Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren A directory that is untracked does not imply that all files under it should be categorized as untracked; in particular, if the caller is interested in ignored files, many files or directories underneath the untracked directory may be ignored. We previously partially handled this right with DIR_SHOW_IGNORED_TOO, but missed DIR_SHOW_IGNORED. It was not obvious, though, because the logic for untracked and excluded files had been fused together making it harder to reason about. The previous commit split that logic out, making it easier to notice that DIR_SHOW_IGNORED was missing. Add it. Signed-off-by: Elijah Newren --- dir.c | 10 ++++++---- t/t3001-ls-files-others-exclude.sh | 2 +- t/t7300-clean.sh | 2 +- 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/dir.c b/dir.c index 4b183749843e..3beb8e17a839 100644 --- a/dir.c +++ b/dir.c @@ -1877,15 +1877,17 @@ static enum path_treatment treat_directory(struct dir_struct *dir, /* * Other than the path_recurse case above, we only need to - * recurse into untracked directories if either of the following + * recurse into untracked directories if any of the following * bits is set: - * - DIR_SHOW_IGNORED_TOO (because then we need to determine if - * there are ignored entries below) + * - DIR_SHOW_IGNORED (because then we need to determine if + * there are ignored entries below) + * - DIR_SHOW_IGNORED_TOO (same as above) * - DIR_HIDE_EMPTY_DIRECTORIES (because we have to determine if * the directory is empty) */ if (!excluded && - !(dir->flags & (DIR_SHOW_IGNORED_TOO | + !(dir->flags & (DIR_SHOW_IGNORED | + DIR_SHOW_IGNORED_TOO | DIR_HIDE_EMPTY_DIRECTORIES))) { return path_untracked; } diff --git a/t/t3001-ls-files-others-exclude.sh b/t/t3001-ls-files-others-exclude.sh index ac05d1a17931..516c95ea0e82 100755 --- a/t/t3001-ls-files-others-exclude.sh +++ b/t/t3001-ls-files-others-exclude.sh @@ -292,7 +292,7 @@ EOF test_cmp expect actual ' -test_expect_failure 'ls-files with "**" patterns and --directory' ' +test_expect_success 'ls-files with "**" patterns and --directory' ' # Expectation same as previous test git ls-files --directory -o -i --exclude "**/a.1" >actual && test_cmp expect actual diff --git a/t/t7300-clean.sh b/t/t7300-clean.sh index 00e5fa35dae3..c2a3b7b6a52b 100755 --- a/t/t7300-clean.sh +++ b/t/t7300-clean.sh @@ -786,7 +786,7 @@ test_expect_success 'avoid traversing into ignored directories' ' ) ' -test_expect_failure 'traverse into directories that may have ignored entries' ' +test_expect_success 'traverse into directories that may have ignored entries' ' test_when_finished rm -f output && test_create_repo need-to-traverse-into-hierarchy && ( From patchwork Fri May 7 04:05:00 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Elijah Newren X-Patchwork-Id: 12243947 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=-12.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,URIBL_BLOCKED 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 9A051C43460 for ; Fri, 7 May 2021 04:05:11 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 728E261076 for ; Fri, 7 May 2021 04:05:11 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230022AbhEGEGJ (ORCPT ); Fri, 7 May 2021 00:06:09 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:58936 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229635AbhEGEGG (ORCPT ); Fri, 7 May 2021 00:06:06 -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 AB256C06138A for ; Thu, 6 May 2021 21:05:05 -0700 (PDT) Received: by mail-wr1-x42a.google.com with SMTP id l2so7679709wrm.9 for ; Thu, 06 May 2021 21:05:05 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=message-id:in-reply-to:references:from:date:subject:fcc :content-transfer-encoding:mime-version:to:cc; bh=0e4RrCJuKuAV6s9KmC98iAx1qWZSkyg2U2VQQvqOO0E=; b=NcF8oNBbFpq/WdT6o5VY3METqwQXMPhIlg/Ea+fqfrzk7HcGRN8E/jqOMYD5wdKzmk 1K8D6jSUFUeApLDdcR12euWkM1IMfyb0igqPDa0HZr+MlZGWgUYtgFll4mrWagfzdV5x nndxDjDEmjNaznX236pFV4LWEX3BP7Pyy12L4NxyTITxUW7eV5GI1QdUmzRGKv3KpMqq 6BEcgjmUcWutAYsvM2+3f5ETuT10qDmGTcdkogHEIeCatNrNLy9qaTlnLdDlL6X2TfI3 ke1w6/OhSQIaJUd1JxlxBFtXvVkMGYx5m0VKkoqNWoivvrC4qVC4paMhrO04IdnHWY1H GtrQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:message-id:in-reply-to:references:from:date :subject:fcc:content-transfer-encoding:mime-version:to:cc; bh=0e4RrCJuKuAV6s9KmC98iAx1qWZSkyg2U2VQQvqOO0E=; b=nW2RqGFQeg9hmORhCYtRYlsEfzBCEhdsL/EUYiqBfSzBAKGrP9az0+YaYzQ1InzKgV g9y/wkmZXOXA+boCk6I3gKBgIkKUDcWcycCUafiv572ODq3Bh9QhDhu3GkJvh8+pQ+u4 rTckSES0JVFu4tgs9sQkuvYUwidKq6zuHirMaeigveGgJCjJg8vVuMlCXdJ4/p922YYO oDxyLWP3J4uV9XRys3+QVVrqxfh5IOdfxocswmMlKZzKOARe3ojUfdREKZtjchGyJFvI R7cz0HBnPHbEnwGt3bPvXTOZ5uaGtMwQxyjRXKqImR9Bq/E+lY4eIBBqmZTXPdIaut3J KzNA== X-Gm-Message-State: AOAM532cAD48R3SrAxQ2yPu3Ld2IUxynT8U4ayUEK8AehKqJiVGntsTj NVbNf15710gtPsKBfnU3z2Pd7Yu1nsY= X-Google-Smtp-Source: ABdhPJw6waGUVhahrJRkOQp7ez98/xQPxcIqNro7Gt8JzqQMVppX9J1d9iokfxEddZWpi3eOQJFzQA== X-Received: by 2002:a5d:6752:: with SMTP id l18mr9221953wrw.422.1620360304471; Thu, 06 May 2021 21:05:04 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id n22sm11118008wmo.12.2021.05.06.21.05.04 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 06 May 2021 21:05:04 -0700 (PDT) Message-Id: <3d8dd00ccd10d6b7ce9f928f31f8a04e885730fc.1620360300.git.gitgitgadget@gmail.com> In-Reply-To: References: Date: Fri, 07 May 2021 04:05:00 +0000 Subject: [PATCH 5/5] [RFC] ls-files: error out on -i unless -o or -c are specified Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: Elijah Newren , Elijah Newren Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren From: Elijah Newren ls-files --ignored can be used together with either --others or --cached. After being perplexed for a bit and digging in to the code, I assumed that ls-files -i was just broken and not printing anything and had a nice patch ready to submit when I finally realized that -i can be used with --cached to find tracked ignores. While that was a mistake on my part, and a careful reading of the documentation could have made this more clear, I suspect this is an error others are likely to make as well. In fact, of two uses in our testsuite, I believe one of the two did make this error. In t1306.13, there are NO tracked files, and all the excludes built up and used in that test and in previous tests thus have to be about untracked files. However, since they were looking for an empty result, the mistake went unnoticed as their erroneous command also just happened to give an empty answer. -i will most the time be used with -o, which would suggest we could just make -i imply -o in the absence of either a -o or -c, but that would be a backward incompatible break. Instead, let's just flag -i without either a -o or -c as an error, and update the two relevant testcases to specify their intent. Signed-off-by: Elijah Newren --- builtin/ls-files.c | 3 +++ t/t1306-xdg-files.sh | 2 +- t/t3003-ls-files-exclude.sh | 4 ++-- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/builtin/ls-files.c b/builtin/ls-files.c index 60a2913a01e9..9f74b1ab2e69 100644 --- a/builtin/ls-files.c +++ b/builtin/ls-files.c @@ -748,6 +748,9 @@ int cmd_ls_files(int argc, const char **argv, const char *cmd_prefix) if (pathspec.nr && error_unmatch) ps_matched = xcalloc(pathspec.nr, 1); + if ((dir.flags & DIR_SHOW_IGNORED) && !show_others && !show_cached) + die("ls-files --ignored is usually used with --others, but --cached is the default. Please specify which you want."); + if ((dir.flags & DIR_SHOW_IGNORED) && !exc_given) die("ls-files --ignored needs some exclude pattern"); diff --git a/t/t1306-xdg-files.sh b/t/t1306-xdg-files.sh index dd87b43be1a6..40d3c42618c0 100755 --- a/t/t1306-xdg-files.sh +++ b/t/t1306-xdg-files.sh @@ -116,7 +116,7 @@ test_expect_success 'Exclusion in a non-XDG global ignore file' ' test_expect_success 'Checking XDG ignore file when HOME is unset' ' (sane_unset HOME && git config --unset core.excludesfile && - git ls-files --exclude-standard --ignored >actual) && + git ls-files --exclude-standard --ignored --others >actual) && test_must_be_empty actual ' diff --git a/t/t3003-ls-files-exclude.sh b/t/t3003-ls-files-exclude.sh index d5ec333131f9..c41c4f046abf 100755 --- a/t/t3003-ls-files-exclude.sh +++ b/t/t3003-ls-files-exclude.sh @@ -29,11 +29,11 @@ test_expect_success 'add file to gitignore' ' ' check_all_output -test_expect_success 'ls-files -i lists only tracked-but-ignored files' ' +test_expect_success 'ls-files -i -c lists only tracked-but-ignored files' ' echo content >other-file && git add other-file && echo file >expect && - git ls-files -i --exclude-standard >output && + git ls-files -i -c --exclude-standard >output && test_cmp expect output ' From patchwork Fri May 7 16:22:50 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Derrick Stolee X-Patchwork-Id: 12244905 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=-14.2 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_SANE_1 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 60299C433ED for ; Fri, 7 May 2021 16:22:54 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 3446260698 for ; Fri, 7 May 2021 16:22:54 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S238101AbhEGQXw (ORCPT ); Fri, 7 May 2021 12:23:52 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53472 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236633AbhEGQXw (ORCPT ); Fri, 7 May 2021 12:23:52 -0400 Received: from mail-qk1-x731.google.com (mail-qk1-x731.google.com [IPv6:2607:f8b0:4864:20::731]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86E24C061574 for ; Fri, 7 May 2021 09:22:52 -0700 (PDT) Received: by mail-qk1-x731.google.com with SMTP id a22so8429968qkl.10 for ; Fri, 07 May 2021 09:22:52 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:cc:references:from:message-id:date:user-agent :mime-version:in-reply-to:content-language:content-transfer-encoding; bh=kfyE/36ejJMgmj28q9XP3B4LF0SVTe/wiJd/IE94CeI=; b=OYzyfOBUnYo6GKTC5driSIMqjQm0Hj1FhGFOj8kwdKPWE/bFrPI7gc71Vdnz2UAOm/ IE8rDzu6d+arcTFuaxQNOUEJsavcTP5n/EhhGBkgO5me8lNC5QyAf31x4NiCbA79g4No BAmDAuO36/lK/BbeD0Ra2jDD+X6NwzuvnX6lDbTMkMz9qVS6w+5LhoN4yU0Y8/m0rwxV waH7W+IDulKVElDVtC+kJjEXwuQJSF8kC0fZfv03OpYPu5su/nDGE4WjzIEpyjopAlgq 43P4ZkkRh90v9KD9B/F6pv1CJrzOI9DmS9Y67AhSyO0XA7x8WHhqqlqtiH2Ajj9qjbb+ iMNQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:cc:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-language :content-transfer-encoding; bh=kfyE/36ejJMgmj28q9XP3B4LF0SVTe/wiJd/IE94CeI=; b=mgvTdRa+LUjgHZErMuAE9P1qsFno62aC10pMAjBpzXg+LeVNzKufo3yu3/BCHynCBC fAyF6kDxTr6FNVbG8l+LtNATQqjlFAcUhA0ULF53O938pQnXj9xO3fanxY3hE0k2aA4d LaoZFniWbMwylN7pRaYpoiv0oVhoibjWR6KjJzbs91E0HLcnLZwy+uR3qGTwSwexmL0V e1lAT5PY2WWn6uAiQVONTwx5RlkXS5VCEP8Z12So1OSfipTfsbjTSY01UHt7krfUBZIO 7PG2OWM0a0qRsY3DMa551rF+g0oP4o1fe35a1gLN1H2Fe7TJR6YfaA19vZ33OqQKjmhY xAGQ== X-Gm-Message-State: AOAM5324C42uVukNxFt3fYHL6JzAoSTCdu73tKpVirozv/KmMLNYVLZf ifQUPODVL6VrRqu0ezMgEE0= X-Google-Smtp-Source: ABdhPJywZy1+v6rFRBG8fw/ovTME+hbgYz2t/s7hWThbr17QIvp5EsNR8PRfNrEncHxfbblMjMjaFg== X-Received: by 2002:a37:910:: with SMTP id 16mr6409010qkj.497.1620404571671; Fri, 07 May 2021 09:22:51 -0700 (PDT) Received: from ?IPv6:2600:1700:e72:80a0:10d2:8815:444d:57fb? ([2600:1700:e72:80a0:10d2:8815:444d:57fb]) by smtp.gmail.com with ESMTPSA id s24sm5006950qtx.94.2021.05.07.09.22.50 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Fri, 07 May 2021 09:22:51 -0700 (PDT) Subject: [PATCH 6/5] dir: update stale description of treat_directory() To: Elijah Newren via GitGitGadget , git@vger.kernel.org Cc: Elijah Newren References: From: Derrick Stolee Message-ID: <3343338e-9262-dfd1-90ef-36908c91dad4@gmail.com> Date: Fri, 7 May 2021 12:22:50 -0400 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:78.0) Gecko/20100101 Thunderbird/78.10.1 MIME-Version: 1.0 In-Reply-To: Content-Language: en-US Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org On 5/7/2021 12:04 AM, Elijah Newren via GitGitGadget wrote: > This patchset fixes a few directory traversal issues, where fill_directory() > would traverse into directories that it shouldn't and not traverse into > directories that it should. One of these issues was reported recently on > this list[1], another was found at $DAYJOB. > > The fifth patch might have backward compatibility implications, but is easy > to review. Even if the logic in dir.c makes your eyes glaze over, at least > take a look at the fifth patch. My eyes were glazing over, so I went to read the whole treat_directory() method and its related documentation comment. I found it to be a bit confusing that it was referencing names that were deprecated 12 years ago. Here is a patch that you could add to this series to improve these comments. Thanks, -Stolee -- >8 -- From 587a94ac396c969b6e7734ee46afeac20e87ccb9 Mon Sep 17 00:00:00 2001 From: Derrick Stolee Date: Fri, 7 May 2021 12:14:13 -0400 Subject: [PATCH] dir: update stale description of treat_directory() The documentation comment for treat_directory() was originally written in 095952 (Teach directory traversal about subprojects, 2007-04-11) which was before the 'struct dir_struct' split its bitfield of named options into a 'flags' enum in 7c4c97c0 (Turn the flags in struct dir_struct into a single variable, 2009-02-16). When those flags changed, the comment became stale, since members like 'show_other_directories' transitioned into flags like DIR_SHOW_OTHER_DIRECTORIES. Update the comments for treat_directory() to use these flag names rather than the old member names. Signed-off-by: Derrick Stolee --- dir.c | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/dir.c b/dir.c index 3beb8e17a83..0a0138bc1aa 100644 --- a/dir.c +++ b/dir.c @@ -1749,13 +1749,13 @@ static enum exist_status directory_exists_in_index(struct index_state *istate, * Case 3: if we didn't have it in the index previously, we * have a few sub-cases: * - * (a) if "show_other_directories" is true, we show it as - * just a directory, unless "hide_empty_directories" is + * (a) if DIR_SHOW_OTHER_DIRECTORIES flag is set, we show it as + * just a directory, unless DIR_HIDE_EMPTY_DIRECTORIES is * also true, in which case we need to check if it contains any * untracked and / or ignored files. - * (b) if it looks like a git directory, and we don't have - * 'no_gitlinks' set we treat it as a gitlink, and show it - * as a directory. + * (b) if it looks like a git directory and we don't have the + * DIR_NO_GITLINKS flag, then we treat it as a gitlink, and + * show it as a directory. * (c) otherwise, we recurse into it. */ static enum path_treatment treat_directory(struct dir_struct *dir, @@ -1843,7 +1843,6 @@ static enum path_treatment treat_directory(struct dir_struct *dir, return path_recurse; } - /* This is the "show_other_directories" case */ assert(dir->flags & DIR_SHOW_OTHER_DIRECTORIES); /* @@ -1858,7 +1857,7 @@ static enum path_treatment treat_directory(struct dir_struct *dir, /* Special cases for where this directory is excluded/ignored */ if (excluded) { /* - * In the show_other_directories case, if we're not + * If DIR_SHOW_OTHER_DIRECTORIES is set and we're not * hiding empty directories, there is no need to * recurse into an ignored directory. */