| 2309 | }; |
| 2310 | |
| 2311 | static int find_conflict_by_gitdir_cb(const char *var, const char *value, |
| 2312 | const struct config_context *ctx UNUSED, void *data) |
| 2313 | { |
| 2314 | struct submodule_from_gitdir_cb *cb = data; |
| 2315 | const char *submodule_name_start; |
| 2316 | size_t submodule_name_len; |
| 2317 | const char *suffix = ".gitdir"; |
| 2318 | size_t suffix_len = strlen(suffix); |
| 2319 | |
| 2320 | if (!skip_prefix(var, "submodule.", &submodule_name_start)) |
| 2321 | return 0; |
| 2322 | |
| 2323 | /* Check if submodule_name_start ends with ".gitdir" */ |
| 2324 | submodule_name_len = strlen(submodule_name_start); |
| 2325 | if (submodule_name_len < suffix_len || |
| 2326 | strcmp(submodule_name_start + submodule_name_len - suffix_len, suffix) != 0) |
| 2327 | return 0; /* Does not end with ".gitdir" */ |
| 2328 | |
| 2329 | submodule_name_len -= suffix_len; |
| 2330 | |
| 2331 | /* |
| 2332 | * A conflict happens if: |
| 2333 | * 1. The submodule names are different and |
| 2334 | * 2. The gitdir paths resolve to the same absolute path |
| 2335 | */ |
| 2336 | if (value && strncmp(cb->submodule_name, submodule_name_start, submodule_name_len)) { |
| 2337 | char *abs_path_cb = absolute_pathdup(cb->gitdir); |
| 2338 | char *abs_path_value = absolute_pathdup(value); |
| 2339 | |
| 2340 | cb->conflict_found = !strcmp(abs_path_cb, abs_path_value); |
| 2341 | |
| 2342 | free(abs_path_cb); |
| 2343 | free(abs_path_value); |
| 2344 | } |
| 2345 | |
| 2346 | return cb->conflict_found; |
| 2347 | } |
| 2348 | |
| 2349 | static bool submodule_conflicts_with_existing(const char *gitdir, const char *submodule_name) |
| 2350 | { |
nothing calls this directly
no test coverage detected