repository: repo_submodule_init to take a submodule struct
[gitweb.git] / repository.c
index 5dd148671811b383a64b8f3adab87804cea9db08..aabe64ee5d9da82db68e4d4dc2072d58bd9ed4ab 100644 (file)
@@ -166,30 +166,23 @@ int repo_init(struct repository *repo,
        return -1;
 }
 
-/*
- * Initialize 'submodule' as the submodule given by 'path' in parent repository
- * 'superproject'.
- * Return 0 upon success and a non-zero value upon failure.
- */
-int repo_submodule_init(struct repository *submodule,
+int repo_submodule_init(struct repository *subrepo,
                        struct repository *superproject,
-                       const char *path)
+                       const struct submodule *sub)
 {
-       const struct submodule *sub;
        struct strbuf gitdir = STRBUF_INIT;
        struct strbuf worktree = STRBUF_INIT;
        int ret = 0;
 
-       sub = submodule_from_path(superproject, &null_oid, path);
        if (!sub) {
                ret = -1;
                goto out;
        }
 
-       strbuf_repo_worktree_path(&gitdir, superproject, "%s/.git", path);
-       strbuf_repo_worktree_path(&worktree, superproject, "%s", path);
+       strbuf_repo_worktree_path(&gitdir, superproject, "%s/.git", sub->path);
+       strbuf_repo_worktree_path(&worktree, superproject, "%s", sub->path);
 
-       if (repo_init(submodule, gitdir.buf, worktree.buf)) {
+       if (repo_init(subrepo, gitdir.buf, worktree.buf)) {
                /*
                 * If initilization fails then it may be due to the submodule
                 * not being populated in the superproject's worktree.  Instead
@@ -201,16 +194,16 @@ int repo_submodule_init(struct repository *submodule,
                strbuf_repo_git_path(&gitdir, superproject,
                                     "modules/%s", sub->name);
 
-               if (repo_init(submodule, gitdir.buf, NULL)) {
+               if (repo_init(subrepo, gitdir.buf, NULL)) {
                        ret = -1;
                        goto out;
                }
        }
 
-       submodule->submodule_prefix = xstrfmt("%s%s/",
-                                             superproject->submodule_prefix ?
-                                             superproject->submodule_prefix :
-                                             "", path);
+       subrepo->submodule_prefix = xstrfmt("%s%s/",
+                                           superproject->submodule_prefix ?
+                                           superproject->submodule_prefix :
+                                           "", sub->path);
 
 out:
        strbuf_release(&gitdir);