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 <jonathantanmy@google.com> Signed-off-by: Stefan Beller <sbeller@google.com> Reviewed-by: Jonathan Tan <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Stefan Beller committed
Mar 28, 2018 at 15:35 UTC
3b8fb393bc32f8d96c2eb4c89349c864e5c56039
5 files changed
+41
-33
builtin/submodule--helper.c
+7
-7
@@ -455,7 +455,7 @@ static void init_submodule(const char *path, const char *prefix,
455
456
displaypath = get_submodule_displaypath(path, prefix);
457
458
- sub = submodule_from_path(&null_oid, path);
458
+ sub = submodule_from_path(the_repository, &null_oid, path);
459
460
if (!sub)
461
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,
622
struct rev_info rev;
623
int diff_files_result;
624
625
- if (!submodule_from_path(&null_oid, path))
625
+ if (!submodule_from_path(the_repository, &null_oid, path))
626
die(_("no submodule mapping found in .gitmodules for path '%s'"),
627
path);
628
@@ -742,7 +742,7 @@ static int module_name(int argc, const char **argv, const char *prefix)
742
if (argc != 2)
743
usage(_("git submodule--helper name <path>"));
744
745
- sub = submodule_from_path(&null_oid, argv[1]);
745
+ sub = submodule_from_path(the_repository, &null_oid, argv[1]);
746
747
if (!sub)
748
die(_("no submodule mapping found in .gitmodules for path '%s'"),
@@ -773,7 +773,7 @@ static void sync_submodule(const char *path, const char *prefix,
773
if (!is_submodule_active(the_repository, path))
774
return;
775
776
- sub = submodule_from_path(&null_oid, path);
776
+ sub = submodule_from_path(the_repository, &null_oid, path);
777
778
if (sub && sub->url) {
779
if (starts_with_dot_dot_slash(sub->url) ||
@@ -926,7 +926,7 @@ static void deinit_submodule(const char *path, const char *prefix,
926
struct strbuf sb_config = STRBUF_INIT;
927
char *sub_git_dir = xstrfmt("%s/.git", path);
928
929
- sub = submodule_from_path(&null_oid, path);
929
+ sub = submodule_from_path(the_repository, &null_oid, path);
930
931
if (!sub || !sub->name)
932
goto cleanup;
@@ -1368,7 +1368,7 @@ static int prepare_to_clone_next_submodule(const struct cache_entry *ce,
1368
goto cleanup;
1369
}
1370
1371
- sub = submodule_from_path(&null_oid, ce->name);
1371
+ sub = submodule_from_path(the_repository, &null_oid, ce->name);
1372
1373
if (suc->recursive_prefix)
1374
displaypath = relative_path(suc->recursive_prefix,
@@ -1651,7 +1651,7 @@ static const char *remote_submodule_branch(const char *path)
1651
const char *branch = NULL;
1652
char *key;
1653
1654
- sub = submodule_from_path(&null_oid, path);
1654
+ sub = submodule_from_path(the_repository, &null_oid, path);
1655
if (!sub)
1656
return NULL;
1657
submodule-config.c
+8
-6
@@ -619,18 +619,20 @@ static void gitmodules_read_check(struct repository *repo)
619
repo_read_gitmodules(repo);
620
}
621
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,
624
const char *name)
625
{
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);
628
}
629
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,
632
const char *path)
633
{
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);
636
}
637
638
const struct submodule *submodule_from_cache(struct repository *repo,
submodule-config.h
+6
-4
@@ -39,10 +39,12 @@ extern int parse_update_recurse_submodules_arg(const char *opt, const char *arg)
39
extern int parse_push_recurse_submodules_arg(const char *opt, const char *arg);
40
extern void repo_read_gitmodules(struct repository *repo);
41
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);
48
extern const struct submodule *submodule_from_cache(struct repository *repo,
49
const struct object_id *treeish_name,
50
const char *key);
submodule.c
+16
-14
@@ -96,7 +96,7 @@ int update_path_in_gitmodules(const char *oldpath, const char *newpath)
96
if (is_gitmodules_unmerged(&the_index))
97
die(_("Cannot change unmerged .gitmodules, resolve merge conflicts first"));
98
99
- submodule = submodule_from_path(&null_oid, oldpath);
99
+ submodule = submodule_from_path(the_repository, &null_oid, oldpath);
100
if (!submodule || !submodule->name) {
101
warning(_("Could not find section in .gitmodules where path=%s"), oldpath);
102
return -1;
@@ -130,7 +130,7 @@ int remove_path_from_gitmodules(const char *path)
130
if (is_gitmodules_unmerged(&the_index))
131
die(_("Cannot change unmerged .gitmodules, resolve merge conflicts first"));
132
133
- submodule = submodule_from_path(&null_oid, path);
133
+ submodule = submodule_from_path(the_repository, &null_oid, path);
134
if (!submodule || !submodule->name) {
135
warning(_("Could not find section in .gitmodules where path=%s"), path);
136
return -1;
@@ -174,7 +174,8 @@ done:
174
void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
175
const char *path)
176
{
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);
179
if (submodule) {
180
const char *ignore;
181
char *key;
@@ -674,7 +675,7 @@ const struct submodule *submodule_from_ce(const struct cache_entry *ce)
675
if (!should_update_submodules())
676
return NULL;
677
677
- return submodule_from_path(&null_oid, ce->name);
678
+ return submodule_from_path(the_repository, &null_oid, ce->name);
679
}
680
681
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,
732
if (!S_ISGITLINK(p->two->mode))
733
continue;
734
734
- submodule = submodule_from_path(commit_oid, p->two->path);
735
+ submodule = submodule_from_path(the_repository,
736
+ commit_oid, p->two->path);
737
if (submodule)
738
name = submodule->name;
739
else {
740
name = default_name_or_path(p->two->path);
741
/* 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);
743
if (submodule) {
744
warning("Submodule in commit %s at path: "
745
"'%s' collides with a submodule named "
@@ -945,7 +947,7 @@ int find_unpushed_submodules(struct oid_array *commits,
947
const struct submodule *submodule;
948
const char *path = NULL;
949
948
- submodule = submodule_from_name(&null_oid, name->string);
950
+ submodule = submodule_from_name(the_repository, &null_oid, name->string);
951
if (submodule)
952
path = submodule->path;
953
else
@@ -1113,7 +1115,7 @@ static void calculate_changed_submodule_paths(void)
1115
const struct string_list_item *name;
1116
1117
/* 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))
1119
return;
1120
1121
argv_array_push(&argv, "--"); /* argv[0] program name */
@@ -1134,7 +1136,7 @@ static void calculate_changed_submodule_paths(void)
1136
const struct submodule *submodule;
1137
const char *path = NULL;
1138
1137
- submodule = submodule_from_name(&null_oid, name->string);
1139
+ submodule = submodule_from_name(the_repository, &null_oid, name->string);
1140
if (submodule)
1141
path = submodule->path;
1142
else
@@ -1162,7 +1164,7 @@ int submodule_touches_in_range(struct object_id *excl_oid,
1164
int ret;
1165
1166
/* 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))
1168
return 0;
1169
1170
argv_array_push(&args, "--"); /* args[0] program name */
@@ -1604,7 +1606,7 @@ int submodule_move_head(const char *path,
1606
if (old && !is_submodule_populated_gently(path, error_code_ptr))
1607
return 0;
1608
1607
- sub = submodule_from_path(&null_oid, path);
1609
+ sub = submodule_from_path(the_repository, &null_oid, path);
1610
1611
if (!sub)
1612
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,
1888
1889
real_old_git_dir = real_pathdup(old_git_dir, 1);
1890
1889
- sub = submodule_from_path(&null_oid, path);
1891
+ sub = submodule_from_path(the_repository, &null_oid, path);
1892
if (!sub)
1893
die(_("could not lookup name for submodule '%s'"), path);
1894
@@ -1942,7 +1944,7 @@ void absorb_git_dir_into_superproject(const char *prefix,
1944
* superproject did not rewrite the git file links yet,
1945
* fix it now.
1946
*/
1945
- sub = submodule_from_path(&null_oid, path);
1947
+ sub = submodule_from_path(the_repository, &null_oid, path);
1948
if (!sub)
1949
die(_("could not lookup name for submodule '%s'"), path);
1950
connect_work_tree_and_git_dir(path,
@@ -2088,7 +2090,7 @@ int submodule_to_gitdir(struct strbuf *buf, const char *submodule)
2090
strbuf_addstr(buf, git_dir);
2091
}
2092
if (!is_git_directory(buf->buf)) {
2091
- sub = submodule_from_path(&null_oid, submodule);
2093
+ sub = submodule_from_path(the_repository, &null_oid, submodule);
2094
if (!sub) {
2095
ret = -1;
2096
goto cleanup;
t/helper/test-submodule-config.c
+4
-2
@@ -48,9 +48,11 @@ int cmd_main(int argc, const char **argv)
48
die_usage(argc, argv, "Commit not found.");
49
50
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);
53
} else
53
- submodule = submodule_from_path(&commit_oid, path_or_name);
54
+ submodule = submodule_from_path(the_repository,
55
+ &commit_oid, path_or_name);
56
if (!submodule)
57
die_usage(argc, argv, "Submodule not found.");
58