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 <bmwill@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Brandon Williams committed
Dec 12, 2017 at 11:53 UTC
e724197f236aa1a4fa87a8e7dd1377dbd0199307
3 files changed
+22
-15
builtin/fetch.c
+3
-1
@@ -3,6 +3,7 @@
3
*/
4
#include "cache.h"
5
#include "config.h"
6
+#include "repository.h"
7
#include "refs.h"
8
#include "commit.h"
9
#include "builtin.h"
@@ -1397,7 +1398,8 @@ int cmd_fetch(int argc, const char **argv, const char *prefix)
1398
struct argv_array options = ARGV_ARRAY_INIT;
1399
1400
add_options_to_argv(&options);
1400
- result = fetch_populated_submodules(&options,
1401
+ result = fetch_populated_submodules(the_repository,
1402
+ &options,
1403
submodule_prefix,
1404
recurse_submodules,
1405
recurse_submodules_default,
submodule.c
+13
-10
@@ -1,3 +1,5 @@
1
+#define NO_THE_INDEX_COMPATIBILITY_MACROS
2
+
3
#include "cache.h"
4
#include "repository.h"
5
#include "config.h"
@@ -1179,7 +1181,7 @@ int submodule_touches_in_range(struct object_id *excl_oid,
1181
struct submodule_parallel_fetch {
1182
int count;
1183
struct argv_array args;
1182
- const char *work_tree;
1184
+ struct repository *r;
1185
const char *prefix;
1186
int command_line_option;
1187
int default_option;
@@ -1200,7 +1202,7 @@ static int get_fetch_recurse_config(const struct submodule *submodule,
1202
1203
int fetch_recurse = submodule->fetch_recurse;
1204
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)) {
1206
fetch_recurse = parse_fetch_recurse_submodules_arg(key, value);
1207
}
1208
free(key);
@@ -1219,11 +1221,11 @@ static int get_next_submodule(struct child_process *cp,
1221
int ret = 0;
1222
struct submodule_parallel_fetch *spf = data;
1223
1222
- for (; spf->count < active_nr; spf->count++) {
1224
+ for (; spf->count < spf->r->index->cache_nr; spf->count++) {
1225
struct strbuf submodule_path = STRBUF_INIT;
1226
struct strbuf submodule_git_dir = STRBUF_INIT;
1227
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];
1229
const char *git_dir, *default_argv;
1230
const struct submodule *submodule;
1231
struct submodule default_submodule = SUBMODULE_INIT;
@@ -1231,7 +1233,7 @@ static int get_next_submodule(struct child_process *cp,
1233
if (!S_ISGITLINK(ce->ce_mode))
1234
continue;
1235
1234
- submodule = submodule_from_path(&null_oid, ce->name);
1236
+ submodule = submodule_from_cache(spf->r, &null_oid, ce->name);
1237
if (!submodule) {
1238
const char *name = default_name_or_path(ce->name);
1239
if (name) {
@@ -1257,7 +1259,7 @@ static int get_next_submodule(struct child_process *cp,
1259
continue;
1260
}
1261
1260
- strbuf_addf(&submodule_path, "%s/%s", spf->work_tree, ce->name);
1262
+ strbuf_repo_worktree_path(&submodule_path, spf->r, "%s", ce->name);
1263
strbuf_addf(&submodule_git_dir, "%s/.git", submodule_path.buf);
1264
strbuf_addf(&submodule_prefix, "%s%s/", spf->prefix, ce->name);
1265
git_dir = read_gitfile(submodule_git_dir.buf);
@@ -1310,7 +1312,8 @@ static int fetch_finish(int retvalue, struct strbuf *err,
1312
return 0;
1313
}
1314
1313
-int fetch_populated_submodules(const struct argv_array *options,
1315
+int fetch_populated_submodules(struct repository *r,
1316
+ const struct argv_array *options,
1317
const char *prefix, int command_line_option,
1318
int default_option,
1319
int quiet, int max_parallel_jobs)
@@ -1318,16 +1321,16 @@ int fetch_populated_submodules(const struct argv_array *options,
1321
int i;
1322
struct submodule_parallel_fetch spf = SPF_INIT;
1323
1321
- spf.work_tree = get_git_work_tree();
1324
+ spf.r = r;
1325
spf.command_line_option = command_line_option;
1326
spf.default_option = default_option;
1327
spf.quiet = quiet;
1328
spf.prefix = prefix;
1329
1327
- if (!spf.work_tree)
1330
+ if (!r->worktree)
1331
goto out;
1332
1330
- if (read_cache() < 0)
1333
+ if (repo_read_index(r) < 0)
1334
die("index file corrupt");
1335
1336
argv_array_push(&spf.args, "fetch");
submodule.h
+6
-4
@@ -76,10 +76,12 @@ extern int should_update_submodules(void);
76
*/
77
extern const struct submodule *submodule_from_ce(const struct cache_entry *ce);
78
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);
85
extern unsigned is_submodule_modified(const char *path, int ignore_untracked);
86
extern int submodule_uses_gitfile(const char *path);
87