Skip to content

Commit 5d3635d

Browse files
committed
Merge branch 'sb/submodule-recursive-fetch-gets-the-tip'
"git fetch --recurse-submodules" may not fetch the necessary commit that is bound to the superproject, which is getting corrected. * sb/submodule-recursive-fetch-gets-the-tip: fetch: ensure submodule objects fetched submodule.c: fetch in submodules git directory instead of in worktree submodule: migrate get_next_submodule to use repository structs repository: repo_submodule_init to take a submodule struct submodule: store OIDs in changed_submodule_names submodule.c: tighten scope of changed_submodule_names struct submodule.c: sort changed_submodule_names before searching it submodule.c: fix indentation sha1-array: provide oid_array_filter
2 parents f339894 + be76c21 commit 5d3635d

File tree

12 files changed

+426
-89
lines changed

12 files changed

+426
-89
lines changed

Documentation/technical/api-oid-array.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,11 @@ Functions
4848
is not sorted, this function has the side effect of sorting
4949
it.
5050

51+
`oid_array_filter`::
52+
Apply the callback function `want` to each entry in the array,
53+
retaining only the entries for which the function returns true.
54+
Preserve the order of the entries that are retained.
55+
5156
Examples
5257
--------
5358

builtin/fetch.c

Lines changed: 2 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -763,9 +763,6 @@ static int update_local_ref(struct ref *ref,
763763
what = _("[new ref]");
764764
}
765765

766-
if ((recurse_submodules != RECURSE_SUBMODULES_OFF) &&
767-
(recurse_submodules != RECURSE_SUBMODULES_ON))
768-
check_for_new_submodule_commits(&ref->new_oid);
769766
r = s_update_ref(msg, ref, 0);
770767
format_display(display, r ? '!' : '*', what,
771768
r ? _("unable to update local ref") : NULL,
@@ -779,9 +776,6 @@ static int update_local_ref(struct ref *ref,
779776
strbuf_add_unique_abbrev(&quickref, &current->object.oid, DEFAULT_ABBREV);
780777
strbuf_addstr(&quickref, "..");
781778
strbuf_add_unique_abbrev(&quickref, &ref->new_oid, DEFAULT_ABBREV);
782-
if ((recurse_submodules != RECURSE_SUBMODULES_OFF) &&
783-
(recurse_submodules != RECURSE_SUBMODULES_ON))
784-
check_for_new_submodule_commits(&ref->new_oid);
785779
r = s_update_ref("fast-forward", ref, 1);
786780
format_display(display, r ? '!' : ' ', quickref.buf,
787781
r ? _("unable to update local ref") : NULL,
@@ -794,9 +788,6 @@ static int update_local_ref(struct ref *ref,
794788
strbuf_add_unique_abbrev(&quickref, &current->object.oid, DEFAULT_ABBREV);
795789
strbuf_addstr(&quickref, "...");
796790
strbuf_add_unique_abbrev(&quickref, &ref->new_oid, DEFAULT_ABBREV);
797-
if ((recurse_submodules != RECURSE_SUBMODULES_OFF) &&
798-
(recurse_submodules != RECURSE_SUBMODULES_ON))
799-
check_for_new_submodule_commits(&ref->new_oid);
800791
r = s_update_ref("forced-update", ref, 1);
801792
format_display(display, r ? '!' : '+', quickref.buf,
802793
r ? _("unable to update local ref") : _("forced update"),
@@ -892,6 +883,8 @@ static int store_updated_refs(const char *raw_url, const char *remote_name,
892883
ref->force = rm->peer_ref->force;
893884
}
894885

886+
if (recurse_submodules != RECURSE_SUBMODULES_OFF)
887+
check_for_new_submodule_commits(&rm->old_oid);
895888

896889
if (!strcmp(rm->name, "HEAD")) {
897890
kind = "";

builtin/grep.c

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -404,7 +404,10 @@ static int grep_submodule(struct grep_opt *opt, struct repository *superproject,
404404
const struct object_id *oid,
405405
const char *filename, const char *path)
406406
{
407-
struct repository submodule;
407+
struct repository subrepo;
408+
const struct submodule *sub = submodule_from_path(superproject,
409+
&null_oid, path);
410+
408411
int hit;
409412

410413
/*
@@ -420,12 +423,12 @@ static int grep_submodule(struct grep_opt *opt, struct repository *superproject,
420423
return 0;
421424
}
422425

423-
if (repo_submodule_init(&submodule, superproject, path)) {
426+
if (repo_submodule_init(&subrepo, superproject, sub)) {
424427
grep_read_unlock();
425428
return 0;
426429
}
427430

428-
repo_read_gitmodules(&submodule);
431+
repo_read_gitmodules(&subrepo);
429432

430433
/*
431434
* NEEDSWORK: This adds the submodule's object directory to the list of
@@ -437,7 +440,7 @@ static int grep_submodule(struct grep_opt *opt, struct repository *superproject,
437440
* store is no longer global and instead is a member of the repository
438441
* object.
439442
*/
440-
add_to_alternates_memory(submodule.objects->odb->path);
443+
add_to_alternates_memory(subrepo.objects->odb->path);
441444
grep_read_unlock();
442445

443446
if (oid) {
@@ -462,14 +465,14 @@ static int grep_submodule(struct grep_opt *opt, struct repository *superproject,
462465

463466
init_tree_desc(&tree, data, size);
464467
hit = grep_tree(opt, pathspec, &tree, &base, base.len,
465-
object->type == OBJ_COMMIT, &submodule);
468+
object->type == OBJ_COMMIT, &subrepo);
466469
strbuf_release(&base);
467470
free(data);
468471
} else {
469-
hit = grep_cache(opt, &submodule, pathspec, 1);
472+
hit = grep_cache(opt, &subrepo, pathspec, 1);
470473
}
471474

472-
repo_clear(&submodule);
475+
repo_clear(&subrepo);
473476
return hit;
474477
}
475478

builtin/ls-files.c

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -206,17 +206,19 @@ static void show_files(struct repository *repo, struct dir_struct *dir);
206206
static void show_submodule(struct repository *superproject,
207207
struct dir_struct *dir, const char *path)
208208
{
209-
struct repository submodule;
209+
struct repository subrepo;
210+
const struct submodule *sub = submodule_from_path(superproject,
211+
&null_oid, path);
210212

211-
if (repo_submodule_init(&submodule, superproject, path))
213+
if (repo_submodule_init(&subrepo, superproject, sub))
212214
return;
213215

214-
if (repo_read_index(&submodule) < 0)
216+
if (repo_read_index(&subrepo) < 0)
215217
die("index file corrupt");
216218

217-
show_files(&submodule, dir);
219+
show_files(&subrepo, dir);
218220

219-
repo_clear(&submodule);
221+
repo_clear(&subrepo);
220222
}
221223

222224
static void show_ce(struct repository *repo, struct dir_struct *dir,

builtin/submodule--helper.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2056,7 +2056,7 @@ static int ensure_core_worktree(int argc, const char **argv, const char *prefix)
20562056
if (!sub)
20572057
BUG("We could get the submodule handle before?");
20582058

2059-
if (repo_submodule_init(&subrepo, the_repository, path))
2059+
if (repo_submodule_init(&subrepo, the_repository, sub))
20602060
die(_("could not get a repository handle for submodule '%s'"), path);
20612061

20622062
if (!repo_config_get_string(&subrepo, "core.worktree", &cw)) {

repository.c

Lines changed: 10 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -172,30 +172,23 @@ int repo_init(struct repository *repo,
172172
return -1;
173173
}
174174

175-
/*
176-
* Initialize 'submodule' as the submodule given by 'path' in parent repository
177-
* 'superproject'.
178-
* Return 0 upon success and a non-zero value upon failure.
179-
*/
180-
int repo_submodule_init(struct repository *submodule,
175+
int repo_submodule_init(struct repository *subrepo,
181176
struct repository *superproject,
182-
const char *path)
177+
const struct submodule *sub)
183178
{
184-
const struct submodule *sub;
185179
struct strbuf gitdir = STRBUF_INIT;
186180
struct strbuf worktree = STRBUF_INIT;
187181
int ret = 0;
188182

189-
sub = submodule_from_path(superproject, &null_oid, path);
190183
if (!sub) {
191184
ret = -1;
192185
goto out;
193186
}
194187

195-
strbuf_repo_worktree_path(&gitdir, superproject, "%s/.git", path);
196-
strbuf_repo_worktree_path(&worktree, superproject, "%s", path);
188+
strbuf_repo_worktree_path(&gitdir, superproject, "%s/.git", sub->path);
189+
strbuf_repo_worktree_path(&worktree, superproject, "%s", sub->path);
197190

198-
if (repo_init(submodule, gitdir.buf, worktree.buf)) {
191+
if (repo_init(subrepo, gitdir.buf, worktree.buf)) {
199192
/*
200193
* If initilization fails then it may be due to the submodule
201194
* not being populated in the superproject's worktree. Instead
@@ -207,16 +200,16 @@ int repo_submodule_init(struct repository *submodule,
207200
strbuf_repo_git_path(&gitdir, superproject,
208201
"modules/%s", sub->name);
209202

210-
if (repo_init(submodule, gitdir.buf, NULL)) {
203+
if (repo_init(subrepo, gitdir.buf, NULL)) {
211204
ret = -1;
212205
goto out;
213206
}
214207
}
215208

216-
submodule->submodule_prefix = xstrfmt("%s%s/",
217-
superproject->submodule_prefix ?
218-
superproject->submodule_prefix :
219-
"", path);
209+
subrepo->submodule_prefix = xstrfmt("%s%s/",
210+
superproject->submodule_prefix ?
211+
superproject->submodule_prefix :
212+
"", sub->path);
220213

221214
out:
222215
strbuf_release(&gitdir);

repository.h

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -116,9 +116,17 @@ void repo_set_worktree(struct repository *repo, const char *path);
116116
void repo_set_hash_algo(struct repository *repo, int algo);
117117
void initialize_the_repository(void);
118118
int repo_init(struct repository *r, const char *gitdir, const char *worktree);
119-
int repo_submodule_init(struct repository *submodule,
119+
120+
/*
121+
* Initialize the repository 'subrepo' as the submodule given by the
122+
* struct submodule 'sub' in parent repository 'superproject'.
123+
* Return 0 upon success and a non-zero value upon failure, which may happen
124+
* if the submodule is not found, or 'sub' is NULL.
125+
*/
126+
struct submodule;
127+
int repo_submodule_init(struct repository *subrepo,
120128
struct repository *superproject,
121-
const char *path);
129+
const struct submodule *sub);
122130
void repo_clear(struct repository *repo);
123131

124132
/*

sha1-array.c

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -77,3 +77,20 @@ int oid_array_for_each_unique(struct oid_array *array,
7777
}
7878
return 0;
7979
}
80+
81+
void oid_array_filter(struct oid_array *array,
82+
for_each_oid_fn want,
83+
void *cb_data)
84+
{
85+
unsigned nr = array->nr, src, dst;
86+
struct object_id *oids = array->oid;
87+
88+
for (src = dst = 0; src < nr; src++) {
89+
if (want(&oids[src], cb_data)) {
90+
if (src != dst)
91+
oidcpy(&oids[dst], &oids[src]);
92+
dst++;
93+
}
94+
}
95+
array->nr = dst;
96+
}

sha1-array.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,5 +22,8 @@ int oid_array_for_each(struct oid_array *array,
2222
int oid_array_for_each_unique(struct oid_array *array,
2323
for_each_oid_fn fn,
2424
void *data);
25+
void oid_array_filter(struct oid_array *array,
26+
for_each_oid_fn want,
27+
void *cbdata);
2528

2629
#endif /* SHA1_ARRAY_H */

0 commit comments

Comments
 (0)