Skip to content

Commit 9ebf689

Browse files
bmwillgitster
authored andcommitted
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 <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent f9f4256 commit 9ebf689

File tree

6 files changed

+25
-7
lines changed

6 files changed

+25
-7
lines changed

cache.h

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1693,6 +1693,8 @@ extern int git_default_config(const char *, const char *, void *);
16931693
extern int git_config_from_file(config_fn_t fn, const char *, void *);
16941694
extern int git_config_from_mem(config_fn_t fn, const enum config_origin_type,
16951695
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);
16961698
extern void git_config_push_parameter(const char *text);
16971699
extern int git_config_from_parameters(config_fn_t fn, void *data);
16981700
extern void git_config(config_fn_t fn, void *);

config.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1214,10 +1214,10 @@ int git_config_from_mem(config_fn_t fn, const enum config_origin_type origin_typ
12141214
return do_config_from(&top, fn, data);
12151215
}
12161216

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)
12211221
{
12221222
enum object_type type;
12231223
char *buf;

submodule-config.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -379,9 +379,9 @@ static int parse_config(const char *var, const char *value, void *data)
379379
return ret;
380380
}
381381

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)
385385
{
386386
int ret = 0;
387387

submodule-config.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,9 @@ const struct submodule *submodule_from_name(const unsigned char *commit_sha1,
2929
const char *name);
3030
const struct submodule *submodule_from_path(const unsigned char *commit_sha1,
3131
const char *path);
32+
extern int gitmodule_sha1_from_commit(const unsigned char *commit_sha1,
33+
unsigned char *gitmodules_sha1,
34+
struct strbuf *rev);
3235
void submodule_free(void);
3336

3437
#endif /* SUBMODULE_CONFIG_H */

submodule.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -198,6 +198,18 @@ void gitmodules_config(void)
198198
}
199199
}
200200

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+
201213
/*
202214
* Determine if a submodule has been initialized at a given 'path'
203215
*/

submodule.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ void set_diffopt_flags_from_submodule_config(struct diff_options *diffopt,
3737
const char *path);
3838
int submodule_config(const char *var, const char *value, void *cb);
3939
void gitmodules_config(void);
40+
extern void gitmodules_config_sha1(const unsigned char *commit_sha1);
4041
extern int is_submodule_initialized(const char *path);
4142
extern int is_submodule_populated(const char *path);
4243
int parse_submodule_update_strategy(const char *value,

0 commit comments

Comments
 (0)