submodules: load gitmodules file from commit sha1
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>
Brandon Williams committed
Dec 16, 2016 at 11:03 UTC
9ebf689aad72bfc091da21e1d73a05308f1ace85
6 files changed
+25
-7
cache.h
+2
@@ -1693,6 +1693,8 @@ extern int git_default_config(const char *, const char *, void *);
1693
extern int git_config_from_file(config_fn_t fn, const char *, void *);
1694
extern int git_config_from_mem(config_fn_t fn, const enum config_origin_type,
1695
const char *name, const char *buf, size_t len, void *data);
1696
+extern int git_config_from_blob_sha1(config_fn_t fn, const char *name,
1697
+ const unsigned char *sha1, void *data);
1698
extern void git_config_push_parameter(const char *text);
1699
extern int git_config_from_parameters(config_fn_t fn, void *data);
1700
extern void git_config(config_fn_t fn, void *);
config.c
+4
-4
@@ -1214,10 +1214,10 @@ int git_config_from_mem(config_fn_t fn, const enum config_origin_type origin_typ
1214
return do_config_from(&top, fn, data);
1215
}
1216
1217
-static int git_config_from_blob_sha1(config_fn_t fn,
1218
- const char *name,
1219
- const unsigned char *sha1,
1220
- void *data)
1217
+int git_config_from_blob_sha1(config_fn_t fn,
1218
+ const char *name,
1219
+ const unsigned char *sha1,
1220
+ void *data)
1221
{
1222
enum object_type type;
1223
char *buf;
submodule-config.c
+3
-3
@@ -379,9 +379,9 @@ static int parse_config(const char *var, const char *value, void *data)
379
return ret;
380
}
381
382
-static int gitmodule_sha1_from_commit(const unsigned char *commit_sha1,
383
- unsigned char *gitmodules_sha1,
384
- struct strbuf *rev)
382
+int gitmodule_sha1_from_commit(const unsigned char *commit_sha1,
383
+ unsigned char *gitmodules_sha1,
384
+ struct strbuf *rev)
385
{
386
int ret = 0;
387
submodule-config.h
+3
@@ -29,6 +29,9 @@ const struct submodule *submodule_from_name(const unsigned char *commit_sha1,
29
const char *name);
30
const struct submodule *submodule_from_path(const unsigned char *commit_sha1,
31
const char *path);
32
+extern int gitmodule_sha1_from_commit(const unsigned char *commit_sha1,
33
+ unsigned char *gitmodules_sha1,
34
+ struct strbuf *rev);
35
void submodule_free(void);
36
37
#endif /* SUBMODULE_CONFIG_H */
submodule.c
+12
@@ -198,6 +198,18 @@ void gitmodules_config(void)
198
}
199
}
200
201
+void gitmodules_config_sha1(const unsigned char *commit_sha1)
202
+{
203
+ struct strbuf rev = STRBUF_INIT;
204
+ unsigned char sha1[20];
205
+
206
+ if (gitmodule_sha1_from_commit(commit_sha1, sha1, &rev)) {
207
+ git_config_from_blob_sha1(submodule_config, rev.buf,
208
+ sha1, NULL);
209
+ }
210
+ strbuf_release(&rev);
211
+}
212
+
213
/*
214
* Determine if a submodule has been initialized at a given 'path'
215
*/
submodule.h
+1
@@ -37,6 +37,7 @@ void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
37
const char *path);
38
int submodule_config(const char *var, const char *value, void *cb);
39
void gitmodules_config(void);
40
+extern void gitmodules_config_sha1(const unsigned char *commit_sha1);
41
extern int is_submodule_initialized(const char *path);
42
extern int is_submodule_populated(const char *path);
43
int parse_submodule_update_strategy(const char *value,