From: "Ævar Arnfjörð Bjarmason" <avarab@gmail.com>
To: Tao Klerks via GitGitGadget <gitgitgadget@gmail.com>
Cc: git@vger.kernel.org, Tao Klerks <tao@klerks.biz>
Subject: Re: [PATCH v4] untracked-cache: support '--untracked-files=all' if configured
Date: Mon, 28 Feb 2022 15:02:24 +0100 [thread overview]
Message-ID: <220228.86y21v3wyj.gmgdl@evledraar.gmail.com> (raw)
In-Reply-To: <pull.985.v4.git.1645974782256.gitgitgadget@gmail.com>
On Sun, Feb 27 2022, Tao Klerks via GitGitGadget wrote:
> From: Tao Klerks <tao@klerks.biz>
> [...]
> The test suite passes, but as a n00b I do have questions:
>
> * Is there any additional validation that could/should be done to
> confirm that "-uall" untracked data can be cached safely?
I haven't given this any substantial review, sorry.
> * It looks safe from following the code
Yes, at a glance it looks safe to me.
> * It seems from discussing briefly with Elijah Newren in the thread
> above that thare are no obvious red flags
> * Manual testing, explicitly and implicitly through months of use,
> yields no issues
> * Is it OK to check the repo configuration in the body of processing?
> It seems to be a rare pattern
Yes, it's not very common, but it's fine.
> * Can anyone think of a way to test this change?
Well, if we set "flags" to 0 in your new helper the existing tests will
fail, so that's something at least.
> -static void new_untracked_cache(struct index_state *istate)
> +static unsigned configured_default_dir_flags(struct repository *repo)
> +{
> + /*
> + * This logic is coordinated with the setting of these flags in
> + * wt-status.c#wt_status_collect_untracked(), and the evaluation
> + * of the config setting in commit.c#git_status_config()
> + */
> + char *status_untracked_files_config_value;
> + int config_outcome = repo_config_get_string(repo,
> + "status.showuntrackedfiles",
> + &status_untracked_files_config_value);
> + if (!config_outcome && !strcmp(status_untracked_files_config_value, "all")) {
> + return 0;
> + } else {
> + /*
> + * The default, if "all" is not set, is "normal" - leading us here.
> + * If the value is "none" then it really doesn't matter.
> + */
> + return DIR_SHOW_OTHER_DIRECTORIES | DIR_HIDE_EMPTY_DIRECTORIES;
> + }
> +}
> +
> [...]
In reviewing this I found the addition of very long lines & indentation
made this a bit harder to read. I came up with the below which should be
squashable on top, and perhaps makes this easier to read.
I.e. the one caller that needs custom flags passes them, others pass -1
now.
For throwaway "char *" variables we usually use "char *p", "char *val"
or whatever. A "status_untracked_files_config_value" is a bit much for
something function local whose body is <10 lines of code.
And if you drop the "int config_outcome" + rename the variable the
repo_config_get_string() fits on one line:
diff --git a/dir.c b/dir.c
index 57a7d42482f..22a27d7780f 100644
--- a/dir.c
+++ b/dir.c
@@ -2746,34 +2746,33 @@ static void set_untracked_ident(struct untracked_cache *uc)
strbuf_addch(&uc->ident, 0);
}
-static unsigned configured_default_dir_flags(struct repository *repo)
+static unsigned new_untracked_cache_flags(struct index_state *istate)
{
+ struct repository *repo = istate->repo;
+ char *val;
+
/*
* This logic is coordinated with the setting of these flags in
* wt-status.c#wt_status_collect_untracked(), and the evaluation
* of the config setting in commit.c#git_status_config()
*/
- char *status_untracked_files_config_value;
- int config_outcome = repo_config_get_string(repo,
- "status.showuntrackedfiles",
- &status_untracked_files_config_value);
- if (!config_outcome && !strcmp(status_untracked_files_config_value, "all")) {
+ if (!repo_config_get_string(repo, "status.showuntrackedfiles", &val) &&
+ !strcmp(val, "all"))
return 0;
- } else {
- /*
- * The default, if "all" is not set, is "normal" - leading us here.
- * If the value is "none" then it really doesn't matter.
- */
- return DIR_SHOW_OTHER_DIRECTORIES | DIR_HIDE_EMPTY_DIRECTORIES;
- }
+
+ /*
+ * The default, if "all" is not set, is "normal" - leading us here.
+ * If the value is "none" then it really doesn't matter.
+ */
+ return DIR_SHOW_OTHER_DIRECTORIES | DIR_HIDE_EMPTY_DIRECTORIES;
}
-static void new_untracked_cache(struct index_state *istate, unsigned flags)
+static void new_untracked_cache(struct index_state *istate, int flags)
{
struct untracked_cache *uc = xcalloc(1, sizeof(*uc));
strbuf_init(&uc->ident, 100);
uc->exclude_per_dir = ".gitignore";
- uc->dir_flags = flags;
+ uc->dir_flags = flags >= 0 ? flags : new_untracked_cache_flags(istate);
set_untracked_ident(uc);
istate->untracked = uc;
istate->cache_changed |= UNTRACKED_CHANGED;
@@ -2782,13 +2781,11 @@ static void new_untracked_cache(struct index_state *istate, unsigned flags)
void add_untracked_cache(struct index_state *istate)
{
if (!istate->untracked) {
- new_untracked_cache(istate,
- configured_default_dir_flags(istate->repo));
+ new_untracked_cache(istate, -1);
} else {
if (!ident_in_untracked(istate->untracked)) {
free_untracked_cache(istate->untracked);
- new_untracked_cache(istate,
- configured_default_dir_flags(istate->repo));
+ new_untracked_cache(istate, -1);
}
}
}
@@ -2866,7 +2863,7 @@ static struct untracked_cache_dir *validate_untracked_cache(struct dir_struct *d
* the current effective flags don't match the configured
* flags.
*/
- if (dir->flags != configured_default_dir_flags(istate->repo))
+ if (dir->flags != new_untracked_cache_flags(istate))
return NULL;
/*
next prev parent reply other threads:[~2022-02-28 14:08 UTC|newest]
Thread overview: 22+ messages / expand[flat|nested] mbox.gz Atom feed top
2021-06-23 6:44 [PATCH] Support untracked cache with '--untracked-files=all' if configured Tao Klerks via GitGitGadget
2022-02-25 17:52 ` [PATCH v2] untracked-cache: support " Tao Klerks via GitGitGadget
2022-02-25 19:43 ` Junio C Hamano
2022-02-27 11:21 ` Tao Klerks
2022-02-27 19:54 ` Junio C Hamano
2022-02-27 11:22 ` [PATCH v3] " Tao Klerks via GitGitGadget
2022-02-27 14:39 ` Tao Klerks
2022-02-27 15:13 ` [PATCH v4] " Tao Klerks via GitGitGadget
2022-02-28 14:02 ` Ævar Arnfjörð Bjarmason [this message]
2022-03-02 8:47 ` Tao Klerks
2022-03-29 11:25 ` [PATCH v5 0/2] Support untracked cache with " Tao Klerks via GitGitGadget
2022-03-29 11:25 ` [PATCH v5 1/2] untracked-cache: test untracked-cache-bypassing behavior with -uall Tao Klerks via GitGitGadget
2022-03-29 16:51 ` Junio C Hamano
2022-03-30 4:46 ` Tao Klerks
2022-03-30 16:39 ` Junio C Hamano
2022-03-31 5:15 ` Tao Klerks
2022-03-29 11:25 ` [PATCH v5 2/2] untracked-cache: support '--untracked-files=all' if configured Tao Klerks via GitGitGadget
2022-03-29 17:43 ` Junio C Hamano
2022-03-30 19:59 ` Tao Klerks
2022-03-31 16:02 ` [PATCH v6 0/2] Support untracked cache with " Tao Klerks via GitGitGadget
2022-03-31 16:02 ` [PATCH v6 1/2] untracked-cache: test untracked-cache-bypassing behavior with -uall Tao Klerks via GitGitGadget
2022-03-31 16:02 ` [PATCH v6 2/2] untracked-cache: support '--untracked-files=all' if configured Tao Klerks via GitGitGadget
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
List information: http://vger.kernel.org/majordomo-info.html
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=220228.86y21v3wyj.gmgdl@evledraar.gmail.com \
--to=avarab@gmail.com \
--cc=git@vger.kernel.org \
--cc=gitgitgadget@gmail.com \
--cc=tao@klerks.biz \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
Code repositories for project(s) associated with this public inbox
https://80x24.org/mirrors/git.git
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).