Browse Source

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>
maint
Stefan Beller 7 years ago committed by Junio C Hamano
parent
commit
3b8fb393bc
  1. 14
      builtin/submodule--helper.c
  2. 14
      submodule-config.c
  3. 10
      submodule-config.h
  4. 30
      submodule.c
  5. 6
      t/helper/test-submodule-config.c

14
builtin/submodule--helper.c

@ -455,7 +455,7 @@ static void init_submodule(const char *path, const char *prefix,


displaypath = get_submodule_displaypath(path, prefix); displaypath = get_submodule_displaypath(path, prefix);


sub = submodule_from_path(&null_oid, path); sub = submodule_from_path(the_repository, &null_oid, path);


if (!sub) if (!sub)
die(_("No url found for submodule path '%s' in .gitmodules"), 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,
struct rev_info rev; struct rev_info rev;
int diff_files_result; int diff_files_result;


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


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


sub = submodule_from_path(&null_oid, argv[1]); sub = submodule_from_path(the_repository, &null_oid, argv[1]);


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


sub = submodule_from_path(&null_oid, path); sub = submodule_from_path(the_repository, &null_oid, path);


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


sub = submodule_from_path(&null_oid, path); sub = submodule_from_path(the_repository, &null_oid, path);


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


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


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


sub = submodule_from_path(&null_oid, path); sub = submodule_from_path(the_repository, &null_oid, path);
if (!sub) if (!sub)
return NULL; return NULL;



14
submodule-config.c

@ -619,18 +619,20 @@ static void gitmodules_read_check(struct repository *repo)
repo_read_gitmodules(repo); repo_read_gitmodules(repo);
} }


const struct submodule *submodule_from_name(const struct object_id *treeish_name, const struct submodule *submodule_from_name(struct repository *r,
const struct object_id *treeish_name,
const char *name) const char *name)
{ {
gitmodules_read_check(the_repository); gitmodules_read_check(r);
return config_from(the_repository->submodule_cache, treeish_name, name, lookup_name); return config_from(r->submodule_cache, treeish_name, name, lookup_name);
} }


const struct submodule *submodule_from_path(const struct object_id *treeish_name, const struct submodule *submodule_from_path(struct repository *r,
const struct object_id *treeish_name,
const char *path) const char *path)
{ {
gitmodules_read_check(the_repository); gitmodules_read_check(r);
return config_from(the_repository->submodule_cache, treeish_name, path, lookup_path); return config_from(r->submodule_cache, treeish_name, path, lookup_path);
} }


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

10
submodule-config.h

@ -39,10 +39,12 @@ extern int parse_update_recurse_submodules_arg(const char *opt, const char *arg)
extern int parse_push_recurse_submodules_arg(const char *opt, const char *arg); extern int parse_push_recurse_submodules_arg(const char *opt, const char *arg);
extern void repo_read_gitmodules(struct repository *repo); extern void repo_read_gitmodules(struct repository *repo);
extern void gitmodules_config_oid(const struct object_id *commit_oid); extern void gitmodules_config_oid(const struct object_id *commit_oid);
extern const struct submodule *submodule_from_name( const struct submodule *submodule_from_name(struct repository *r,
const struct object_id *commit_or_tree, const char *name); const struct object_id *commit_or_tree,
extern const struct submodule *submodule_from_path( const char *name);
const struct object_id *commit_or_tree, const char *path); const struct submodule *submodule_from_path(struct repository *r,
const struct object_id *commit_or_tree,
const char *path);
extern const struct submodule *submodule_from_cache(struct repository *repo, extern const struct submodule *submodule_from_cache(struct repository *repo,
const struct object_id *treeish_name, const struct object_id *treeish_name,
const char *key); const char *key);

30
submodule.c

@ -96,7 +96,7 @@ int update_path_in_gitmodules(const char *oldpath, const char *newpath)
if (is_gitmodules_unmerged(&the_index)) if (is_gitmodules_unmerged(&the_index))
die(_("Cannot change unmerged .gitmodules, resolve merge conflicts first")); die(_("Cannot change unmerged .gitmodules, resolve merge conflicts first"));


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


submodule = submodule_from_path(&null_oid, path); submodule = submodule_from_path(the_repository, &null_oid, path);
if (!submodule || !submodule->name) { if (!submodule || !submodule->name) {
warning(_("Could not find section in .gitmodules where path=%s"), path); warning(_("Could not find section in .gitmodules where path=%s"), path);
return -1; return -1;
@ -174,7 +174,8 @@ done:
void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt, void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
const char *path) const char *path)
{ {
const struct submodule *submodule = submodule_from_path(&null_oid, path); const struct submodule *submodule = submodule_from_path(the_repository,
&null_oid, path);
if (submodule) { if (submodule) {
const char *ignore; const char *ignore;
char *key; char *key;
@ -674,7 +675,7 @@ const struct submodule *submodule_from_ce(const struct cache_entry *ce)
if (!should_update_submodules()) if (!should_update_submodules())
return NULL; return NULL;


return submodule_from_path(&null_oid, ce->name); return submodule_from_path(the_repository, &null_oid, ce->name);
} }


static struct oid_array *submodule_commits(struct string_list *submodules, 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,
if (!S_ISGITLINK(p->two->mode)) if (!S_ISGITLINK(p->two->mode))
continue; continue;


submodule = submodule_from_path(commit_oid, p->two->path); submodule = submodule_from_path(the_repository,
commit_oid, p->two->path);
if (submodule) if (submodule)
name = submodule->name; name = submodule->name;
else { else {
name = default_name_or_path(p->two->path); name = default_name_or_path(p->two->path);
/* make sure name does not collide with existing one */ /* make sure name does not collide with existing one */
submodule = submodule_from_name(commit_oid, name); submodule = submodule_from_name(the_repository, commit_oid, name);
if (submodule) { if (submodule) {
warning("Submodule in commit %s at path: " warning("Submodule in commit %s at path: "
"'%s' collides with a submodule named " "'%s' collides with a submodule named "
@ -945,7 +947,7 @@ int find_unpushed_submodules(struct oid_array *commits,
const struct submodule *submodule; const struct submodule *submodule;
const char *path = NULL; const char *path = NULL;


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


/* No need to check if there are no submodules configured */ /* No need to check if there are no submodules configured */
if (!submodule_from_path(NULL, NULL)) if (!submodule_from_path(the_repository, NULL, NULL))
return; return;


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


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


/* No need to check if there are no submodules configured */ /* No need to check if there are no submodules configured */
if (!submodule_from_path(NULL, NULL)) if (!submodule_from_path(the_repository, NULL, NULL))
return 0; return 0;


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


sub = submodule_from_path(&null_oid, path); sub = submodule_from_path(the_repository, &null_oid, path);


if (!sub) if (!sub)
die("BUG: could not get submodule information for '%s'", path); 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,


real_old_git_dir = real_pathdup(old_git_dir, 1); real_old_git_dir = real_pathdup(old_git_dir, 1);


sub = submodule_from_path(&null_oid, path); sub = submodule_from_path(the_repository, &null_oid, path);
if (!sub) if (!sub)
die(_("could not lookup name for submodule '%s'"), path); die(_("could not lookup name for submodule '%s'"), path);


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

6
t/helper/test-submodule-config.c

@ -48,9 +48,11 @@ int cmd_main(int argc, const char **argv)
die_usage(argc, argv, "Commit not found."); die_usage(argc, argv, "Commit not found.");


if (lookup_name) { if (lookup_name) {
submodule = submodule_from_name(&commit_oid, path_or_name); submodule = submodule_from_name(the_repository,
&commit_oid, path_or_name);
} else } else
submodule = submodule_from_path(&commit_oid, path_or_name); submodule = submodule_from_path(the_repository,
&commit_oid, path_or_name);
if (!submodule) if (!submodule)
die_usage(argc, argv, "Submodule not found."); die_usage(argc, argv, "Submodule not found.");



Loading…
Cancel
Save