Re: [PATCH v7 11/11] submodule: detect conflicts with existing gitdir configs
On Sat, Dec 20, 2025 at 12:15:28PM +0200, Adrian Ratiu wrote:
Show 51 quoted lines
> diff --git a/submodule.c b/submodule.c
> index 834c794b7d..d778e8eca7 100644
> --- a/submodule.c
> +++ b/submodule.c
> @@ -2289,6 +2289,61 @@ static int check_casefolding_conflict(const char *git_dir,
> return ret;
> }
>
> +struct submodule_from_gitdir_cb {
> + const char *gitdir;
> + const char *submodule_name;
> + bool conflict_found;
> +};
> +
> +static int find_conflict_by_gitdir_cb(const char *var, const char *value,
> + const struct config_context *ctx UNUSED, void *data)
> +{
> + struct submodule_from_gitdir_cb *cb = data;
> + const char *submodule_name_start;
> + size_t submodule_name_len;
> + const char *suffix = ".gitdir";
> + size_t suffix_len = strlen(suffix);
> +
> + if (!skip_prefix(var, "submodule.", &submodule_name_start))
> + return 0;
> +
> + /* Check if submodule_name_start ends with ".gitdir" */
> + submodule_name_len = strlen(submodule_name_start);
> + if (submodule_name_len < suffix_len ||
> + strcmp(submodule_name_start + submodule_name_len - suffix_len, suffix) != 0)
> + return 0; /* Does not end with ".gitdir" */
> +
> + submodule_name_len -= suffix_len;
> +
> + /*
> + * A conflict happens if:
> + * 1. The submodule names are different and
> + * 2. The gitdir paths resolve to the same absolute path
> + */
> + if (value && strncmp(cb->submodule_name, submodule_name_start, submodule_name_len)) {
> + char *abs_path_cb = absolute_pathdup(cb->gitdir);
> + char *abs_path_value = absolute_pathdup(value);
> +
> + cb->conflict_found = !strcmp(abs_path_cb, abs_path_value);
> +
> + free(abs_path_cb);
> + free(abs_path_value);
> + }
> +
> + return cb->conflict_found;
> +}Nit: empty line missing between these two functions.
Patrick