Skip to content

Commit 6295f87

Browse files
committed
Merge branch 'jt/add-submodule-odb-clean-up' into jt/no-abuse-alternate-odb-for-submodules
* jt/add-submodule-odb-clean-up: revision: remove "submodule" from opt struct repository: support unabsorbed in repo_submodule_init submodule: remove unnecessary unabsorbed fallback
2 parents 99c99ed + 10a0d6a commit 6295f87

File tree

11 files changed

+102
-97
lines changed

11 files changed

+102
-97
lines changed

builtin/grep.c

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -433,17 +433,14 @@ static int grep_submodule(struct grep_opt *opt,
433433
{
434434
struct repository *subrepo;
435435
struct repository *superproject = opt->repo;
436-
const struct submodule *sub;
437436
struct grep_opt subopt;
438437
int hit = 0;
439438

440-
sub = submodule_from_path(superproject, null_oid(), path);
441-
442439
if (!is_submodule_active(superproject, path))
443440
return 0;
444441

445442
subrepo = xmalloc(sizeof(*subrepo));
446-
if (repo_submodule_init(subrepo, superproject, sub)) {
443+
if (repo_submodule_init(subrepo, superproject, path, null_oid())) {
447444
free(subrepo);
448445
return 0;
449446
}

builtin/ls-files.c

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -209,10 +209,8 @@ static void show_submodule(struct repository *superproject,
209209
struct dir_struct *dir, const char *path)
210210
{
211211
struct repository subrepo;
212-
const struct submodule *sub = submodule_from_path(superproject,
213-
null_oid(), path);
214212

215-
if (repo_submodule_init(&subrepo, superproject, sub))
213+
if (repo_submodule_init(&subrepo, superproject, path, null_oid()))
216214
return;
217215

218216
if (repo_read_index(&subrepo) < 0)

builtin/submodule--helper.c

Lines changed: 1 addition & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2760,7 +2760,6 @@ static int push_check(int argc, const char **argv, const char *prefix)
27602760

27612761
static int ensure_core_worktree(int argc, const char **argv, const char *prefix)
27622762
{
2763-
const struct submodule *sub;
27642763
const char *path;
27652764
const char *cw;
27662765
struct repository subrepo;
@@ -2770,11 +2769,7 @@ static int ensure_core_worktree(int argc, const char **argv, const char *prefix)
27702769

27712770
path = argv[1];
27722771

2773-
sub = submodule_from_path(the_repository, null_oid(), path);
2774-
if (!sub)
2775-
BUG("We could get the submodule handle before?");
2776-
2777-
if (repo_submodule_init(&subrepo, the_repository, sub))
2772+
if (repo_submodule_init(&subrepo, the_repository, path, null_oid()))
27782773
die(_("could not get a repository handle for submodule '%s'"), path);
27792774

27802775
if (!repo_config_get_string_tmp(&subrepo, "core.worktree", &cw)) {

merge-ort.c

Lines changed: 35 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
#include "promisor-remote.h"
3333
#include "revision.h"
3434
#include "strmap.h"
35+
#include "submodule-config.h"
3536
#include "submodule.h"
3637
#include "tree.h"
3738
#include "unpack-trees.h"
@@ -1511,7 +1512,6 @@ static int find_first_merges(struct repository *repo,
15111512
xsnprintf(merged_revision, sizeof(merged_revision), "^%s",
15121513
oid_to_hex(&a->object.oid));
15131514
repo_init_revisions(repo, &revs, NULL);
1514-
rev_opts.submodule = path;
15151515
/* FIXME: can't handle linked worktrees in submodules yet */
15161516
revs.single_worktree = path != NULL;
15171517
setup_revisions(ARRAY_SIZE(rev_args)-1, rev_args, &revs, &rev_opts);
@@ -1521,7 +1521,7 @@ static int find_first_merges(struct repository *repo,
15211521
die("revision walk setup failed");
15221522
while ((commit = get_revision(&revs)) != NULL) {
15231523
struct object *o = &(commit->object);
1524-
if (in_merge_bases(b, commit))
1524+
if (repo_in_merge_bases(repo, b, commit))
15251525
add_object_array(o, NULL, &merges);
15261526
}
15271527
reset_revision_walk();
@@ -1536,7 +1536,7 @@ static int find_first_merges(struct repository *repo,
15361536
contains_another = 0;
15371537
for (j = 0; j < merges.nr; j++) {
15381538
struct commit *m2 = (struct commit *) merges.objects[j].item;
1539-
if (i != j && in_merge_bases(m2, m1)) {
1539+
if (i != j && repo_in_merge_bases(repo, m2, m1)) {
15401540
contains_another = 1;
15411541
break;
15421542
}
@@ -1557,10 +1557,12 @@ static int merge_submodule(struct merge_options *opt,
15571557
const struct object_id *b,
15581558
struct object_id *result)
15591559
{
1560+
struct repository subrepo;
1561+
struct strbuf sb = STRBUF_INIT;
1562+
int ret = 0;
15601563
struct commit *commit_o, *commit_a, *commit_b;
15611564
int parent_count;
15621565
struct object_array merges;
1563-
struct strbuf sb = STRBUF_INIT;
15641566

15651567
int i;
15661568
int search = !opt->priv->call_depth;
@@ -1576,46 +1578,59 @@ static int merge_submodule(struct merge_options *opt,
15761578
if (is_null_oid(b))
15771579
return 0;
15781580

1581+
/*
1582+
* NEEDSWORK: Remove this when all submodule object accesses are
1583+
* through explicitly specified repositores.
1584+
*/
15791585
if (add_submodule_odb(path)) {
15801586
path_msg(opt, path, 0,
15811587
_("Failed to merge submodule %s (not checked out)"),
15821588
path);
15831589
return 0;
15841590
}
15851591

1586-
if (!(commit_o = lookup_commit_reference(opt->repo, o)) ||
1587-
!(commit_a = lookup_commit_reference(opt->repo, a)) ||
1588-
!(commit_b = lookup_commit_reference(opt->repo, b))) {
1592+
if (repo_submodule_init(&subrepo, opt->repo, path, null_oid())) {
1593+
path_msg(opt, path, 0,
1594+
_("Failed to merge submodule %s (not checked out)"),
1595+
path);
1596+
return 0;
1597+
}
1598+
1599+
if (!(commit_o = lookup_commit_reference(&subrepo, o)) ||
1600+
!(commit_a = lookup_commit_reference(&subrepo, a)) ||
1601+
!(commit_b = lookup_commit_reference(&subrepo, b))) {
15891602
path_msg(opt, path, 0,
15901603
_("Failed to merge submodule %s (commits not present)"),
15911604
path);
1592-
return 0;
1605+
goto cleanup;
15931606
}
15941607

15951608
/* check whether both changes are forward */
1596-
if (!in_merge_bases(commit_o, commit_a) ||
1597-
!in_merge_bases(commit_o, commit_b)) {
1609+
if (!repo_in_merge_bases(&subrepo, commit_o, commit_a) ||
1610+
!repo_in_merge_bases(&subrepo, commit_o, commit_b)) {
15981611
path_msg(opt, path, 0,
15991612
_("Failed to merge submodule %s "
16001613
"(commits don't follow merge-base)"),
16011614
path);
1602-
return 0;
1615+
goto cleanup;
16031616
}
16041617

16051618
/* Case #1: a is contained in b or vice versa */
1606-
if (in_merge_bases(commit_a, commit_b)) {
1619+
if (repo_in_merge_bases(&subrepo, commit_a, commit_b)) {
16071620
oidcpy(result, b);
16081621
path_msg(opt, path, 1,
16091622
_("Note: Fast-forwarding submodule %s to %s"),
16101623
path, oid_to_hex(b));
1611-
return 1;
1624+
ret = 1;
1625+
goto cleanup;
16121626
}
1613-
if (in_merge_bases(commit_b, commit_a)) {
1627+
if (repo_in_merge_bases(&subrepo, commit_b, commit_a)) {
16141628
oidcpy(result, a);
16151629
path_msg(opt, path, 1,
16161630
_("Note: Fast-forwarding submodule %s to %s"),
16171631
path, oid_to_hex(a));
1618-
return 1;
1632+
ret = 1;
1633+
goto cleanup;
16191634
}
16201635

16211636
/*
@@ -1627,10 +1642,10 @@ static int merge_submodule(struct merge_options *opt,
16271642

16281643
/* Skip the search if makes no sense to the calling context. */
16291644
if (!search)
1630-
return 0;
1645+
goto cleanup;
16311646

16321647
/* find commit which merges them */
1633-
parent_count = find_first_merges(opt->repo, path, commit_a, commit_b,
1648+
parent_count = find_first_merges(&subrepo, path, commit_a, commit_b,
16341649
&merges);
16351650
switch (parent_count) {
16361651
case 0:
@@ -1664,7 +1679,9 @@ static int merge_submodule(struct merge_options *opt,
16641679
}
16651680

16661681
object_array_clear(&merges);
1667-
return 0;
1682+
cleanup:
1683+
repo_clear(&subrepo);
1684+
return ret;
16681685
}
16691686

16701687
static void initialize_attr_index(struct merge_options *opt)

merge-recursive.c

Lines changed: 32 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@
2424
#include "repository.h"
2525
#include "revision.h"
2626
#include "string-list.h"
27+
#include "submodule-config.h"
2728
#include "submodule.h"
2829
#include "tag.h"
2930
#include "tree-walk.h"
@@ -1110,7 +1111,6 @@ static int find_first_merges(struct repository *repo,
11101111
xsnprintf(merged_revision, sizeof(merged_revision), "^%s",
11111112
oid_to_hex(&a->object.oid));
11121113
repo_init_revisions(repo, &revs, NULL);
1113-
rev_opts.submodule = path;
11141114
/* FIXME: can't handle linked worktrees in submodules yet */
11151115
revs.single_worktree = path != NULL;
11161116
setup_revisions(ARRAY_SIZE(rev_args)-1, rev_args, &revs, &rev_opts);
@@ -1120,7 +1120,7 @@ static int find_first_merges(struct repository *repo,
11201120
die("revision walk setup failed");
11211121
while ((commit = get_revision(&revs)) != NULL) {
11221122
struct object *o = &(commit->object);
1123-
if (in_merge_bases(b, commit))
1123+
if (repo_in_merge_bases(repo, b, commit))
11241124
add_object_array(o, NULL, &merges);
11251125
}
11261126
reset_revision_walk();
@@ -1135,7 +1135,7 @@ static int find_first_merges(struct repository *repo,
11351135
contains_another = 0;
11361136
for (j = 0; j < merges.nr; j++) {
11371137
struct commit *m2 = (struct commit *) merges.objects[j].item;
1138-
if (i != j && in_merge_bases(m2, m1)) {
1138+
if (i != j && repo_in_merge_bases(repo, m2, m1)) {
11391139
contains_another = 1;
11401140
break;
11411141
}
@@ -1171,6 +1171,8 @@ static int merge_submodule(struct merge_options *opt,
11711171
const struct object_id *base, const struct object_id *a,
11721172
const struct object_id *b)
11731173
{
1174+
struct repository subrepo;
1175+
int ret = 0;
11741176
struct commit *commit_base, *commit_a, *commit_b;
11751177
int parent_count;
11761178
struct object_array merges;
@@ -1194,27 +1196,36 @@ static int merge_submodule(struct merge_options *opt,
11941196
if (is_null_oid(b))
11951197
return 0;
11961198

1199+
/*
1200+
* NEEDSWORK: Remove this when all submodule object accesses are
1201+
* through explicitly specified repositores.
1202+
*/
11971203
if (add_submodule_odb(path)) {
11981204
output(opt, 1, _("Failed to merge submodule %s (not checked out)"), path);
11991205
return 0;
12001206
}
12011207

1202-
if (!(commit_base = lookup_commit_reference(opt->repo, base)) ||
1203-
!(commit_a = lookup_commit_reference(opt->repo, a)) ||
1204-
!(commit_b = lookup_commit_reference(opt->repo, b))) {
1205-
output(opt, 1, _("Failed to merge submodule %s (commits not present)"), path);
1208+
if (repo_submodule_init(&subrepo, opt->repo, path, null_oid())) {
1209+
output(opt, 1, _("Failed to merge submodule %s (not checked out)"), path);
12061210
return 0;
12071211
}
12081212

1213+
if (!(commit_base = lookup_commit_reference(&subrepo, base)) ||
1214+
!(commit_a = lookup_commit_reference(&subrepo, a)) ||
1215+
!(commit_b = lookup_commit_reference(&subrepo, b))) {
1216+
output(opt, 1, _("Failed to merge submodule %s (commits not present)"), path);
1217+
goto cleanup;
1218+
}
1219+
12091220
/* check whether both changes are forward */
1210-
if (!in_merge_bases(commit_base, commit_a) ||
1211-
!in_merge_bases(commit_base, commit_b)) {
1221+
if (!repo_in_merge_bases(&subrepo, commit_base, commit_a) ||
1222+
!repo_in_merge_bases(&subrepo, commit_base, commit_b)) {
12121223
output(opt, 1, _("Failed to merge submodule %s (commits don't follow merge-base)"), path);
1213-
return 0;
1224+
goto cleanup;
12141225
}
12151226

12161227
/* Case #1: a is contained in b or vice versa */
1217-
if (in_merge_bases(commit_a, commit_b)) {
1228+
if (repo_in_merge_bases(&subrepo, commit_a, commit_b)) {
12181229
oidcpy(result, b);
12191230
if (show(opt, 3)) {
12201231
output(opt, 3, _("Fast-forwarding submodule %s to the following commit:"), path);
@@ -1224,9 +1235,10 @@ static int merge_submodule(struct merge_options *opt,
12241235
else
12251236
; /* no output */
12261237

1227-
return 1;
1238+
ret = 1;
1239+
goto cleanup;
12281240
}
1229-
if (in_merge_bases(commit_b, commit_a)) {
1241+
if (repo_in_merge_bases(&subrepo, commit_b, commit_a)) {
12301242
oidcpy(result, a);
12311243
if (show(opt, 3)) {
12321244
output(opt, 3, _("Fast-forwarding submodule %s to the following commit:"), path);
@@ -1236,7 +1248,8 @@ static int merge_submodule(struct merge_options *opt,
12361248
else
12371249
; /* no output */
12381250

1239-
return 1;
1251+
ret = 1;
1252+
goto cleanup;
12401253
}
12411254

12421255
/*
@@ -1248,10 +1261,10 @@ static int merge_submodule(struct merge_options *opt,
12481261

12491262
/* Skip the search if makes no sense to the calling context. */
12501263
if (!search)
1251-
return 0;
1264+
goto cleanup;
12521265

12531266
/* find commit which merges them */
1254-
parent_count = find_first_merges(opt->repo, &merges, path,
1267+
parent_count = find_first_merges(&subrepo, &merges, path,
12551268
commit_a, commit_b);
12561269
switch (parent_count) {
12571270
case 0:
@@ -1278,7 +1291,9 @@ static int merge_submodule(struct merge_options *opt,
12781291
}
12791292

12801293
object_array_clear(&merges);
1281-
return 0;
1294+
cleanup:
1295+
repo_clear(&subrepo);
1296+
return ret;
12821297
}
12831298

12841299
static int merge_mode_and_contents(struct merge_options *opt,

repository.c

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -190,19 +190,15 @@ int repo_init(struct repository *repo,
190190

191191
int repo_submodule_init(struct repository *subrepo,
192192
struct repository *superproject,
193-
const struct submodule *sub)
193+
const char *path,
194+
const struct object_id *treeish_name)
194195
{
195196
struct strbuf gitdir = STRBUF_INIT;
196197
struct strbuf worktree = STRBUF_INIT;
197198
int ret = 0;
198199

199-
if (!sub) {
200-
ret = -1;
201-
goto out;
202-
}
203-
204-
strbuf_repo_worktree_path(&gitdir, superproject, "%s/.git", sub->path);
205-
strbuf_repo_worktree_path(&worktree, superproject, "%s", sub->path);
200+
strbuf_repo_worktree_path(&gitdir, superproject, "%s/.git", path);
201+
strbuf_repo_worktree_path(&worktree, superproject, "%s", path);
206202

207203
if (repo_init(subrepo, gitdir.buf, worktree.buf)) {
208204
/*
@@ -212,6 +208,13 @@ int repo_submodule_init(struct repository *subrepo,
212208
* in the superproject's 'modules' directory. In this case the
213209
* submodule would not have a worktree.
214210
*/
211+
const struct submodule *sub =
212+
submodule_from_path(superproject, treeish_name, path);
213+
if (!sub) {
214+
ret = -1;
215+
goto out;
216+
}
217+
215218
strbuf_reset(&gitdir);
216219
strbuf_repo_git_path(&gitdir, superproject,
217220
"modules/%s", sub->name);
@@ -225,7 +228,7 @@ int repo_submodule_init(struct repository *subrepo,
225228
subrepo->submodule_prefix = xstrfmt("%s%s/",
226229
superproject->submodule_prefix ?
227230
superproject->submodule_prefix :
228-
"", sub->path);
231+
"", path);
229232

230233
out:
231234
strbuf_release(&gitdir);

0 commit comments

Comments
 (0)