Skip to content

Commit e724197

Browse files
bmwillgitster
authored andcommitted
submodule: convert get_next_submodule to not rely on the_index
Instead of implicitly relying on the global 'the_index', convert 'get_next_submodule()' to use the index of the repository stored in the callback data 'struct submodule_parallel_fetch'. Since this removes the last user of the index compatibility macros, define 'NO_THE_INDEX_COMPATIBILITY_MACROS' to prevent future users of these macros in submodule.c. Signed-off-by: Brandon Williams <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 7da9aba commit e724197

File tree

3 files changed

+22
-15
lines changed

3 files changed

+22
-15
lines changed

builtin/fetch.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
*/
44
#include "cache.h"
55
#include "config.h"
6+
#include "repository.h"
67
#include "refs.h"
78
#include "commit.h"
89
#include "builtin.h"
@@ -1397,7 +1398,8 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
13971398
struct argv_array options = ARGV_ARRAY_INIT;
13981399

13991400
add_options_to_argv(&options);
1400-
result = fetch_populated_submodules(&options,
1401+
result = fetch_populated_submodules(the_repository,
1402+
&options,
14011403
submodule_prefix,
14021404
recurse_submodules,
14031405
recurse_submodules_default,

submodule.c

Lines changed: 13 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
#define NO_THE_INDEX_COMPATIBILITY_MACROS
2+
13
#include "cache.h"
24
#include "repository.h"
35
#include "config.h"
@@ -1179,7 +1181,7 @@ int submodule_touches_in_range(struct object_id *excl_oid,
11791181
struct submodule_parallel_fetch {
11801182
int count;
11811183
struct argv_array args;
1182-
const char *work_tree;
1184+
struct repository *r;
11831185
const char *prefix;
11841186
int command_line_option;
11851187
int default_option;
@@ -1200,7 +1202,7 @@ static int get_fetch_recurse_config(const struct submodule *submodule,
12001202

12011203
int fetch_recurse = submodule->fetch_recurse;
12021204
key = xstrfmt("submodule.%s.fetchRecurseSubmodules", submodule->name);
1203-
if (!repo_config_get_string_const(the_repository, key, &value)) {
1205+
if (!repo_config_get_string_const(spf->r, key, &value)) {
12041206
fetch_recurse = parse_fetch_recurse_submodules_arg(key, value);
12051207
}
12061208
free(key);
@@ -1219,19 +1221,19 @@ static int get_next_submodule(struct child_process *cp,
12191221
int ret = 0;
12201222
struct submodule_parallel_fetch *spf = data;
12211223

1222-
for (; spf->count < active_nr; spf->count++) {
1224+
for (; spf->count < spf->r->index->cache_nr; spf->count++) {
12231225
struct strbuf submodule_path = STRBUF_INIT;
12241226
struct strbuf submodule_git_dir = STRBUF_INIT;
12251227
struct strbuf submodule_prefix = STRBUF_INIT;
1226-
const struct cache_entry *ce = active_cache[spf->count];
1228+
const struct cache_entry *ce = spf->r->index->cache[spf->count];
12271229
const char *git_dir, *default_argv;
12281230
const struct submodule *submodule;
12291231
struct submodule default_submodule = SUBMODULE_INIT;
12301232

12311233
if (!S_ISGITLINK(ce->ce_mode))
12321234
continue;
12331235

1234-
submodule = submodule_from_path(&null_oid, ce->name);
1236+
submodule = submodule_from_cache(spf->r, &null_oid, ce->name);
12351237
if (!submodule) {
12361238
const char *name = default_name_or_path(ce->name);
12371239
if (name) {
@@ -1257,7 +1259,7 @@ static int get_next_submodule(struct child_process *cp,
12571259
continue;
12581260
}
12591261

1260-
strbuf_addf(&submodule_path, "%s/%s", spf->work_tree, ce->name);
1262+
strbuf_repo_worktree_path(&submodule_path, spf->r, "%s", ce->name);
12611263
strbuf_addf(&submodule_git_dir, "%s/.git", submodule_path.buf);
12621264
strbuf_addf(&submodule_prefix, "%s%s/", spf->prefix, ce->name);
12631265
git_dir = read_gitfile(submodule_git_dir.buf);
@@ -1310,24 +1312,25 @@ static int fetch_finish(int retvalue, struct strbuf *err,
13101312
return 0;
13111313
}
13121314

1313-
int fetch_populated_submodules(const struct argv_array *options,
1315+
int fetch_populated_submodules(struct repository *r,
1316+
const struct argv_array *options,
13141317
const char *prefix, int command_line_option,
13151318
int default_option,
13161319
int quiet, int max_parallel_jobs)
13171320
{
13181321
int i;
13191322
struct submodule_parallel_fetch spf = SPF_INIT;
13201323

1321-
spf.work_tree = get_git_work_tree();
1324+
spf.r = r;
13221325
spf.command_line_option = command_line_option;
13231326
spf.default_option = default_option;
13241327
spf.quiet = quiet;
13251328
spf.prefix = prefix;
13261329

1327-
if (!spf.work_tree)
1330+
if (!r->worktree)
13281331
goto out;
13291332

1330-
if (read_cache() < 0)
1333+
if (repo_read_index(r) < 0)
13311334
die("index file corrupt");
13321335

13331336
argv_array_push(&spf.args, "fetch");

submodule.h

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -76,10 +76,12 @@ extern int should_update_submodules(void);
7676
*/
7777
extern const struct submodule *submodule_from_ce(const struct cache_entry *ce);
7878
extern void check_for_new_submodule_commits(struct object_id *oid);
79-
extern int fetch_populated_submodules(const struct argv_array *options,
80-
const char *prefix, int command_line_option,
81-
int default_option,
82-
int quiet, int max_parallel_jobs);
79+
extern int fetch_populated_submodules(struct repository *r,
80+
const struct argv_array *options,
81+
const char *prefix,
82+
int command_line_option,
83+
int default_option,
84+
int quiet, int max_parallel_jobs);
8385
extern unsigned is_submodule_modified(const char *path, int ignore_untracked);
8486
extern int submodule_uses_gitfile(const char *path);
8587

0 commit comments

Comments
 (0)