From patchwork Thu Jun 11 06:59:30 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood via GitGitGadget X-Patchwork-Id: 11599321 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 29EE6912 for ; Thu, 11 Jun 2020 06:59:41 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 11AF32075F for ; Thu, 11 Jun 2020 06:59:41 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="pNYON9M/" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726631AbgFKG7j (ORCPT ); Thu, 11 Jun 2020 02:59:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46646 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726526AbgFKG7i (ORCPT ); Thu, 11 Jun 2020 02:59:38 -0400 Received: from mail-wm1-x341.google.com (mail-wm1-x341.google.com [IPv6:2a00:1450:4864:20::341]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E4CC6C08C5C2 for ; Wed, 10 Jun 2020 23:59:37 -0700 (PDT) Received: by mail-wm1-x341.google.com with SMTP id l26so3912981wme.3 for ; Wed, 10 Jun 2020 23:59:37 -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=AafMz9R4E5k5OaVWLq2859BJWipKHSLAeJiS2GAQ5i4=; b=pNYON9M/gGAl0njERx3KlXIiEMhLiZ6vJuDbS7Mg6ChtmYk1reCIRtwzkXhn94TtAW EAKxrh+r+jQiaAzgw57XnYeCuDyoqbNwb7GVh0f/CqiVgePunz9Rce9568rRWrTYGzSj ICySjh5db25TC50+ziAn9CEqawP7NATqyscP9099wXohoVZj5aPRvXjL+vjybNSaFVkd eEL4JYx0yJJHkpXSfr8h4c83zzL0kz0G5kK0BHwy8dUBoG9NpL4AxVBM3D4bN9p+48nm EUxFLodv1gbRkEIQ8mHONd8/FT1D/BkAL9WJogFnYBLdJJtFGQ96zM/W7Vmws+hIVbMp +BcQ== 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=AafMz9R4E5k5OaVWLq2859BJWipKHSLAeJiS2GAQ5i4=; b=dKNx/udzYWc8WtoZzH5fSmxOa7pUNSfNUnPNOfGlr+Kn6EfQPv6oY0EfaipbhCTh1Q s0PH03ebqLI3LoLsojT1RfoMtPH2oB6pyYE9feQWlUZO6RZI4jlhUYyE0XW47oG0T7BH /w3z4wLOAmv5hhdWFQ6xZQUznIqVKmnbxgSyT53bv/wPRkvVp0x9ZdvYCO9ZMijQhIoH B0DCUJEBZTVZT4u5xershF/80j3d2uqZtG7KVAHEdpBIAv/m6JS+eb7qPLhEpj+FQWJT VTCz3EkNYY6rMnk3r9RHwrh3HidPCz1EZiR9WmfT19DEsx5YV4ypjBtx8309gjiOPJPK 8FmQ== X-Gm-Message-State: AOAM532VeSSeOayyf2uVCuZ6z89IGVtlzrTJS5sDcReyI8LAQqZEg6W3 RF1K4wauSCFoU1KzHbznVgy11zUU X-Google-Smtp-Source: ABdhPJzkyusSvvRkqUn1r+wxLIckq4BGuOCNQ95R9QXiRSQI181wWVW2gcFw3mQVIHY6M9AaYQigiA== X-Received: by 2002:a1c:1b17:: with SMTP id b23mr6485971wmb.3.1591858776422; Wed, 10 Jun 2020 23:59:36 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id s132sm2901784wmf.12.2020.06.10.23.59.35 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jun 2020 23:59:36 -0700 (PDT) Message-Id: In-Reply-To: References: From: "Elijah Newren via GitGitGadget" Date: Thu, 11 Jun 2020 06:59:30 +0000 Subject: [PATCH 1/4] dir: fix a few confusing comments Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: bmalehorn@gmail.com, Elijah Newren , Elijah Newren Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren Signed-off-by: Elijah Newren --- dir.c | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/dir.c b/dir.c index d97e9558489..6fb2f8ecdd7 100644 --- a/dir.c +++ b/dir.c @@ -1820,7 +1820,7 @@ static enum path_treatment treat_directory(struct dir_struct *dir, * to recurse into untracked/ignored directories if either of the * following bits is set: * - DIR_SHOW_IGNORED_TOO (because then we need to determine if - * there are ignored directories below) + * there are ignored entries below) * - DIR_HIDE_EMPTY_DIRECTORIES (because we have to determine if * the directory is empty) */ @@ -1838,10 +1838,11 @@ static enum path_treatment treat_directory(struct dir_struct *dir, return path_excluded; /* - * If we have we don't want to know the all the paths under an - * untracked or ignored directory, we still need to go into the - * directory to determine if it is empty (because an empty directory - * should be path_none instead of path_excluded or path_untracked). + * Even if we don't want to know all the paths under an untracked or + * ignored directory, we may still need to go into the directory to + * determine if it is empty (because with DIR_HIDE_EMPTY_DIRECTORIES, + * an empty directory should be path_none instead of path_excluded or + * path_untracked). */ check_only = ((dir->flags & DIR_HIDE_EMPTY_DIRECTORIES) && !(dir->flags & DIR_SHOW_IGNORED_TOO)); From patchwork Thu Jun 11 06:59:31 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood via GitGitGadget X-Patchwork-Id: 11599323 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id CC9BD739 for ; Thu, 11 Jun 2020 06:59:43 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id A8BB92075F for ; Thu, 11 Jun 2020 06:59:43 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="rJLUuVZL" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726646AbgFKG7m (ORCPT ); Thu, 11 Jun 2020 02:59:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46652 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726635AbgFKG7k (ORCPT ); Thu, 11 Jun 2020 02:59:40 -0400 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id AEF29C08C5C1 for ; Wed, 10 Jun 2020 23:59:38 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id x6so4890388wrm.13 for ; Wed, 10 Jun 2020 23:59:38 -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=ydblsq5391Sh2V97ZTnFfOW1gE+9Map7bAYJl97qdsM=; b=rJLUuVZL/VhPhqPGle82+R9UZQPb7lcz8sSZy+nOUWOVuYLREDbkLqHwf1skZj3FcJ xOSDZqvE8lXq5sdJYGLOYaRTHngpOiWr0nIQFRr1crzD78ChxYq/bMX7320RegsjLON6 THKekQrVFRxGDoIopE6tADPXg+1Bc/mEba7TAZQd7imaZh0fGPHnDGMeNHtZxcl0hXlX kgWQtiy2RNSIhdQYLZ32VOHDP9U+79CJscz6BqzVTfoJnh3SmfZS523+pM4PuzTG6YlE T0K7u+pG9UDIzBagHsAzMdJ0wCArOw0mwwn/OTvvlF44YDM/6biJlNWgHY0s3W6lH03T RP+A== 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=ydblsq5391Sh2V97ZTnFfOW1gE+9Map7bAYJl97qdsM=; b=AfWqir3UH9Nmtc8U4kz7KSmwL7llc8ggyg4Yg5/k6OnrHnWna18BrAJTv3uDSw9m7O dG9mK3oKt8rZ2rSSPO6a5ttUZvBQ24P7WtMoUZUbbjehnxXbFonDZSnI4mmqXiEpZkUh UigQ/zGOj84LvlG+mhSN5hwfp9wy0uBTCA1837fD4M2uhWxR7UN3x8z5/sQAr/QK0PCP wLoK7HkQWn+sWa3XSprS3LinHr5Dm7nUnPuIIKcYOcZI/rUB18yZeo1ZoGRO+EtgCoRY PBdkfSHQYKpSAy1mDzts+mUVSc/9oTBN3+mKWXagdiUZaE08n2/o8IVgnnAJZogrD+1+ /buQ== X-Gm-Message-State: AOAM5330+MQigKt7NhxciMO9CY/xblKfv7IkQkn9qRxfhSs1cfTdGgBj fT1+8ORrKweHKP8nP0thZU5FXjnW X-Google-Smtp-Source: ABdhPJyzfwopFqHHu++bhXEotg5RLqT8mg+jdCpQ/eUneuCS4QZWCns+Q6Q6CuBEoZm9i9BqSsgrlA== X-Received: by 2002:a05:6000:108c:: with SMTP id y12mr7559759wrw.88.1591858777265; Wed, 10 Jun 2020 23:59:37 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id y14sm2648485wma.25.2020.06.10.23.59.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jun 2020 23:59:36 -0700 (PDT) Message-Id: In-Reply-To: References: From: "Elijah Newren via GitGitGadget" Date: Thu, 11 Jun 2020 06:59:31 +0000 Subject: [PATCH 2/4] dir, clean: avoid disallowed behavior Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: bmalehorn@gmail.com, Elijah Newren , Elijah Newren Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren dir.h documented quite clearly that DIR_SHOW_IGNORED and DIR_SHOW_IGNORED_TOO are mutually exclusive, with a big comment to this effect by the definition of both enum values. However, a command like git clean -fx $DIR would set both values for dir.flags. I _think_ it happened to work because: * As dir.h points out, DIR_KEEP_UNTRACKED_CONTENTS only takes effect if DIR_SHOW_IGNORED_TOO is set. * As coded, I believe DIR_SHOW_IGNORED would just happen to take precedence over DIR_SHOW_IGNORED_TOO in the code as currently constructed. Which is a long way of saying "we just got lucky". Fix clean.c to avoid setting these mutually exclusive values at the same time, and add a check to dir.c that will throw a BUG() to prevent anyone else from making this mistake. Signed-off-by: Elijah Newren --- builtin/clean.c | 2 +- dir.c | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/builtin/clean.c b/builtin/clean.c index 4ca12bc0c0b..3ca940f83a2 100644 --- a/builtin/clean.c +++ b/builtin/clean.c @@ -954,7 +954,7 @@ int cmd_clean(int argc, const char **argv, const char *prefix) remove_directories = 1; } - if (remove_directories) + if (remove_directories && !ignored_only) dir.flags |= DIR_SHOW_IGNORED_TOO | DIR_KEEP_UNTRACKED_CONTENTS; if (read_cache() < 0) diff --git a/dir.c b/dir.c index 6fb2f8ecdd7..a3ad9702d64 100644 --- a/dir.c +++ b/dir.c @@ -193,6 +193,10 @@ int fill_directory(struct dir_struct *dir, const char *prefix; size_t prefix_len; + unsigned exclusive_flags = DIR_SHOW_IGNORED | DIR_SHOW_IGNORED_TOO; + if ((dir->flags & exclusive_flags) == exclusive_flags) + BUG("DIR_SHOW_IGNORED and DIR_SHOW_IGNORED_TOO are exclusive"); + /* * Calculate common prefix for the pathspec, and * use that to optimize the directory walk From patchwork Thu Jun 11 06:59:32 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood via GitGitGadget X-Patchwork-Id: 11599325 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 441A4912 for ; Thu, 11 Jun 2020 06:59:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 288672075F for ; Thu, 11 Jun 2020 06:59:44 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="oIdzB/hT" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726643AbgFKG7l (ORCPT ); Thu, 11 Jun 2020 02:59:41 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726526AbgFKG7j (ORCPT ); Thu, 11 Jun 2020 02:59:39 -0400 Received: from mail-wr1-x444.google.com (mail-wr1-x444.google.com [IPv6:2a00:1450:4864:20::444]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 86503C08C5C2 for ; Wed, 10 Jun 2020 23:59:39 -0700 (PDT) Received: by mail-wr1-x444.google.com with SMTP id t18so4925147wru.6 for ; Wed, 10 Jun 2020 23:59:39 -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=2BI2zOKCYnv4HUooTIQLIlweJ3GRgVhA10HSsWAgCYs=; b=oIdzB/hTK9AfT7nNGEQPqVmoJugpHxn0jo4PXWEdcPNdPdo9EBsn88BmnMCo3bTkDO jvba+uWhbk1UX6kETBHNaUrkGqwoVOVuXTWqicw+o0aE0bM0muHyR7PqQLe4EOPafdog N7xO1VbRcEmu56bCcoAR+BCHE9dwTrKtc2tZMVe+23TEhNcL2v8hXJqd9v8Ly6zWeh9I h1DN301DFAiNo/rPBSIum/aKC+sNdSZ4bEhvLDAiNi1on+/e2sA0v/AVUFaGP+2cAXZU 137TWoVNTghHd16QCfGSycYAGZUjZt2zYB0lk86AAuZq9cm3lRDHJRJ8ml6sPnCdBjzv iGJw== 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=2BI2zOKCYnv4HUooTIQLIlweJ3GRgVhA10HSsWAgCYs=; b=QQxOa2qW+sildNm4pzlaw2+IwgnhFFeL4O2OqvBPePUEiwHJMpg0afAZqcIQV7+Zfr BN+CPOoZogGCEPBKtObKtS+Znmdzo2ktx18zXfLxds3R6RC72JHDcnzPU/45/1a7tF8T 2fs1XgcXtH2eCiwr9ZcAG9Gumf5nZ+U/FsYyw+3o0Dg+Vk2YBKjVDnZp2ac9cq8dRVxS QQV+nXxyui7Fiw0g/OEA8+yM1ErMqZtc50iHYKfcS+/PXlyzu2XzhcYivtqaBIibapiZ +nAqBDUyY0HaFQfuYaPqDuHQj3Z/r5Z7yw4LgJeOnMxr2KOp1uzd9lRr1rZttfCBFBwz +PRw== X-Gm-Message-State: AOAM532Zh1B+xKJMj3jZqcRf2HKu8GbdnwJkzRsFSBab9HzsZYoY8LHA Xcnn1Bd/y9X0+f8zLKIGvIikwnjM X-Google-Smtp-Source: ABdhPJw0y4IIBaw+wG9TRh0pfJjM7Bw9JLSgF2vmy5C1Cb6foEp2dbEDHEx464h6ZbIgOG+StVeHwA== X-Received: by 2002:adf:dd06:: with SMTP id a6mr8043796wrm.142.1591858778079; Wed, 10 Jun 2020 23:59:38 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id m3sm2714035wmc.0.2020.06.10.23.59.37 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jun 2020 23:59:37 -0700 (PDT) Message-Id: In-Reply-To: References: From: "Elijah Newren via GitGitGadget" Date: Thu, 11 Jun 2020 06:59:32 +0000 Subject: [PATCH 3/4] clean: consolidate handling of ignored parameters Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: bmalehorn@gmail.com, Elijah Newren , Elijah Newren Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren I spent a long time trying to figure out how and whether the code worked with different values of ignore, ignore_only, and remove_directories. After lots of time setting up lots of testcases, sifting through lots of print statements, and walking through the debugger, I finally realized that one piece of code related to how it was all setup was found in clean.c rather than dir.c. Make a change that would have made it easier for me to do the extra testing by putting this handling in one spot. Signed-off-by: Elijah Newren --- builtin/clean.c | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/builtin/clean.c b/builtin/clean.c index 3ca940f83a2..1be437bd5a3 100644 --- a/builtin/clean.c +++ b/builtin/clean.c @@ -924,12 +924,6 @@ int cmd_clean(int argc, const char **argv, const char *prefix) 0); memset(&dir, 0, sizeof(dir)); - if (ignored_only) - dir.flags |= DIR_SHOW_IGNORED; - - if (ignored && ignored_only) - die(_("-x and -X cannot be used together")); - if (!interactive && !dry_run && !force) { if (config_set) die(_("clean.requireForce set to true and neither -i, -n, nor -f given; " @@ -946,6 +940,13 @@ int cmd_clean(int argc, const char **argv, const char *prefix) dir.flags |= DIR_SHOW_OTHER_DIRECTORIES; + if (ignored && ignored_only) + die(_("-x and -X cannot be used together")); + if (!ignored) + setup_standard_excludes(&dir); + if (ignored_only) + dir.flags |= DIR_SHOW_IGNORED; + if (argc) { /* * Remaining args implies pathspecs specified, and we should @@ -960,9 +961,6 @@ int cmd_clean(int argc, const char **argv, const char *prefix) if (read_cache() < 0) die(_("index file corrupt")); - if (!ignored) - setup_standard_excludes(&dir); - pl = add_pattern_list(&dir, EXC_CMDL, "--exclude option"); for (i = 0; i < exclude_list.nr; i++) add_pattern(exclude_list.items[i].string, "", 0, pl, -(i+1)); From patchwork Thu Jun 11 06:59:33 2020 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Phillip Wood via GitGitGadget X-Patchwork-Id: 11599327 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 20649739 for ; Thu, 11 Jun 2020 06:59:45 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by mail.kernel.org (Postfix) with ESMTP id 086FC207C3 for ; Thu, 11 Jun 2020 06:59:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=gmail.com header.i=@gmail.com header.b="ECgJXNKV" Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726526AbgFKG7o (ORCPT ); Thu, 11 Jun 2020 02:59:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46654 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726645AbgFKG7l (ORCPT ); Thu, 11 Jun 2020 02:59:41 -0400 Received: from mail-wr1-x441.google.com (mail-wr1-x441.google.com [IPv6:2a00:1450:4864:20::441]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 682BAC08C5C3 for ; Wed, 10 Jun 2020 23:59:40 -0700 (PDT) Received: by mail-wr1-x441.google.com with SMTP id j10so4919794wrw.8 for ; Wed, 10 Jun 2020 23:59:40 -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=xROFT2e5aVDwZO7Wu0WjJ07qYlY5Khd4BZpkxVRpZHw=; b=ECgJXNKV96f7bn+4x/8g+y49gvwQqtWQ8VAuOW5MfxgQI+UylS2kuC+pUMRogA1nQb hMrQXCViuIAD7IyB54DWTfaCWpbsC0GS1m/dT5ST03xxsqoaygR9DBujOkLf6sXqpF/W qtWJ3FYcVfKnNI9/Krba1vLEiU8vH4vw5q26sZSQI1ldj0VDD1buxvqbmXMspne/MePi ICiEskMphQAGTprp3Q/YWrRG8HYQRZCsJUn0l13vsxbxeCV+n1RT/meyjB13cPupqX59 eWn1kSleg1rX7gxTZXom+NPUYwrmLmgPNa6fD+y5zvhCySiim6RN65vNlD4/N82sTqXl keJg== 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=xROFT2e5aVDwZO7Wu0WjJ07qYlY5Khd4BZpkxVRpZHw=; b=Ar8n3r9gkfrMDVPyURl7dkoIucaeOMaYPrQWFKES2lTTy6UOEhSsf9PmBKTigMksTx OL8j/mBU1lRJV+egJ2k838ArQgKcSy2ZXUMqwBb/EAs9HvIFh4rMN187tXtxvqFU5EOJ Ub1PCnK2h2Jt6Z/eaNPQhz2HQ2H9h2joNVe770PBaxb+dh/QBeszPJyQMlK2AucNMPIj v7xtenuQ0Cph8JfBiS45f5n98Ni/bZGppu/2NlYnU4vzHKXRa5Cc2TIPDKW3OrEtUyT5 G44bVU490S2DU9832JWNnXYQ/BxOwRmri5ft7mdmApmVWRsSy0ejp3yv6k3/ROFZANi+ ovAw== X-Gm-Message-State: AOAM531H5Ka3Nlqswj9Bz9IhiegBFOnUdzB3h1WNqkWSJrYRohgf3t2P BDuLgNeE0UsKPf3/l+undU30SSNO X-Google-Smtp-Source: ABdhPJwlR4TYZVwELeSs5ZIrymGdHVd+e3KlQZiwGvPc0Pr2dFdJTQ2SPcVlK4/cFWYIvTdJUpJURA== X-Received: by 2002:adf:dec5:: with SMTP id i5mr8248481wrn.16.1591858778910; Wed, 10 Jun 2020 23:59:38 -0700 (PDT) Received: from [127.0.0.1] ([13.74.141.28]) by smtp.gmail.com with ESMTPSA id y25sm8664238wmi.2.2020.06.10.23.59.38 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 10 Jun 2020 23:59:38 -0700 (PDT) Message-Id: In-Reply-To: References: From: "Elijah Newren via GitGitGadget" Date: Thu, 11 Jun 2020 06:59:33 +0000 Subject: [PATCH 4/4] clean: optimize and document cases where we recurse into subdirectories Fcc: Sent MIME-Version: 1.0 To: git@vger.kernel.org Cc: bmalehorn@gmail.com, Elijah Newren , Elijah Newren Sender: git-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: git@vger.kernel.org From: Elijah Newren Commit 6b1db43109 ("clean: teach clean -d to preserve ignored paths", 2017-05-23) added the following code block (among others) to git-clean: if (remove_directories) dir.flags |= DIR_SHOW_IGNORED_TOO | DIR_KEEP_UNTRACKED_CONTENTS; The reason for these flags is well documented in the commit message, but isn't obvious just from looking at the code. Add some explanations to the code to make it clearer. Further, it appears git-2.26 did not correctly handle this combination of flags from git-clean. With both these flags and without DIR_SHOW_IGNORED_TOO_MODE_MATCHING set, git is supposed to recurse into all untracked AND ignored directories. git-2.26.0 clearly was not doing that. I don't know the full reasons for that or whether git < 2.27.0 had additional unknown bugs because of that misbehavior, because I don't feel it's worth digging into. As per the huge changes and craziness documented in commit 8d92fb2927 ("dir: replace exponential algorithm with a linear one", 2020-04-01), the old algorithm was a mess and was thrown out. What I can say is that git-2.27.0 correctly recurses into untracked AND ignored directories with that combination. However, in clean's case we don't need to recurse into ignored directories; that is just a waste of time. Thus, when git-2.27.0 started correctly handling those flags, we got a performance regression report. Rather than relying on other bugs in fill_directory()'s former logic to provide the behavior of skipping ignored directories, make use of the DIR_SHOW_IGNORED_TOO_MODE_MATCHING value specifically added in commit eec0f7f2b7 ("status: add option to show ignored files differently", 2017-10-30) for this purpose. Reported-by: Brian Malehorn Signed-off-by: Elijah Newren --- builtin/clean.c | 33 +++++++++++++++++++++++++++++++-- 1 file changed, 31 insertions(+), 2 deletions(-) diff --git a/builtin/clean.c b/builtin/clean.c index 1be437bd5a3..5a9c29a558b 100644 --- a/builtin/clean.c +++ b/builtin/clean.c @@ -955,8 +955,37 @@ int cmd_clean(int argc, const char **argv, const char *prefix) remove_directories = 1; } - if (remove_directories && !ignored_only) - dir.flags |= DIR_SHOW_IGNORED_TOO | DIR_KEEP_UNTRACKED_CONTENTS; + if (remove_directories && !ignored_only) { + /* + * We need to know about ignored files too: + * + * If (ignored), then we will delete ignored files as well. + * + * If (!ignored), then even though we not are doing + * anything with ignored files, we need to know about them + * so that we can avoid deleting a directory of untracked + * files that also contains an ignored file within it. + * + * For the (!ignored) case, since we only need to avoid + * deleting ignored files, we can set + * DIR_SHOW_IGNORED_TOO_MODE_MATCHING in order to avoid + * recursing into a directory which is itself ignored. + */ + dir.flags |= DIR_SHOW_IGNORED_TOO; + if (!ignored) + dir.flags |= DIR_SHOW_IGNORED_TOO_MODE_MATCHING; + + /* + * Let the fill_directory() machinery know that we aren't + * just recursing to collect the ignored files; we want all + * the untracked ones so that we can delete them. (Note: + * we could also set DIR_KEEP_UNTRACKED_CONTENTS when + * ignored_only is true, since DIR_KEEP_UNTRACKED_CONTENTS + * only has effect in combination with DIR_SHOW_IGNORED_TOO. It makes + * the code clearer to exclude it, though. + */ + dir.flags |= DIR_KEEP_UNTRACKED_CONTENTS; + } if (read_cache() < 0) die(_("index file corrupt"));