Skip to content

Commit 10a0d6a

Browse files
jonathantanmygitster
authored andcommitted
revision: remove "submodule" from opt struct
Clean up a TODO in revision.h by removing the "submodule" field from struct setup_revision_opt. This field is only used to specify the ref store to use, so use rev_info->repo to determine the ref store instead. The only users of this field are merge-ort.c and merge-recursive.c. However, both these files specify the superproject as rev_info->repo and the submodule as setup_revision_opt->submodule. In order to be able to pass the submodule as rev_info->repo, all commits must be parsed with the submodule explicitly specified; this patch does that as well. (An incremental solution in which only some commits are parsed with explicit submodule will not work, because if the same commit is parsed twice in different repositories, there will be 2 heap-allocated object structs corresponding to that commit, and any flag set by the revision walking mechanism on one of them will not be reflected onto the other.) Signed-off-by: Jonathan Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8eb8dcf commit 10a0d6a

File tree

4 files changed

+72
-47
lines changed

4 files changed

+72
-47
lines changed

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"
@@ -1499,7 +1500,6 @@ static int find_first_merges(struct repository *repo,
14991500
xsnprintf(merged_revision, sizeof(merged_revision), "^%s",
15001501
oid_to_hex(&a->object.oid));
15011502
repo_init_revisions(repo, &revs, NULL);
1502-
rev_opts.submodule = path;
15031503
/* FIXME: can't handle linked worktrees in submodules yet */
15041504
revs.single_worktree = path != NULL;
15051505
setup_revisions(ARRAY_SIZE(rev_args)-1, rev_args, &revs, &rev_opts);
@@ -1509,7 +1509,7 @@ static int find_first_merges(struct repository *repo,
15091509
die("revision walk setup failed");
15101510
while ((commit = get_revision(&revs)) != NULL) {
15111511
struct object *o = &(commit->object);
1512-
if (in_merge_bases(b, commit))
1512+
if (repo_in_merge_bases(repo, b, commit))
15131513
add_object_array(o, NULL, &merges);
15141514
}
15151515
reset_revision_walk();
@@ -1524,7 +1524,7 @@ static int find_first_merges(struct repository *repo,
15241524
contains_another = 0;
15251525
for (j = 0; j < merges.nr; j++) {
15261526
struct commit *m2 = (struct commit *) merges.objects[j].item;
1527-
if (i != j && in_merge_bases(m2, m1)) {
1527+
if (i != j && repo_in_merge_bases(repo, m2, m1)) {
15281528
contains_another = 1;
15291529
break;
15301530
}
@@ -1545,10 +1545,12 @@ static int merge_submodule(struct merge_options *opt,
15451545
const struct object_id *b,
15461546
struct object_id *result)
15471547
{
1548+
struct repository subrepo;
1549+
struct strbuf sb = STRBUF_INIT;
1550+
int ret = 0;
15481551
struct commit *commit_o, *commit_a, *commit_b;
15491552
int parent_count;
15501553
struct object_array merges;
1551-
struct strbuf sb = STRBUF_INIT;
15521554

15531555
int i;
15541556
int search = !opt->priv->call_depth;
@@ -1564,46 +1566,59 @@ static int merge_submodule(struct merge_options *opt,
15641566
if (is_null_oid(b))
15651567
return 0;
15661568

1569+
/*
1570+
* NEEDSWORK: Remove this when all submodule object accesses are
1571+
* through explicitly specified repositores.
1572+
*/
15671573
if (add_submodule_odb(path)) {
15681574
path_msg(opt, path, 0,
15691575
_("Failed to merge submodule %s (not checked out)"),
15701576
path);
15711577
return 0;
15721578
}
15731579

1574-
if (!(commit_o = lookup_commit_reference(opt->repo, o)) ||
1575-
!(commit_a = lookup_commit_reference(opt->repo, a)) ||
1576-
!(commit_b = lookup_commit_reference(opt->repo, b))) {
1580+
if (repo_submodule_init(&subrepo, opt->repo, path, null_oid())) {
1581+
path_msg(opt, path, 0,
1582+
_("Failed to merge submodule %s (not checked out)"),
1583+
path);
1584+
return 0;
1585+
}
1586+
1587+
if (!(commit_o = lookup_commit_reference(&subrepo, o)) ||
1588+
!(commit_a = lookup_commit_reference(&subrepo, a)) ||
1589+
!(commit_b = lookup_commit_reference(&subrepo, b))) {
15771590
path_msg(opt, path, 0,
15781591
_("Failed to merge submodule %s (commits not present)"),
15791592
path);
1580-
return 0;
1593+
goto cleanup;
15811594
}
15821595

15831596
/* check whether both changes are forward */
1584-
if (!in_merge_bases(commit_o, commit_a) ||
1585-
!in_merge_bases(commit_o, commit_b)) {
1597+
if (!repo_in_merge_bases(&subrepo, commit_o, commit_a) ||
1598+
!repo_in_merge_bases(&subrepo, commit_o, commit_b)) {
15861599
path_msg(opt, path, 0,
15871600
_("Failed to merge submodule %s "
15881601
"(commits don't follow merge-base)"),
15891602
path);
1590-
return 0;
1603+
goto cleanup;
15911604
}
15921605

15931606
/* Case #1: a is contained in b or vice versa */
1594-
if (in_merge_bases(commit_a, commit_b)) {
1607+
if (repo_in_merge_bases(&subrepo, commit_a, commit_b)) {
15951608
oidcpy(result, b);
15961609
path_msg(opt, path, 1,
15971610
_("Note: Fast-forwarding submodule %s to %s"),
15981611
path, oid_to_hex(b));
1599-
return 1;
1612+
ret = 1;
1613+
goto cleanup;
16001614
}
1601-
if (in_merge_bases(commit_b, commit_a)) {
1615+
if (repo_in_merge_bases(&subrepo, commit_b, commit_a)) {
16021616
oidcpy(result, a);
16031617
path_msg(opt, path, 1,
16041618
_("Note: Fast-forwarding submodule %s to %s"),
16051619
path, oid_to_hex(a));
1606-
return 1;
1620+
ret = 1;
1621+
goto cleanup;
16071622
}
16081623

16091624
/*
@@ -1615,10 +1630,10 @@ static int merge_submodule(struct merge_options *opt,
16151630

16161631
/* Skip the search if makes no sense to the calling context. */
16171632
if (!search)
1618-
return 0;
1633+
goto cleanup;
16191634

16201635
/* find commit which merges them */
1621-
parent_count = find_first_merges(opt->repo, path, commit_a, commit_b,
1636+
parent_count = find_first_merges(&subrepo, path, commit_a, commit_b,
16221637
&merges);
16231638
switch (parent_count) {
16241639
case 0:
@@ -1652,7 +1667,9 @@ static int merge_submodule(struct merge_options *opt,
16521667
}
16531668

16541669
object_array_clear(&merges);
1655-
return 0;
1670+
cleanup:
1671+
repo_clear(&subrepo);
1672+
return ret;
16561673
}
16571674

16581675
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"
@@ -1113,7 +1114,6 @@ static int find_first_merges(struct repository *repo,
11131114
xsnprintf(merged_revision, sizeof(merged_revision), "^%s",
11141115
oid_to_hex(&a->object.oid));
11151116
repo_init_revisions(repo, &revs, NULL);
1116-
rev_opts.submodule = path;
11171117
/* FIXME: can't handle linked worktrees in submodules yet */
11181118
revs.single_worktree = path != NULL;
11191119
setup_revisions(ARRAY_SIZE(rev_args)-1, rev_args, &revs, &rev_opts);
@@ -1123,7 +1123,7 @@ static int find_first_merges(struct repository *repo,
11231123
die("revision walk setup failed");
11241124
while ((commit = get_revision(&revs)) != NULL) {
11251125
struct object *o = &(commit->object);
1126-
if (in_merge_bases(b, commit))
1126+
if (repo_in_merge_bases(repo, b, commit))
11271127
add_object_array(o, NULL, &merges);
11281128
}
11291129
reset_revision_walk();
@@ -1138,7 +1138,7 @@ static int find_first_merges(struct repository *repo,
11381138
contains_another = 0;
11391139
for (j = 0; j < merges.nr; j++) {
11401140
struct commit *m2 = (struct commit *) merges.objects[j].item;
1141-
if (i != j && in_merge_bases(m2, m1)) {
1141+
if (i != j && repo_in_merge_bases(repo, m2, m1)) {
11421142
contains_another = 1;
11431143
break;
11441144
}
@@ -1174,6 +1174,8 @@ static int merge_submodule(struct merge_options *opt,
11741174
const struct object_id *base, const struct object_id *a,
11751175
const struct object_id *b)
11761176
{
1177+
struct repository subrepo;
1178+
int ret = 0;
11771179
struct commit *commit_base, *commit_a, *commit_b;
11781180
int parent_count;
11791181
struct object_array merges;
@@ -1197,27 +1199,36 @@ static int merge_submodule(struct merge_options *opt,
11971199
if (is_null_oid(b))
11981200
return 0;
11991201

1202+
/*
1203+
* NEEDSWORK: Remove this when all submodule object accesses are
1204+
* through explicitly specified repositores.
1205+
*/
12001206
if (add_submodule_odb(path)) {
12011207
output(opt, 1, _("Failed to merge submodule %s (not checked out)"), path);
12021208
return 0;
12031209
}
12041210

1205-
if (!(commit_base = lookup_commit_reference(opt->repo, base)) ||
1206-
!(commit_a = lookup_commit_reference(opt->repo, a)) ||
1207-
!(commit_b = lookup_commit_reference(opt->repo, b))) {
1208-
output(opt, 1, _("Failed to merge submodule %s (commits not present)"), path);
1211+
if (repo_submodule_init(&subrepo, opt->repo, path, null_oid())) {
1212+
output(opt, 1, _("Failed to merge submodule %s (not checked out)"), path);
12091213
return 0;
12101214
}
12111215

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

12191230
/* Case #1: a is contained in b or vice versa */
1220-
if (in_merge_bases(commit_a, commit_b)) {
1231+
if (repo_in_merge_bases(&subrepo, commit_a, commit_b)) {
12211232
oidcpy(result, b);
12221233
if (show(opt, 3)) {
12231234
output(opt, 3, _("Fast-forwarding submodule %s to the following commit:"), path);
@@ -1227,9 +1238,10 @@ static int merge_submodule(struct merge_options *opt,
12271238
else
12281239
; /* no output */
12291240

1230-
return 1;
1241+
ret = 1;
1242+
goto cleanup;
12311243
}
1232-
if (in_merge_bases(commit_b, commit_a)) {
1244+
if (repo_in_merge_bases(&subrepo, commit_b, commit_a)) {
12331245
oidcpy(result, a);
12341246
if (show(opt, 3)) {
12351247
output(opt, 3, _("Fast-forwarding submodule %s to the following commit:"), path);
@@ -1239,7 +1251,8 @@ static int merge_submodule(struct merge_options *opt,
12391251
else
12401252
; /* no output */
12411253

1242-
return 1;
1254+
ret = 1;
1255+
goto cleanup;
12431256
}
12441257

12451258
/*
@@ -1251,10 +1264,10 @@ static int merge_submodule(struct merge_options *opt,
12511264

12521265
/* Skip the search if makes no sense to the calling context. */
12531266
if (!search)
1254-
return 0;
1267+
goto cleanup;
12551268

12561269
/* find commit which merges them */
1257-
parent_count = find_first_merges(opt->repo, &merges, path,
1270+
parent_count = find_first_merges(&subrepo, &merges, path,
12581271
commit_a, commit_b);
12591272
switch (parent_count) {
12601273
case 0:
@@ -1281,7 +1294,9 @@ static int merge_submodule(struct merge_options *opt,
12811294
}
12821295

12831296
object_array_clear(&merges);
1284-
return 0;
1297+
cleanup:
1298+
repo_clear(&subrepo);
1299+
return ret;
12851300
}
12861301

12871302
static int merge_mode_and_contents(struct merge_options *opt,

revision.c

Lines changed: 5 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2561,16 +2561,15 @@ static int for_each_good_bisect_ref(struct ref_store *refs, each_ref_fn fn, void
25612561
return for_each_bisect_ref(refs, fn, cb_data, term_good);
25622562
}
25632563

2564-
static int handle_revision_pseudo_opt(const char *submodule,
2565-
struct rev_info *revs,
2564+
static int handle_revision_pseudo_opt(struct rev_info *revs,
25662565
const char **argv, int *flags)
25672566
{
25682567
const char *arg = argv[0];
25692568
const char *optarg;
25702569
struct ref_store *refs;
25712570
int argcount;
25722571

2573-
if (submodule) {
2572+
if (revs->repo != the_repository) {
25742573
/*
25752574
* We need some something like get_submodule_worktrees()
25762575
* before we can go through all worktrees of a submodule,
@@ -2579,9 +2578,8 @@ static int handle_revision_pseudo_opt(const char *submodule,
25792578
*/
25802579
if (!revs->single_worktree)
25812580
BUG("--single-worktree cannot be used together with submodule");
2582-
refs = get_submodule_ref_store(submodule);
2583-
} else
2584-
refs = get_main_ref_store(revs->repo);
2581+
}
2582+
refs = get_main_ref_store(revs->repo);
25852583

25862584
/*
25872585
* NOTE!
@@ -2699,12 +2697,8 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
26992697
{
27002698
int i, flags, left, seen_dashdash, revarg_opt;
27012699
struct strvec prune_data = STRVEC_INIT;
2702-
const char *submodule = NULL;
27032700
int seen_end_of_options = 0;
27042701

2705-
if (opt)
2706-
submodule = opt->submodule;
2707-
27082702
/* First, search for "--" */
27092703
if (opt && opt->assume_dashdash) {
27102704
seen_dashdash = 1;
@@ -2733,7 +2727,7 @@ int setup_revisions(int argc, const char **argv, struct rev_info *revs, struct s
27332727
if (!seen_end_of_options && *arg == '-') {
27342728
int opts;
27352729

2736-
opts = handle_revision_pseudo_opt(submodule,
2730+
opts = handle_revision_pseudo_opt(
27372731
revs, argv + i,
27382732
&flags);
27392733
if (opts > 0) {

revision.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -339,7 +339,6 @@ extern volatile show_early_output_fn_t show_early_output;
339339
struct setup_revision_opt {
340340
const char *def;
341341
void (*tweak)(struct rev_info *, struct setup_revision_opt *);
342-
const char *submodule; /* TODO: drop this and use rev_info->repo */
343342
unsigned int assume_dashdash:1,
344343
allow_exclude_promisor_objects:1;
345344
unsigned revarg_opt;

0 commit comments

Comments
 (0)