submodules: load gitmodules file from commit sha1
[gitweb.git] / submodule.c
index 6f7d883de950af8ba6427537d09e021a4bed36bd..260090898acf4701a96c51d13cf4834d107f5c55 100644 (file)
@@ -198,6 +198,56 @@ void gitmodules_config(void)
        }
 }
 
+void gitmodules_config_sha1(const unsigned char *commit_sha1)
+{
+       struct strbuf rev = STRBUF_INIT;
+       unsigned char sha1[20];
+
+       if (gitmodule_sha1_from_commit(commit_sha1, sha1, &rev)) {
+               git_config_from_blob_sha1(submodule_config, rev.buf,
+                                         sha1, NULL);
+       }
+       strbuf_release(&rev);
+}
+
+/*
+ * Determine if a submodule has been initialized at a given 'path'
+ */
+int is_submodule_initialized(const char *path)
+{
+       int ret = 0;
+       const struct submodule *module = NULL;
+
+       module = submodule_from_path(null_sha1, path);
+
+       if (module) {
+               char *key = xstrfmt("submodule.%s.url", module->name);
+               char *value = NULL;
+
+               ret = !git_config_get_string(key, &value);
+
+               free(value);
+               free(key);
+       }
+
+       return ret;
+}
+
+/*
+ * Determine if a submodule has been populated at a given 'path'
+ */
+int is_submodule_populated(const char *path)
+{
+       int ret = 0;
+       char *gitdir = xstrfmt("%s/.git", path);
+
+       if (resolve_gitdir(gitdir))
+               ret = 1;
+
+       free(gitdir);
+       return ret;
+}
+
 int parse_submodule_update_strategy(const char *value,
                struct submodule_update_strategy *dst)
 {
@@ -1227,7 +1277,7 @@ void connect_work_tree_and_git_dir(const char *work_tree, const char *git_dir)
 {
        struct strbuf file_name = STRBUF_INIT;
        struct strbuf rel_path = STRBUF_INIT;
-       const char *real_work_tree = xstrdup(real_path(work_tree));
+       const char *real_work_tree = real_pathdup(work_tree);
 
        /* Update gitfile */
        strbuf_addf(&file_name, "%s/.git", work_tree);