This does a lookup of a submodule configuration by name or by path * (key) with on-demand reading of the appropriate .gitmodules from * revisions. */
| 690 | * revisions. |
| 691 | */ |
| 692 | static const struct submodule *config_from(struct submodule_cache *cache, |
| 693 | const struct object_id *treeish_name, const char *key, |
| 694 | enum lookup_type lookup_type) |
| 695 | { |
| 696 | struct strbuf rev = STRBUF_INIT; |
| 697 | size_t config_size; |
| 698 | char *config = NULL; |
| 699 | struct object_id oid; |
| 700 | enum object_type type; |
| 701 | const struct submodule *submodule = NULL; |
| 702 | struct parse_config_parameter parameter; |
| 703 | |
| 704 | /* |
| 705 | * If any parameter except the cache is a NULL pointer just |
| 706 | * return the first submodule. Can be used to check whether |
| 707 | * there are any submodules parsed. |
| 708 | */ |
| 709 | if (!treeish_name || !key) { |
| 710 | struct hashmap_iter iter; |
| 711 | struct submodule_entry *entry; |
| 712 | |
| 713 | entry = hashmap_iter_first_entry(&cache->for_name, &iter, |
| 714 | struct submodule_entry, |
| 715 | ent /* member name */); |
| 716 | if (!entry) |
| 717 | return NULL; |
| 718 | return entry->config; |
| 719 | } |
| 720 | |
| 721 | if (!gitmodule_oid_from_commit(treeish_name, &oid, &rev)) |
| 722 | goto out; |
| 723 | |
| 724 | switch (lookup_type) { |
| 725 | case lookup_name: |
| 726 | submodule = cache_lookup_name(cache, &oid, key); |
| 727 | break; |
| 728 | case lookup_path: |
| 729 | submodule = cache_lookup_path(cache, &oid, key); |
| 730 | break; |
| 731 | } |
| 732 | if (submodule) |
| 733 | goto out; |
| 734 | |
| 735 | config = odb_read_object(the_repository->objects, &oid, |
| 736 | &type, &config_size); |
| 737 | if (!config || type != OBJ_BLOB) |
| 738 | goto out; |
| 739 | |
| 740 | /* fill the submodule config into the cache */ |
| 741 | parameter.cache = cache; |
| 742 | parameter.treeish_name = treeish_name; |
| 743 | parameter.gitmodules_oid = &oid; |
| 744 | parameter.overwrite = 0; |
| 745 | git_config_from_mem(parse_config, CONFIG_ORIGIN_SUBMODULE_BLOB, rev.buf, |
| 746 | config, config_size, ¶meter, CONFIG_SCOPE_UNKNOWN, NULL); |
| 747 | strbuf_release(&rev); |
| 748 | free(config); |
| 749 |
no test coverage detected