"Alessio Attilio via GitGitGadget" <gitg…@gmail.com> writes:
> diff --git a/builtin/commit.c b/builtin/commit.c
> index 36e47e18ed..577b097aa0 100644
> --- a/builtin/commit.c
> +++ b/builtin/commit.c
> @@ -1636,6 +1636,7 @@ struct repository *repo UNUSED)
>
> s.ignore_submodule_arg = ignore_submodule_arg;
> s.status_format = status_format;
> + s.check_submodule_urls = 1;
The hunk header unfortunately is hard to read but this is inside
cmd_status().
Now whichever format wt_status_print() is triggered with, we will show
the submodule changes but only when the top-level command is "git
status".
Good.
> diff --git a/wt-status.c b/wt-status.c
> ...
> +static int submodule_has_custom_remote_url(struct repository *repo,
> + const char *path,
> + const char *gitmodules_url,
> + const char *config_url)
> +{
> + struct repository subrepo = { 0 };
> + const struct string_list *remote_urls = NULL;
> + const char *remote;
> + const char *remote_url;
> + char *key, *up_path, *config_remote_url, *gitmodules_remote_url;
> + int error_code, ret = 0;
> +
> + if (!is_submodule_populated_gently(path, &error_code))
> + return 0;
> +
> + if (repo_submodule_init(&subrepo, repo, path,
> + null_oid(repo->hash_algo)) < 0) {
> + repo_clear(&subrepo);
> + return 0;
> + }
> +
> + remote = repo_default_remote(&subrepo);
> +
> + key = xstrfmt("remote.%s.url", remote);
> + if (!repo_config_get_value_multi(&subrepo, key, &remote_urls) &&
> + remote_urls->nr == 1 &&
> + (remote_url = remote_urls->items[0].string)) {
The third condition being a non-NULL check of the value and not a
comparison can easily become confusing. GNU toolchains seem to
encourage putting such a "var = value" assignment that is also used for
a non-NULL/0 check inside an extra pair of parentheses, which is the
convention the above code also uses. Use of the _get_value_ variant and
checking the NULL-ness of .string allows us to cope with a valueless
truth "[remote "frotz"] url;" cleanly.
> +static int submodule_has_custom_remote_url(struct repository *repo,
> + const char *path,
> + const char *gitmodules_url,
> + const char *config_url)
> +{
> + struct repository subrepo = { 0 };
> + const struct string_list *remote_urls = NULL;
> + const char *remote;
> + const char *remote_url;
> + char *key, *up_path, *config_remote_url, *gitmodules_remote_url;
> + int error_code, ret = 0;
> +
> + if (!is_submodule_populated_gently(path, &error_code))
> + return 0;
> +
> + if (repo_submodule_init(&subrepo, repo, path,
> + null_oid(repo->hash_algo)) < 0) {
> + repo_clear(&subrepo);
> + return 0;
> + }
Do we see a small inconsistency with the repository-aware design from
the previous patch here?
This function takes 'repo' and passes it to repo_submodule_init() and
resolve_submodule_url(), yet is_submodule_populated_gently() inspects
"%s/.git" relative to the current working directory rather than the
'.worktree' member of 'repo'.
That may be harmless today because cmd_status() runs with NEED_WORK_TREE
and repo == the_repository, so we are always at the worktree root. It
might be worth a comment near the call to is_submodule_populated_gently()
though.
> +static void wt_status_check_submodule_urls(struct wt_status *s)
> +{
> + int i;
> +
> + if (s->ignore_submodule_arg &&
> + !strcmp(s->ignore_submodule_arg, "all"))
> + return;
> +
> + if (is_gitmodules_unmerged(s->repo->index))
> + return;
> +
> + for (i = 0; i < s->repo->index->cache_nr; i++) {
> + struct cache_entry *ce = s->repo->index->cache[i];
Because cmd_status() sets '.command_requires_full_index' to 0, you need
to be careful when iterating '.cache' directly like the above loop when
sparse-index is in effect.
In sparse-index.c, convert_to_sparse_rec() refuses to collapse any
directory containing S_ISGITLINK entries, so I _think_ gitlinks remain
visible even in a sparse index, but please double check.
Overall, this iteration was a very pleasant read.
Thanks for working on it.