Skip to content

Commit 1b796ac

Browse files
bmwillgitster
authored andcommitted
submodule-config: move submodule-config functions to submodule-config.c
Migrate the functions used to initialize the submodule-config to submodule-config.c so that the callback routine used in the initialization process can be static and prevent it from being used outside of initializing the submodule-config through the main API. Signed-off-by: Brandon Williams <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 32bc548 commit 1b796ac

File tree

5 files changed

+34
-49
lines changed

5 files changed

+34
-49
lines changed

builtin/ls-files.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "pathspec.h"
2020
#include "run-command.h"
2121
#include "submodule.h"
22+
#include "submodule-config.h"
2223

2324
static int abbrev;
2425
static int show_deleted;

submodule-config.c

Lines changed: 31 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -449,9 +449,9 @@ static int parse_config(const char *var, const char *value, void *data)
449449
return ret;
450450
}
451451

452-
int gitmodule_oid_from_commit(const struct object_id *treeish_name,
453-
struct object_id *gitmodules_oid,
454-
struct strbuf *rev)
452+
static int gitmodule_oid_from_commit(const struct object_id *treeish_name,
453+
struct object_id *gitmodules_oid,
454+
struct strbuf *rev)
455455
{
456456
int ret = 0;
457457

@@ -552,9 +552,9 @@ static void submodule_cache_check_init(struct repository *repo)
552552
submodule_cache_init(repo->submodule_cache);
553553
}
554554

555-
int submodule_config_option(struct repository *repo,
556-
const char *var, const char *value)
555+
static int gitmodules_cb(const char *var, const char *value, void *data)
557556
{
557+
struct repository *repo = data;
558558
struct parse_config_parameter parameter;
559559

560560
submodule_cache_check_init(repo);
@@ -567,9 +567,33 @@ int submodule_config_option(struct repository *repo,
567567
return parse_config(var, value, &parameter);
568568
}
569569

570-
int parse_submodule_config_option(const char *var, const char *value)
570+
void repo_read_gitmodules(struct repository *repo)
571571
{
572-
return submodule_config_option(the_repository, var, value);
572+
if (repo->worktree) {
573+
char *gitmodules;
574+
575+
if (repo_read_index(repo) < 0)
576+
return;
577+
578+
gitmodules = repo_worktree_path(repo, GITMODULES_FILE);
579+
580+
if (!is_gitmodules_unmerged(repo->index))
581+
git_config_from_file(gitmodules_cb, gitmodules, repo);
582+
583+
free(gitmodules);
584+
}
585+
}
586+
587+
void gitmodules_config_oid(const struct object_id *commit_oid)
588+
{
589+
struct strbuf rev = STRBUF_INIT;
590+
struct object_id oid;
591+
592+
if (gitmodule_oid_from_commit(commit_oid, &oid, &rev)) {
593+
git_config_from_blob_oid(gitmodules_cb, rev.buf,
594+
&oid, the_repository);
595+
}
596+
strbuf_release(&rev);
573597
}
574598

575599
const struct submodule *submodule_from_name(const struct object_id *treeish_name,

submodule-config.h

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,15 @@ extern int option_fetch_parse_recurse_submodules(const struct option *opt,
3434
const char *arg, int unset);
3535
extern int parse_update_recurse_submodules_arg(const char *opt, const char *arg);
3636
extern int parse_push_recurse_submodules_arg(const char *opt, const char *arg);
37-
extern int submodule_config_option(struct repository *repo,
38-
const char *var, const char *value);
37+
extern void repo_read_gitmodules(struct repository *repo);
38+
extern void gitmodules_config_oid(const struct object_id *commit_oid);
3939
extern const struct submodule *submodule_from_name(
4040
const struct object_id *commit_or_tree, const char *name);
4141
extern const struct submodule *submodule_from_path(
4242
const struct object_id *commit_or_tree, const char *path);
4343
extern const struct submodule *submodule_from_cache(struct repository *repo,
4444
const struct object_id *treeish_name,
4545
const char *key);
46-
extern int gitmodule_oid_from_commit(const struct object_id *commit_oid,
47-
struct object_id *gitmodules_oid,
48-
struct strbuf *rev);
4946
extern void submodule_free(void);
5047

5148
#endif /* SUBMODULE_CONFIG_H */

submodule.c

Lines changed: 0 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -216,46 +216,11 @@ void load_submodule_cache(void)
216216
gitmodules_config();
217217
}
218218

219-
static int gitmodules_cb(const char *var, const char *value, void *data)
220-
{
221-
struct repository *repo = data;
222-
return submodule_config_option(repo, var, value);
223-
}
224-
225-
void repo_read_gitmodules(struct repository *repo)
226-
{
227-
if (repo->worktree) {
228-
char *gitmodules;
229-
230-
if (repo_read_index(repo) < 0)
231-
return;
232-
233-
gitmodules = repo_worktree_path(repo, GITMODULES_FILE);
234-
235-
if (!is_gitmodules_unmerged(repo->index))
236-
git_config_from_file(gitmodules_cb, gitmodules, repo);
237-
238-
free(gitmodules);
239-
}
240-
}
241-
242219
void gitmodules_config(void)
243220
{
244221
repo_read_gitmodules(the_repository);
245222
}
246223

247-
void gitmodules_config_oid(const struct object_id *commit_oid)
248-
{
249-
struct strbuf rev = STRBUF_INIT;
250-
struct object_id oid;
251-
252-
if (gitmodule_oid_from_commit(commit_oid, &oid, &rev)) {
253-
git_config_from_blob_oid(gitmodules_cb, rev.buf,
254-
&oid, the_repository);
255-
}
256-
strbuf_release(&rev);
257-
}
258-
259224
/*
260225
* Determine if a submodule has been initialized at a given 'path'
261226
*/

submodule.h

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,6 @@ int option_parse_recurse_submodules_worktree_updater(const struct option *opt,
4747
const char *arg, int unset);
4848
void load_submodule_cache(void);
4949
extern void gitmodules_config(void);
50-
extern void repo_read_gitmodules(struct repository *repo);
51-
extern void gitmodules_config_oid(const struct object_id *commit_oid);
5250
extern int is_submodule_active(struct repository *repo, const char *path);
5351
/*
5452
* Determine if a submodule has been populated at a given 'path' by checking if

0 commit comments

Comments
 (0)