submodules: load gitmodules file from commit sha1
authorBrandon Williams <bmwill@google.com>
Fri, 16 Dec 2016 19:03:18 +0000 (11:03 -0800)
committerJunio C Hamano <gitster@pobox.com>
Thu, 22 Dec 2016 19:47:33 +0000 (11:47 -0800)
teach submodules to load a '.gitmodules' file from a commit sha1. This
enables the population of the submodule_cache to be based on the state
of the '.gitmodules' file from a particular commit.

Signed-off-by: Brandon Williams <bmwill@google.com>
Signed-off-by: Junio C Hamano <gitster@pobox.com>
cache.h
config.c
submodule-config.c
submodule-config.h
submodule.c
submodule.h
diff --git a/cache.h b/cache.h
index e12a5d9129b9382a7c2155f740672dce9d0a3280..de237cab6b760c74f9858952473465a5875e4ac5 100644 (file)
--- a/cache.h
+++ b/cache.h
@@ -1693,6 +1693,8 @@ extern int git_default_config(const char *, const char *, void *);
 extern int git_config_from_file(config_fn_t fn, const char *, void *);
 extern int git_config_from_mem(config_fn_t fn, const enum config_origin_type,
                                        const char *name, const char *buf, size_t len, void *data);
+extern int git_config_from_blob_sha1(config_fn_t fn, const char *name,
+                                    const unsigned char *sha1, void *data);
 extern void git_config_push_parameter(const char *text);
 extern int git_config_from_parameters(config_fn_t fn, void *data);
 extern void git_config(config_fn_t fn, void *);
index 83fdecb1bc9f6f31bc625c79c1d3c12ba5b27f77..4d78e7227c4f5d2337c62a53e19aeba2f4e6c5f7 100644 (file)
--- a/config.c
+++ b/config.c
@@ -1214,10 +1214,10 @@ int git_config_from_mem(config_fn_t fn, const enum config_origin_type origin_typ
        return do_config_from(&top, fn, data);
 }
 
-static int git_config_from_blob_sha1(config_fn_t fn,
-                                    const char *name,
-                                    const unsigned char *sha1,
-                                    void *data)
+int git_config_from_blob_sha1(config_fn_t fn,
+                             const char *name,
+                             const unsigned char *sha1,
+                             void *data)
 {
        enum object_type type;
        char *buf;
index 098085be69b97687b0febfe9e29c6dc0c64569a1..8b9a2ef2888c3f12563b9392b4254905211e5aa5 100644 (file)
@@ -379,9 +379,9 @@ static int parse_config(const char *var, const char *value, void *data)
        return ret;
 }
 
-static int gitmodule_sha1_from_commit(const unsigned char *commit_sha1,
-                                     unsigned char *gitmodules_sha1,
-                                     struct strbuf *rev)
+int gitmodule_sha1_from_commit(const unsigned char *commit_sha1,
+                              unsigned char *gitmodules_sha1,
+                              struct strbuf *rev)
 {
        int ret = 0;
 
index d05c542d2cdace181ea72055c0f71db6b1afda42..78584ba6a715f38ebe5c30b7617c84afbc657fa0 100644 (file)
@@ -29,6 +29,9 @@ const struct submodule *submodule_from_name(const unsigned char *commit_sha1,
                const char *name);
 const struct submodule *submodule_from_path(const unsigned char *commit_sha1,
                const char *path);
+extern int gitmodule_sha1_from_commit(const unsigned char *commit_sha1,
+                                     unsigned char *gitmodules_sha1,
+                                     struct strbuf *rev);
 void submodule_free(void);
 
 #endif /* SUBMODULE_CONFIG_H */
index edffaa186bb4087b874aa5d1c8c93f24dfe7b3ce..260090898acf4701a96c51d13cf4834d107f5c55 100644 (file)
@@ -198,6 +198,18 @@ 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'
  */
index 6ec5f2f207c7a0f209b8f1c537dc78fed27eedda..9203d89a595a9c959a6a99ea51ac52a52860d23c 100644 (file)
@@ -37,6 +37,7 @@ void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
                const char *path);
 int submodule_config(const char *var, const char *value, void *cb);
 void gitmodules_config(void);
+extern void gitmodules_config_sha1(const unsigned char *commit_sha1);
 extern int is_submodule_initialized(const char *path);
 extern int is_submodule_populated(const char *path);
 int parse_submodule_update_strategy(const char *value,