Skip to content

Commit 3b8fb39

Browse files
stefanbellergitster
authored andcommitted
submodule-config: add repository argument to submodule_from_{name, path}
This enables submodule_from_{name, path} to handle arbitrary repositories. All callers just pass in the_repository, a later patch will pass in other repos. While at it remove the extern key word from the declarations. Reviewed-by: Jonathan Tan <[email protected]> Signed-off-by: Stefan Beller <[email protected]> Reviewed-by: Jonathan Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f793b89 commit 3b8fb39

File tree

5 files changed

+41
-33
lines changed

5 files changed

+41
-33
lines changed

builtin/submodule--helper.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -455,7 +455,7 @@ static void init_submodule(const char *path, const char *prefix,
455455

456456
displaypath = get_submodule_displaypath(path, prefix);
457457

458-
sub = submodule_from_path(&null_oid, path);
458+
sub = submodule_from_path(the_repository, &null_oid, path);
459459

460460
if (!sub)
461461
die(_("No url found for submodule path '%s' in .gitmodules"),
@@ -622,7 +622,7 @@ static void status_submodule(const char *path, const struct object_id *ce_oid,
622622
struct rev_info rev;
623623
int diff_files_result;
624624

625-
if (!submodule_from_path(&null_oid, path))
625+
if (!submodule_from_path(the_repository, &null_oid, path))
626626
die(_("no submodule mapping found in .gitmodules for path '%s'"),
627627
path);
628628

@@ -742,7 +742,7 @@ static int module_name(int argc, const char **argv, const char *prefix)
742742
if (argc != 2)
743743
usage(_("git submodule--helper name <path>"));
744744

745-
sub = submodule_from_path(&null_oid, argv[1]);
745+
sub = submodule_from_path(the_repository, &null_oid, argv[1]);
746746

747747
if (!sub)
748748
die(_("no submodule mapping found in .gitmodules for path '%s'"),
@@ -773,7 +773,7 @@ static void sync_submodule(const char *path, const char *prefix,
773773
if (!is_submodule_active(the_repository, path))
774774
return;
775775

776-
sub = submodule_from_path(&null_oid, path);
776+
sub = submodule_from_path(the_repository, &null_oid, path);
777777

778778
if (sub && sub->url) {
779779
if (starts_with_dot_dot_slash(sub->url) ||
@@ -926,7 +926,7 @@ static void deinit_submodule(const char *path, const char *prefix,
926926
struct strbuf sb_config = STRBUF_INIT;
927927
char *sub_git_dir = xstrfmt("%s/.git", path);
928928

929-
sub = submodule_from_path(&null_oid, path);
929+
sub = submodule_from_path(the_repository, &null_oid, path);
930930

931931
if (!sub || !sub->name)
932932
goto cleanup;
@@ -1368,7 +1368,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
13681368
goto cleanup;
13691369
}
13701370

1371-
sub = submodule_from_path(&null_oid, ce->name);
1371+
sub = submodule_from_path(the_repository, &null_oid, ce->name);
13721372

13731373
if (suc->recursive_prefix)
13741374
displaypath = relative_path(suc->recursive_prefix,
@@ -1651,7 +1651,7 @@ static const char *remote_submodule_branch(const char *path)
16511651
const char *branch = NULL;
16521652
char *key;
16531653

1654-
sub = submodule_from_path(&null_oid, path);
1654+
sub = submodule_from_path(the_repository, &null_oid, path);
16551655
if (!sub)
16561656
return NULL;
16571657

submodule-config.c

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -619,18 +619,20 @@ static void gitmodules_read_check(struct repository *repo)
619619
repo_read_gitmodules(repo);
620620
}
621621

622-
const struct submodule *submodule_from_name(const struct object_id *treeish_name,
622+
const struct submodule *submodule_from_name(struct repository *r,
623+
const struct object_id *treeish_name,
623624
const char *name)
624625
{
625-
gitmodules_read_check(the_repository);
626-
return config_from(the_repository->submodule_cache, treeish_name, name, lookup_name);
626+
gitmodules_read_check(r);
627+
return config_from(r->submodule_cache, treeish_name, name, lookup_name);
627628
}
628629

629-
const struct submodule *submodule_from_path(const struct object_id *treeish_name,
630+
const struct submodule *submodule_from_path(struct repository *r,
631+
const struct object_id *treeish_name,
630632
const char *path)
631633
{
632-
gitmodules_read_check(the_repository);
633-
return config_from(the_repository->submodule_cache, treeish_name, path, lookup_path);
634+
gitmodules_read_check(r);
635+
return config_from(r->submodule_cache, treeish_name, path, lookup_path);
634636
}
635637

636638
const struct submodule *submodule_from_cache(struct repository *repo,

submodule-config.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,10 +39,12 @@ extern int parse_update_recurse_submodules_arg(const char *opt, const char *arg)
3939
extern int parse_push_recurse_submodules_arg(const char *opt, const char *arg);
4040
extern void repo_read_gitmodules(struct repository *repo);
4141
extern void gitmodules_config_oid(const struct object_id *commit_oid);
42-
extern const struct submodule *submodule_from_name(
43-
const struct object_id *commit_or_tree, const char *name);
44-
extern const struct submodule *submodule_from_path(
45-
const struct object_id *commit_or_tree, const char *path);
42+
const struct submodule *submodule_from_name(struct repository *r,
43+
const struct object_id *commit_or_tree,
44+
const char *name);
45+
const struct submodule *submodule_from_path(struct repository *r,
46+
const struct object_id *commit_or_tree,
47+
const char *path);
4648
extern const struct submodule *submodule_from_cache(struct repository *repo,
4749
const struct object_id *treeish_name,
4850
const char *key);

submodule.c

Lines changed: 16 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ int update_path_in_gitmodules(const char *oldpath, const char *newpath)
9696
if (is_gitmodules_unmerged(&the_index))
9797
die(_("Cannot change unmerged .gitmodules, resolve merge conflicts first"));
9898

99-
submodule = submodule_from_path(&null_oid, oldpath);
99+
submodule = submodule_from_path(the_repository, &null_oid, oldpath);
100100
if (!submodule || !submodule->name) {
101101
warning(_("Could not find section in .gitmodules where path=%s"), oldpath);
102102
return -1;
@@ -130,7 +130,7 @@ int remove_path_from_gitmodules(const char *path)
130130
if (is_gitmodules_unmerged(&the_index))
131131
die(_("Cannot change unmerged .gitmodules, resolve merge conflicts first"));
132132

133-
submodule = submodule_from_path(&null_oid, path);
133+
submodule = submodule_from_path(the_repository, &null_oid, path);
134134
if (!submodule || !submodule->name) {
135135
warning(_("Could not find section in .gitmodules where path=%s"), path);
136136
return -1;
@@ -174,7 +174,8 @@ static int add_submodule_odb(const char *path)
174174
void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
175175
const char *path)
176176
{
177-
const struct submodule *submodule = submodule_from_path(&null_oid, path);
177+
const struct submodule *submodule = submodule_from_path(the_repository,
178+
&null_oid, path);
178179
if (submodule) {
179180
const char *ignore;
180181
char *key;
@@ -674,7 +675,7 @@ const struct submodule *submodule_from_ce(const struct cache_entry *ce)
674675
if (!should_update_submodules())
675676
return NULL;
676677

677-
return submodule_from_path(&null_oid, ce->name);
678+
return submodule_from_path(the_repository, &null_oid, ce->name);
678679
}
679680

680681
static struct oid_array *submodule_commits(struct string_list *submodules,
@@ -731,13 +732,14 @@ static void collect_changed_submodules_cb(struct diff_queue_struct *q,
731732
if (!S_ISGITLINK(p->two->mode))
732733
continue;
733734

734-
submodule = submodule_from_path(commit_oid, p->two->path);
735+
submodule = submodule_from_path(the_repository,
736+
commit_oid, p->two->path);
735737
if (submodule)
736738
name = submodule->name;
737739
else {
738740
name = default_name_or_path(p->two->path);
739741
/* make sure name does not collide with existing one */
740-
submodule = submodule_from_name(commit_oid, name);
742+
submodule = submodule_from_name(the_repository, commit_oid, name);
741743
if (submodule) {
742744
warning("Submodule in commit %s at path: "
743745
"'%s' collides with a submodule named "
@@ -945,7 +947,7 @@ int find_unpushed_submodules(struct oid_array *commits,
945947
const struct submodule *submodule;
946948
const char *path = NULL;
947949

948-
submodule = submodule_from_name(&null_oid, name->string);
950+
submodule = submodule_from_name(the_repository, &null_oid, name->string);
949951
if (submodule)
950952
path = submodule->path;
951953
else
@@ -1113,7 +1115,7 @@ static void calculate_changed_submodule_paths(void)
11131115
const struct string_list_item *name;
11141116

11151117
/* No need to check if there are no submodules configured */
1116-
if (!submodule_from_path(NULL, NULL))
1118+
if (!submodule_from_path(the_repository, NULL, NULL))
11171119
return;
11181120

11191121
argv_array_push(&argv, "--"); /* argv[0] program name */
@@ -1134,7 +1136,7 @@ static void calculate_changed_submodule_paths(void)
11341136
const struct submodule *submodule;
11351137
const char *path = NULL;
11361138

1137-
submodule = submodule_from_name(&null_oid, name->string);
1139+
submodule = submodule_from_name(the_repository, &null_oid, name->string);
11381140
if (submodule)
11391141
path = submodule->path;
11401142
else
@@ -1162,7 +1164,7 @@ int submodule_touches_in_range(struct object_id *excl_oid,
11621164
int ret;
11631165

11641166
/* No need to check if there are no submodules configured */
1165-
if (!submodule_from_path(NULL, NULL))
1167+
if (!submodule_from_path(the_repository, NULL, NULL))
11661168
return 0;
11671169

11681170
argv_array_push(&args, "--"); /* args[0] program name */
@@ -1604,7 +1606,7 @@ int submodule_move_head(const char *path,
16041606
if (old && !is_submodule_populated_gently(path, error_code_ptr))
16051607
return 0;
16061608

1607-
sub = submodule_from_path(&null_oid, path);
1609+
sub = submodule_from_path(the_repository, &null_oid, path);
16081610

16091611
if (!sub)
16101612
die("BUG: could not get submodule information for '%s'", path);
@@ -1886,7 +1888,7 @@ static void relocate_single_git_dir_into_superproject(const char *prefix,
18861888

18871889
real_old_git_dir = real_pathdup(old_git_dir, 1);
18881890

1889-
sub = submodule_from_path(&null_oid, path);
1891+
sub = submodule_from_path(the_repository, &null_oid, path);
18901892
if (!sub)
18911893
die(_("could not lookup name for submodule '%s'"), path);
18921894

@@ -1942,7 +1944,7 @@ void absorb_git_dir_into_superproject(const char *prefix,
19421944
* superproject did not rewrite the git file links yet,
19431945
* fix it now.
19441946
*/
1945-
sub = submodule_from_path(&null_oid, path);
1947+
sub = submodule_from_path(the_repository, &null_oid, path);
19461948
if (!sub)
19471949
die(_("could not lookup name for submodule '%s'"), path);
19481950
connect_work_tree_and_git_dir(path,
@@ -2088,7 +2090,7 @@ int submodule_to_gitdir(struct strbuf *buf, const char *submodule)
20882090
strbuf_addstr(buf, git_dir);
20892091
}
20902092
if (!is_git_directory(buf->buf)) {
2091-
sub = submodule_from_path(&null_oid, submodule);
2093+
sub = submodule_from_path(the_repository, &null_oid, submodule);
20922094
if (!sub) {
20932095
ret = -1;
20942096
goto cleanup;

t/helper/test-submodule-config.c

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,9 +48,11 @@ int cmd_main(int argc, const char **argv)
4848
die_usage(argc, argv, "Commit not found.");
4949

5050
if (lookup_name) {
51-
submodule = submodule_from_name(&commit_oid, path_or_name);
51+
submodule = submodule_from_name(the_repository,
52+
&commit_oid, path_or_name);
5253
} else
53-
submodule = submodule_from_path(&commit_oid, path_or_name);
54+
submodule = submodule_from_path(the_repository,
55+
&commit_oid, path_or_name);
5456
if (!submodule)
5557
die_usage(argc, argv, "Submodule not found.");
5658

0 commit comments

Comments
 (0)