Skip to content

Commit 00c4d2b

Browse files
committed
Merge branch 'bw/submodule-sans-cache-compat'
Code clean-up. * bw/submodule-sans-cache-compat: submodule: convert get_next_submodule to not rely on the_index submodule: used correct index in is_staging_gitmodules_ok submodule: convert stage_updated_gitmodules to take a struct index_state
2 parents 237aa99 + e724197 commit 00c4d2b

File tree

5 files changed

+31
-23
lines changed

5 files changed

+31
-23
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,

builtin/mv.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -291,7 +291,7 @@ int cmd_mv(int argc, const char **argv, const char *prefix)
291291
}
292292

293293
if (gitmodules_modified)
294-
stage_updated_gitmodules();
294+
stage_updated_gitmodules(&the_index);
295295

296296
if (active_cache_changed &&
297297
write_locked_index(&the_index, &lock_file, COMMIT_LOCK))

builtin/rm.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -382,7 +382,7 @@ int cmd_rm(int argc, const char **argv, const char *prefix)
382382
}
383383
strbuf_release(&buf);
384384
if (gitmodules_modified)
385-
stage_updated_gitmodules();
385+
stage_updated_gitmodules(&the_index);
386386
}
387387

388388
if (active_cache_changed) {

submodule.c

Lines changed: 18 additions & 14 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"
@@ -55,14 +57,15 @@ int is_gitmodules_unmerged(const struct index_state *istate)
5557
* future version when we learn to stage the changes we do ourselves without
5658
* staging any previous modifications.
5759
*/
58-
int is_staging_gitmodules_ok(const struct index_state *istate)
60+
int is_staging_gitmodules_ok(struct index_state *istate)
5961
{
6062
int pos = index_name_pos(istate, GITMODULES_FILE, strlen(GITMODULES_FILE));
6163

6264
if ((pos >= 0) && (pos < istate->cache_nr)) {
6365
struct stat st;
6466
if (lstat(GITMODULES_FILE, &st) == 0 &&
65-
ce_match_stat(istate->cache[pos], &st, CE_MATCH_IGNORE_FSMONITOR) & DATA_CHANGED)
67+
ie_match_stat(istate, istate->cache[pos], &st,
68+
CE_MATCH_IGNORE_FSMONITOR) & DATA_CHANGED)
6669
return 0;
6770
}
6871

@@ -143,9 +146,9 @@ int remove_path_from_gitmodules(const char *path)
143146
return 0;
144147
}
145148

146-
void stage_updated_gitmodules(void)
149+
void stage_updated_gitmodules(struct index_state *istate)
147150
{
148-
if (add_file_to_cache(GITMODULES_FILE, 0))
151+
if (add_file_to_index(istate, GITMODULES_FILE, 0))
149152
die(_("staging updated .gitmodules failed"));
150153
}
151154

@@ -1178,7 +1181,7 @@ int submodule_touches_in_range(struct object_id *excl_oid,
11781181
struct submodule_parallel_fetch {
11791182
int count;
11801183
struct argv_array args;
1181-
const char *work_tree;
1184+
struct repository *r;
11821185
const char *prefix;
11831186
int command_line_option;
11841187
int default_option;
@@ -1199,7 +1202,7 @@ static int get_fetch_recurse_config(const struct submodule *submodule,
11991202

12001203
int fetch_recurse = submodule->fetch_recurse;
12011204
key = xstrfmt("submodule.%s.fetchRecurseSubmodules", submodule->name);
1202-
if (!repo_config_get_string_const(the_repository, key, &value)) {
1205+
if (!repo_config_get_string_const(spf->r, key, &value)) {
12031206
fetch_recurse = parse_fetch_recurse_submodules_arg(key, value);
12041207
}
12051208
free(key);
@@ -1218,19 +1221,19 @@ static int get_next_submodule(struct child_process *cp,
12181221
int ret = 0;
12191222
struct submodule_parallel_fetch *spf = data;
12201223

1221-
for (; spf->count < active_nr; spf->count++) {
1224+
for (; spf->count < spf->r->index->cache_nr; spf->count++) {
12221225
struct strbuf submodule_path = STRBUF_INIT;
12231226
struct strbuf submodule_git_dir = STRBUF_INIT;
12241227
struct strbuf submodule_prefix = STRBUF_INIT;
1225-
const struct cache_entry *ce = active_cache[spf->count];
1228+
const struct cache_entry *ce = spf->r->index->cache[spf->count];
12261229
const char *git_dir, *default_argv;
12271230
const struct submodule *submodule;
12281231
struct submodule default_submodule = SUBMODULE_INIT;
12291232

12301233
if (!S_ISGITLINK(ce->ce_mode))
12311234
continue;
12321235

1233-
submodule = submodule_from_path(&null_oid, ce->name);
1236+
submodule = submodule_from_cache(spf->r, &null_oid, ce->name);
12341237
if (!submodule) {
12351238
const char *name = default_name_or_path(ce->name);
12361239
if (name) {
@@ -1256,7 +1259,7 @@ static int get_next_submodule(struct child_process *cp,
12561259
continue;
12571260
}
12581261

1259-
strbuf_addf(&submodule_path, "%s/%s", spf->work_tree, ce->name);
1262+
strbuf_repo_worktree_path(&submodule_path, spf->r, "%s", ce->name);
12601263
strbuf_addf(&submodule_git_dir, "%s/.git", submodule_path.buf);
12611264
strbuf_addf(&submodule_prefix, "%s%s/", spf->prefix, ce->name);
12621265
git_dir = read_gitfile(submodule_git_dir.buf);
@@ -1309,24 +1312,25 @@ static int fetch_finish(int retvalue, struct strbuf *err,
13091312
return 0;
13101313
}
13111314

1312-
int fetch_populated_submodules(const struct argv_array *options,
1315+
int fetch_populated_submodules(struct repository *r,
1316+
const struct argv_array *options,
13131317
const char *prefix, int command_line_option,
13141318
int default_option,
13151319
int quiet, int max_parallel_jobs)
13161320
{
13171321
int i;
13181322
struct submodule_parallel_fetch spf = SPF_INIT;
13191323

1320-
spf.work_tree = get_git_work_tree();
1324+
spf.r = r;
13211325
spf.command_line_option = command_line_option;
13221326
spf.default_option = default_option;
13231327
spf.quiet = quiet;
13241328
spf.prefix = prefix;
13251329

1326-
if (!spf.work_tree)
1330+
if (!r->worktree)
13271331
goto out;
13281332

1329-
if (read_cache() < 0)
1333+
if (repo_read_index(r) < 0)
13301334
die("index file corrupt");
13311335

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

submodule.h

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ struct submodule_update_strategy {
3434
#define SUBMODULE_UPDATE_STRATEGY_INIT {SM_UPDATE_UNSPECIFIED, NULL}
3535

3636
extern int is_gitmodules_unmerged(const struct index_state *istate);
37-
extern int is_staging_gitmodules_ok(const struct index_state *istate);
37+
extern int is_staging_gitmodules_ok(struct index_state *istate);
3838
extern int update_path_in_gitmodules(const char *oldpath, const char *newpath);
3939
extern int remove_path_from_gitmodules(const char *path);
40-
extern void stage_updated_gitmodules(void);
40+
extern void stage_updated_gitmodules(struct index_state *istate);
4141
extern void set_diffopt_flags_from_submodule_config(struct diff_options *,
4242
const char *path);
4343
extern int git_default_submodule_config(const char *var, const char *value, void *cb);
@@ -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)