Commit
8751a0ffc30dc91233f968d064fe913b3eeba885
submodule-config: remove uses of `the_repository`
Several functions in the submodule-config subsystem implicitly depend on `the_repository`. Refactor these to take a `struct repository` as parameter and adapt callers accordingly. Note that as usual with these refactorings, callers simply pass `the_repository` even if they already have a different repository available in the calling context. This simplifies the migration and ensures that we don't have a change in behaviour. Signed-off-by: Patrick Steinhardt <ps@pks.im> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Patrick Steinhardt <ps@pks.im> · 2026-09-11 05:51 UTC · committed by Junio C Hamano
7 files changed,
+45
−34
- builtin/fetch.c
- builtin/grep.c
- builtin/submodule--helper.c
- submodule-config.c
- submodule-config.h
- submodule.c
- t/helper/test-submodule.c
modified builtin/fetch.c
| @@ -2681,7 +2681,7 @@ int cmd_fetch(int argc, | |||
| 2681 | 2681 | int *rs = config.recurse_submodules == RECURSE_SUBMODULES_DEFAULT | |
| 2682 | 2682 | ? &config.recurse_submodules : NULL; | |
| 2683 | 2683 | ||
| 2684 | - | fetch_config_from_gitmodules(sfjc, rs); | |
| 2684 | + | fetch_config_from_gitmodules(the_repository, sfjc, rs); | |
| 2685 | 2685 | } | |
| 2686 | 2686 | ||
| 2687 | 2687 | ||
modified builtin/grep.c
| @@ -897,7 +897,7 @@ static int grep_objects(struct grep_opt *opt, const struct pathspec *pathspec, | |||
| 897 | 897 | if (recurse_submodules) { | |
| 898 | 898 | submodule_free(opt->repo); | |
| 899 | 899 | obj_read_lock(); | |
| 900 | - | gitmodules_config_oid(&real_obj->oid); | |
| 900 | + | gitmodules_config_oid(the_repository, &real_obj->oid); | |
| 901 | 901 | obj_read_unlock(); | |
| 902 | 902 | } | |
| 903 | 903 | if (grep_object(opt, pathspec, real_obj, list->objects[i].name, | |
modified builtin/submodule--helper.c
| @@ -3041,7 +3041,7 @@ static int module_update(int argc, const char **argv, const char *prefix, | |||
| 3041 | 3041 | NULL | |
| 3042 | 3042 | }; | |
| 3043 | 3043 | ||
| 3044 | - | update_clone_config_from_gitmodules(&opt.max_jobs); | |
| 3044 | + | update_clone_config_from_gitmodules(the_repository, &opt.max_jobs); | |
| 3045 | 3045 | repo_config(the_repository, git_update_clone_config, &opt.max_jobs); | |
| 3046 | 3046 | ||
| 3047 | 3047 | argc = parse_options(argc, argv, prefix, module_update_options, | |
| @@ -3255,7 +3255,7 @@ static int module_set_url(int argc, const char **argv, const char *prefix, | |||
| 3255 | 3255 | path); | |
| 3256 | 3256 | ||
| 3257 | 3257 | config_name = xstrfmt("submodule.%s.url", sub->name); | |
| 3258 | - | ret = config_set_in_gitmodules_file_gently(config_name, newurl); | |
| 3258 | + | ret = config_set_in_gitmodules_file_gently(the_repository, config_name, newurl); | |
| 3259 | 3259 | ||
| 3260 | 3260 | if (!ret) { | |
| 3261 | 3261 | repo_read_gitmodules(the_repository, 0); | |
| @@ -3311,7 +3311,7 @@ static int module_set_branch(int argc, const char **argv, const char *prefix, | |||
| 3311 | 3311 | path); | |
| 3312 | 3312 | ||
| 3313 | 3313 | config_name = xstrfmt("submodule.%s.branch", sub->name); | |
| 3314 | - | ret = config_set_in_gitmodules_file_gently(config_name, opt_branch); | |
| 3314 | + | ret = config_set_in_gitmodules_file_gently(the_repository, config_name, opt_branch); | |
| 3315 | 3315 | ||
| 3316 | 3316 | free(config_name); | |
| 3317 | 3317 | return !!ret; | |
| @@ -3510,7 +3510,7 @@ static int config_submodule_in_gitmodules(const char *name, const char *var, con | |||
| 3510 | 3510 | die(_("please make sure that the .gitmodules file is in the working tree")); | |
| 3511 | 3511 | ||
| 3512 | 3512 | key = xstrfmt("submodule.%s.%s", name, var); | |
| 3513 | - | ret = config_set_in_gitmodules_file_gently(key, value); | |
| 3513 | + | ret = config_set_in_gitmodules_file_gently(the_repository, key, value); | |
| 3514 | 3514 | free(key); | |
| 3515 | 3515 | ||
| 3516 | 3516 | return ret; | |
modified submodule-config.c
| @@ -667,19 +667,20 @@ static int parse_config(const char *var, const char *value, | |||
| 667 | 667 | return ret; | |
| 668 | 668 | } | |
| 669 | 669 | ||
| 670 | - | static int gitmodule_oid_from_commit(const struct object_id *treeish_name, | |
| 670 | + | static int gitmodule_oid_from_commit(struct repository *repo, | |
| 671 | + | const struct object_id *treeish_name, | |
| 671 | 672 | struct object_id *gitmodules_oid, | |
| 672 | 673 | struct strbuf *rev) | |
| 673 | 674 | { | |
| 674 | 675 | int ret = 0; | |
| 675 | 676 | ||
| 676 | 677 | if (is_null_oid(treeish_name)) { | |
| 677 | - | oidclr(gitmodules_oid, the_repository->hash_algo); | |
| 678 | + | oidclr(gitmodules_oid, repo->hash_algo); | |
| 678 | 679 | return 1; | |
| 679 | 680 | } | |
| 680 | 681 | ||
| 681 | 682 | strbuf_addf(rev, "%s:.gitmodules", oid_to_hex(treeish_name)); | |
| 682 | - | if (repo_get_oid(the_repository, rev->buf, gitmodules_oid) >= 0) | |
| 683 | + | if (repo_get_oid(repo, rev->buf, gitmodules_oid) >= 0) | |
| 683 | 684 | ret = 1; | |
| 684 | 685 | ||
| 685 | 686 | return ret; | |
| @@ -689,9 +690,11 @@ static int gitmodule_oid_from_commit(const struct object_id *treeish_name, | |||
| 689 | 690 | * (key) with on-demand reading of the appropriate .gitmodules from | |
| 690 | 691 | * revisions. | |
| 691 | 692 | */ | |
| 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) | |
| 693 | + | static const struct submodule *config_from(struct repository *repo, | |
| 694 | + | struct submodule_cache *cache, | |
| 695 | + | const struct object_id *treeish_name, | |
| 696 | + | const char *key, | |
| 697 | + | enum lookup_type lookup_type) | |
| 695 | 698 | { | |
| 696 | 699 | struct strbuf rev = STRBUF_INIT; | |
| 697 | 700 | size_t config_size; | |
| @@ -718,7 +721,7 @@ static const struct submodule *config_from(struct submodule_cache *cache, | |||
| 718 | 721 | return entry->config; | |
| 719 | 722 | } | |
| 720 | 723 | ||
| 721 | - | if (!gitmodule_oid_from_commit(treeish_name, &oid, &rev)) | |
| 724 | + | if (!gitmodule_oid_from_commit(repo, treeish_name, &oid, &rev)) | |
| 722 | 725 | goto out; | |
| 723 | 726 | ||
| 724 | 727 | switch (lookup_type) { | |
| @@ -732,7 +735,7 @@ static const struct submodule *config_from(struct submodule_cache *cache, | |||
| 732 | 735 | if (submodule) | |
| 733 | 736 | goto out; | |
| 734 | 737 | ||
| 735 | - | config = odb_read_object(the_repository->objects, &oid, | |
| 738 | + | config = odb_read_object(repo->objects, &oid, | |
| 736 | 739 | &type, &config_size); | |
| 737 | 740 | if (!config || type != OBJ_BLOB) | |
| 738 | 741 | goto out; | |
| @@ -843,21 +846,22 @@ void repo_read_gitmodules(struct repository *repo, int skip_if_read) | |||
| 843 | 846 | repo->submodule_cache->gitmodules_read = 1; | |
| 844 | 847 | } | |
| 845 | 848 | ||
| 846 | - | void gitmodules_config_oid(const struct object_id *commit_oid) | |
| 849 | + | void gitmodules_config_oid(struct repository *repo, | |
| 850 | + | const struct object_id *commit_oid) | |
| 847 | 851 | { | |
| 848 | 852 | struct strbuf rev = STRBUF_INIT; | |
| 849 | 853 | struct object_id oid; | |
| 850 | 854 | ||
| 851 | - | submodule_cache_check_init(the_repository); | |
| 855 | + | submodule_cache_check_init(repo); | |
| 852 | 856 | ||
| 853 | - | if (gitmodule_oid_from_commit(commit_oid, &oid, &rev)) { | |
| 857 | + | if (gitmodule_oid_from_commit(repo, commit_oid, &oid, &rev)) { | |
| 854 | 858 | git_config_from_blob_oid(gitmodules_cb, rev.buf, | |
| 855 | - | the_repository, &oid, the_repository, | |
| 859 | + | repo, &oid, repo, | |
| 856 | 860 | CONFIG_SCOPE_UNKNOWN); | |
| 857 | 861 | } | |
| 858 | 862 | strbuf_release(&rev); | |
| 859 | 863 | ||
| 860 | - | the_repository->submodule_cache->gitmodules_read = 1; | |
| 864 | + | repo->submodule_cache->gitmodules_read = 1; | |
| 861 | 865 | } | |
| 862 | 866 | ||
| 863 | 867 | const struct submodule *submodule_from_name(struct repository *r, | |
| @@ -865,7 +869,7 @@ const struct submodule *submodule_from_name(struct repository *r, | |||
| 865 | 869 | const char *name) | |
| 866 | 870 | { | |
| 867 | 871 | repo_read_gitmodules(r, 1); | |
| 868 | - | return config_from(r->submodule_cache, treeish_name, name, lookup_name); | |
| 872 | + | return config_from(r, r->submodule_cache, treeish_name, name, lookup_name); | |
| 869 | 873 | } | |
| 870 | 874 | ||
| 871 | 875 | const struct submodule *submodule_from_path(struct repository *r, | |
| @@ -873,7 +877,7 @@ const struct submodule *submodule_from_path(struct repository *r, | |||
| 873 | 877 | const char *path) | |
| 874 | 878 | { | |
| 875 | 879 | repo_read_gitmodules(r, 1); | |
| 876 | - | return config_from(r->submodule_cache, treeish_name, path, lookup_path); | |
| 880 | + | return config_from(r, r->submodule_cache, treeish_name, path, lookup_path); | |
| 877 | 881 | } | |
| 878 | 882 | ||
| 879 | 883 | /** | |
| @@ -980,11 +984,12 @@ int print_config_from_gitmodules(struct repository *repo, const char *key) | |||
| 980 | 984 | return 0; | |
| 981 | 985 | } | |
| 982 | 986 | ||
| 983 | - | int config_set_in_gitmodules_file_gently(const char *key, const char *value) | |
| 987 | + | int config_set_in_gitmodules_file_gently(struct repository *repo, | |
| 988 | + | const char *key, const char *value) | |
| 984 | 989 | { | |
| 985 | 990 | int ret; | |
| 986 | 991 | ||
| 987 | - | ret = repo_config_set_in_file_gently(the_repository, GITMODULES_FILE, key, NULL, value); | |
| 992 | + | ret = repo_config_set_in_file_gently(repo, GITMODULES_FILE, key, NULL, value); | |
| 988 | 993 | if (ret < 0) | |
| 989 | 994 | /* Maybe the user already did that, don't error out here */ | |
| 990 | 995 | warning(_("Could not update .gitmodules entry %s"), key); | |
| @@ -1017,13 +1022,15 @@ static int gitmodules_fetch_config(const char *var, const char *value, | |||
| 1017 | 1022 | return 0; | |
| 1018 | 1023 | } | |
| 1019 | 1024 | ||
| 1020 | - | void fetch_config_from_gitmodules(int *max_children, int *recurse_submodules) | |
| 1025 | + | void fetch_config_from_gitmodules(struct repository *repo, | |
| 1026 | + | int *max_children, | |
| 1027 | + | int *recurse_submodules) | |
| 1021 | 1028 | { | |
| 1022 | 1029 | struct fetch_config config = { | |
| 1023 | 1030 | .max_children = max_children, | |
| 1024 | 1031 | .recurse_submodules = recurse_submodules | |
| 1025 | 1032 | }; | |
| 1026 | - | config_from_gitmodules(gitmodules_fetch_config, the_repository, &config); | |
| 1033 | + | config_from_gitmodules(gitmodules_fetch_config, repo, &config); | |
| 1027 | 1034 | } | |
| 1028 | 1035 | ||
| 1029 | 1036 | static int gitmodules_update_clone_config(const char *var, const char *value, | |
| @@ -1036,7 +1043,7 @@ static int gitmodules_update_clone_config(const char *var, const char *value, | |||
| 1036 | 1043 | return 0; | |
| 1037 | 1044 | } | |
| 1038 | 1045 | ||
| 1039 | - | void update_clone_config_from_gitmodules(int *max_jobs) | |
| 1046 | + | void update_clone_config_from_gitmodules(struct repository *repo, int *max_jobs) | |
| 1040 | 1047 | { | |
| 1041 | - | config_from_gitmodules(gitmodules_update_clone_config, the_repository, max_jobs); | |
| 1048 | + | config_from_gitmodules(gitmodules_update_clone_config, repo, max_jobs); | |
| 1042 | 1049 | } | |
modified submodule-config.h
| @@ -57,7 +57,8 @@ int option_fetch_parse_recurse_submodules(const struct option *opt, | |||
| 57 | 57 | int parse_update_recurse_submodules_arg(const char *opt, const char *arg); | |
| 58 | 58 | int parse_push_recurse_submodules_arg(const char *opt, const char *arg); | |
| 59 | 59 | void repo_read_gitmodules(struct repository *repo, int skip_if_read); | |
| 60 | - | void gitmodules_config_oid(const struct object_id *commit_oid); | |
| 60 | + | void gitmodules_config_oid(struct repository *repo, | |
| 61 | + | const struct object_id *commit_oid); | |
| 61 | 62 | ||
| 62 | 63 | /** | |
| 63 | 64 | * Same as submodule_from_path but lookup by name. | |
| @@ -80,7 +81,8 @@ const struct submodule *submodule_from_path(struct repository *r, | |||
| 80 | 81 | void submodule_free(struct repository *r); | |
| 81 | 82 | ||
| 82 | 83 | int print_config_from_gitmodules(struct repository *repo, const char *key); | |
| 83 | - | int config_set_in_gitmodules_file_gently(const char *key, const char *value); | |
| 84 | + | int config_set_in_gitmodules_file_gently(struct repository *repo, | |
| 85 | + | const char *key, const char *value); | |
| 84 | 86 | ||
| 85 | 87 | /* | |
| 86 | 88 | * Returns 0 if the name is syntactically acceptable as a submodule "name" | |
| @@ -100,8 +102,10 @@ int check_submodule_url(const char *url); | |||
| 100 | 102 | * New helpers to retrieve arbitrary configuration from the '.gitmodules' file | |
| 101 | 103 | * should NOT be added. | |
| 102 | 104 | */ | |
| 103 | - | void fetch_config_from_gitmodules(int *max_children, int *recurse_submodules); | |
| 104 | - | void update_clone_config_from_gitmodules(int *max_jobs); | |
| 105 | + | void fetch_config_from_gitmodules(struct repository *repo, | |
| 106 | + | int *max_children, | |
| 107 | + | int *recurse_submodules); | |
| 108 | + | void update_clone_config_from_gitmodules(struct repository *repo, int *max_jobs); | |
| 105 | 109 | ||
| 106 | 110 | /* | |
| 107 | 111 | * Submodule entry that contains relevant information about a | |
modified submodule.c
| @@ -133,7 +133,7 @@ int update_path_in_gitmodules(const char *oldpath, const char *newpath) | |||
| 133 | 133 | strbuf_addstr(&entry, "submodule."); | |
| 134 | 134 | strbuf_addstr(&entry, submodule->name); | |
| 135 | 135 | strbuf_addstr(&entry, ".path"); | |
| 136 | - | ret = config_set_in_gitmodules_file_gently(entry.buf, newpath); | |
| 136 | + | ret = config_set_in_gitmodules_file_gently(the_repository, entry.buf, newpath); | |
| 137 | 137 | strbuf_release(&entry); | |
| 138 | 138 | return ret; | |
| 139 | 139 | } | |
modified t/helper/test-submodule.c
| @@ -168,7 +168,7 @@ static int cmd__submodule_config_set(int argc, const char **argv) | |||
| 168 | 168 | if (!is_writing_gitmodules_ok()) | |
| 169 | 169 | die("please make sure that the .gitmodules file is in the working tree"); | |
| 170 | 170 | ||
| 171 | - | return config_set_in_gitmodules_file_gently(argv[1], argv[2]); | |
| 171 | + | return config_set_in_gitmodules_file_gently(the_repository, argv[1], argv[2]); | |
| 172 | 172 | } | |
| 173 | 173 | usage_with_options(usage, options); | |
| 174 | 174 | } | |
| @@ -188,7 +188,7 @@ static int cmd__submodule_config_unset(int argc, const char **argv) | |||
| 188 | 188 | if (argc == 2) { | |
| 189 | 189 | if (!is_writing_gitmodules_ok()) | |
| 190 | 190 | die("please make sure that the .gitmodules file is in the working tree"); | |
| 191 | - | return config_set_in_gitmodules_file_gently(argv[1], NULL); | |
| 191 | + | return config_set_in_gitmodules_file_gently(the_repository, argv[1], NULL); | |
| 192 | 192 | } | |
| 193 | 193 | usage_with_options(usage, options); | |
| 194 | 194 | } | |