MCPcopy Create free account
hub / github.com/git/git / grep_submodule

Function grep_submodule

builtin/grep.c:446–546  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

444 int check_attr);
445
446static int grep_submodule(struct grep_opt *opt,
447 const struct pathspec *pathspec,
448 const struct object_id *oid,
449 const char *filename, const char *path, int cached)
450{
451 struct repository *subrepo;
452 struct repository *superproject = opt->repo;
453 struct grep_opt subopt;
454 int hit = 0;
455
456 if (!is_submodule_active(superproject, path))
457 return 0;
458
459 subrepo = xmalloc(sizeof(*subrepo));
460 if (repo_submodule_init(subrepo, superproject, path, null_oid(opt->repo->hash_algo))) {
461 free(subrepo);
462 return 0;
463 }
464 ALLOC_GROW(repos_to_free, repos_to_free_nr + 1, repos_to_free_alloc);
465 repos_to_free[repos_to_free_nr++] = subrepo;
466
467 /*
468 * NEEDSWORK: repo_read_gitmodules() might call
469 * odb_add_to_alternates_memory() via config_from_gitmodules(). This
470 * operation causes a race condition with concurrent object readings
471 * performed by the worker threads. That's why we need obj_read_lock()
472 * here. It should be removed once it's no longer necessary to add the
473 * subrepo's odbs to the in-memory alternates list.
474 */
475 obj_read_lock();
476
477 /*
478 * NEEDSWORK: when reading a submodule, the sparsity settings in the
479 * superproject are incorrectly forgotten or misused. For example:
480 *
481 * 1. "command_requires_full_index"
482 * When this setting is turned on for `grep`, only the superproject
483 * knows it. All the submodules are read with their own configs
484 * and get prepare_repo_settings()'d. Therefore, these submodules
485 * "forget" the sparse-index feature switch. As a result, the index
486 * of these submodules are expanded unexpectedly.
487 *
488 * 2. "config_values_private_.apply_sparse_checkout"
489 * When running `grep` in the superproject, this setting is
490 * populated using the superproject's configs. However, once
491 * initialized, this config is globally accessible and is read by
492 * prepare_repo_settings() for the submodules. For instance, if a
493 * submodule is using a sparse-checkout, however, the superproject
494 * is not, the result is that the config from the superproject will
495 * dictate the behavior for the submodule, making it "forget" its
496 * sparse-checkout state.
497 *
498 * 3. "core_sparse_checkout_cone"
499 * ditto.
500 *
501 * Note that this list is not exhaustive.
502 */
503 repo_read_gitmodules(subrepo, 0);

Callers 2

grep_cacheFunction · 0.85
grep_treeFunction · 0.85

Calls 15

is_submodule_activeFunction · 0.85
repo_submodule_initFunction · 0.85
null_oidFunction · 0.85
obj_read_lockFunction · 0.85
repo_read_gitmodulesFunction · 0.85
obj_read_unlockFunction · 0.85
odb_read_object_infoFunction · 0.85
odb_read_object_peeledFunction · 0.85
oid_to_hexFunction · 0.85
strbuf_addstrFunction · 0.85
strbuf_addchFunction · 0.85

Tested by

no test coverage detected