Skip to content

Commit 155b517

Browse files
jonathantanmygitster
authored andcommitted
merge-{ort,recursive}: remove add_submodule_odb()
After the parent commit and some of its ancestors, the only place commits are being accessed through alternates is in the user-facing message formatting code. Fix those, and remove the add_submodule_odb() calls. Signed-off-by: Jonathan Tan <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent 8788195 commit 155b517

File tree

5 files changed

+40
-40
lines changed

5 files changed

+40
-40
lines changed

merge-ort.c

Lines changed: 4 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,7 @@ static int err(struct merge_options *opt, const char *err, ...)
609609

610610
static void format_commit(struct strbuf *sb,
611611
int indent,
612+
struct repository *repo,
612613
struct commit *commit)
613614
{
614615
struct merge_remote_desc *desc;
@@ -622,7 +623,7 @@ static void format_commit(struct strbuf *sb,
622623
return;
623624
}
624625

625-
format_commit_message(commit, "%h %s", sb, &ctx);
626+
repo_format_commit_message(repo, commit, "%h %s", sb, &ctx);
626627
strbuf_addch(sb, '\n');
627628
}
628629

@@ -1578,17 +1579,6 @@ static int merge_submodule(struct merge_options *opt,
15781579
if (is_null_oid(b))
15791580
return 0;
15801581

1581-
/*
1582-
* NEEDSWORK: Remove this when all submodule object accesses are
1583-
* through explicitly specified repositores.
1584-
*/
1585-
if (add_submodule_odb(path)) {
1586-
path_msg(opt, path, 0,
1587-
_("Failed to merge submodule %s (not checked out)"),
1588-
path);
1589-
return 0;
1590-
}
1591-
15921582
if (repo_submodule_init(&subrepo, opt->repo, path, null_oid())) {
15931583
path_msg(opt, path, 0,
15941584
_("Failed to merge submodule %s (not checked out)"),
@@ -1653,7 +1643,7 @@ static int merge_submodule(struct merge_options *opt,
16531643
break;
16541644

16551645
case 1:
1656-
format_commit(&sb, 4,
1646+
format_commit(&sb, 4, &subrepo,
16571647
(struct commit *)merges.objects[0].item);
16581648
path_msg(opt, path, 0,
16591649
_("Failed to merge submodule %s, but a possible merge "
@@ -1670,7 +1660,7 @@ static int merge_submodule(struct merge_options *opt,
16701660
break;
16711661
default:
16721662
for (i = 0; i < merges.nr; i++)
1673-
format_commit(&sb, 4,
1663+
format_commit(&sb, 4, &subrepo,
16741664
(struct commit *)merges.objects[i].item);
16751665
path_msg(opt, path, 0,
16761666
_("Failed to merge submodule %s, but multiple "

merge-recursive.c

Lines changed: 20 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,9 @@ static void output(struct merge_options *opt, int v, const char *fmt, ...)
334334
flush_output(opt);
335335
}
336336

337-
static void output_commit_title(struct merge_options *opt, struct commit *commit)
337+
static void repo_output_commit_title(struct merge_options *opt,
338+
struct repository *repo,
339+
struct commit *commit)
338340
{
339341
struct merge_remote_desc *desc;
340342

@@ -343,23 +345,29 @@ static void output_commit_title(struct merge_options *opt, struct commit *commit
343345
if (desc)
344346
strbuf_addf(&opt->obuf, "virtual %s\n", desc->name);
345347
else {
346-
strbuf_add_unique_abbrev(&opt->obuf, &commit->object.oid,
347-
DEFAULT_ABBREV);
348+
strbuf_repo_add_unique_abbrev(&opt->obuf, repo,
349+
&commit->object.oid,
350+
DEFAULT_ABBREV);
348351
strbuf_addch(&opt->obuf, ' ');
349-
if (parse_commit(commit) != 0)
352+
if (repo_parse_commit(repo, commit) != 0)
350353
strbuf_addstr(&opt->obuf, _("(bad commit)\n"));
351354
else {
352355
const char *title;
353-
const char *msg = get_commit_buffer(commit, NULL);
356+
const char *msg = repo_get_commit_buffer(repo, commit, NULL);
354357
int len = find_commit_subject(msg, &title);
355358
if (len)
356359
strbuf_addf(&opt->obuf, "%.*s\n", len, title);
357-
unuse_commit_buffer(commit, msg);
360+
repo_unuse_commit_buffer(repo, commit, msg);
358361
}
359362
}
360363
flush_output(opt);
361364
}
362365

366+
static void output_commit_title(struct merge_options *opt, struct commit *commit)
367+
{
368+
repo_output_commit_title(opt, the_repository, commit);
369+
}
370+
363371
static int add_cacheinfo(struct merge_options *opt,
364372
const struct diff_filespec *blob,
365373
const char *path, int stage, int refresh, int options)
@@ -1149,14 +1157,14 @@ static int find_first_merges(struct repository *repo,
11491157
return result->nr;
11501158
}
11511159

1152-
static void print_commit(struct commit *commit)
1160+
static void print_commit(struct repository *repo, struct commit *commit)
11531161
{
11541162
struct strbuf sb = STRBUF_INIT;
11551163
struct pretty_print_context ctx = {0};
11561164
ctx.date_mode.type = DATE_NORMAL;
11571165
/* FIXME: Merge this with output_commit_title() */
11581166
assert(!merge_remote_util(commit));
1159-
format_commit_message(commit, " %h: %m %s", &sb, &ctx);
1167+
repo_format_commit_message(repo, commit, " %h: %m %s", &sb, &ctx);
11601168
fprintf(stderr, "%s\n", sb.buf);
11611169
strbuf_release(&sb);
11621170
}
@@ -1196,15 +1204,6 @@ static int merge_submodule(struct merge_options *opt,
11961204
if (is_null_oid(b))
11971205
return 0;
11981206

1199-
/*
1200-
* NEEDSWORK: Remove this when all submodule object accesses are
1201-
* through explicitly specified repositores.
1202-
*/
1203-
if (add_submodule_odb(path)) {
1204-
output(opt, 1, _("Failed to merge submodule %s (not checked out)"), path);
1205-
return 0;
1206-
}
1207-
12081207
if (repo_submodule_init(&subrepo, opt->repo, path, null_oid())) {
12091208
output(opt, 1, _("Failed to merge submodule %s (not checked out)"), path);
12101209
return 0;
@@ -1229,7 +1228,7 @@ static int merge_submodule(struct merge_options *opt,
12291228
oidcpy(result, b);
12301229
if (show(opt, 3)) {
12311230
output(opt, 3, _("Fast-forwarding submodule %s to the following commit:"), path);
1232-
output_commit_title(opt, commit_b);
1231+
repo_output_commit_title(opt, &subrepo, commit_b);
12331232
} else if (show(opt, 2))
12341233
output(opt, 2, _("Fast-forwarding submodule %s"), path);
12351234
else
@@ -1242,7 +1241,7 @@ static int merge_submodule(struct merge_options *opt,
12421241
oidcpy(result, a);
12431242
if (show(opt, 3)) {
12441243
output(opt, 3, _("Fast-forwarding submodule %s to the following commit:"), path);
1245-
output_commit_title(opt, commit_a);
1244+
repo_output_commit_title(opt, &subrepo, commit_a);
12461245
} else if (show(opt, 2))
12471246
output(opt, 2, _("Fast-forwarding submodule %s"), path);
12481247
else
@@ -1274,7 +1273,7 @@ static int merge_submodule(struct merge_options *opt,
12741273
case 1:
12751274
output(opt, 1, _("Failed to merge submodule %s (not fast-forward)"), path);
12761275
output(opt, 2, _("Found a possible merge resolution for the submodule:\n"));
1277-
print_commit((struct commit *) merges.objects[0].item);
1276+
print_commit(&subrepo, (struct commit *) merges.objects[0].item);
12781277
output(opt, 2, _(
12791278
"If this is correct simply add it to the index "
12801279
"for example\n"
@@ -1287,7 +1286,7 @@ static int merge_submodule(struct merge_options *opt,
12871286
default:
12881287
output(opt, 1, _("Failed to merge submodule %s (multiple merges found)"), path);
12891288
for (i = 0; i < merges.nr; i++)
1290-
print_commit((struct commit *) merges.objects[i].item);
1289+
print_commit(&subrepo, (struct commit *) merges.objects[i].item);
12911290
}
12921291

12931292
object_array_clear(&merges);

strbuf.c

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1059,15 +1059,21 @@ void strbuf_addftime(struct strbuf *sb, const char *fmt, const struct tm *tm,
10591059
strbuf_setlen(sb, sb->len + len);
10601060
}
10611061

1062-
void strbuf_add_unique_abbrev(struct strbuf *sb, const struct object_id *oid,
1063-
int abbrev_len)
1062+
void strbuf_repo_add_unique_abbrev(struct strbuf *sb, struct repository *repo,
1063+
const struct object_id *oid, int abbrev_len)
10641064
{
10651065
int r;
10661066
strbuf_grow(sb, GIT_MAX_HEXSZ + 1);
1067-
r = find_unique_abbrev_r(sb->buf + sb->len, oid, abbrev_len);
1067+
r = repo_find_unique_abbrev_r(repo, sb->buf + sb->len, oid, abbrev_len);
10681068
strbuf_setlen(sb, sb->len + r);
10691069
}
10701070

1071+
void strbuf_add_unique_abbrev(struct strbuf *sb, const struct object_id *oid,
1072+
int abbrev_len)
1073+
{
1074+
strbuf_repo_add_unique_abbrev(sb, the_repository, oid, abbrev_len);
1075+
}
1076+
10711077
/*
10721078
* Returns the length of a line, without trailing spaces.
10731079
*

strbuf.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -634,8 +634,10 @@ void strbuf_list_free(struct strbuf **list);
634634
* Add the abbreviation, as generated by find_unique_abbrev, of `sha1` to
635635
* the strbuf `sb`.
636636
*/
637-
void strbuf_add_unique_abbrev(struct strbuf *sb,
638-
const struct object_id *oid,
637+
struct repository;
638+
void strbuf_repo_add_unique_abbrev(struct strbuf *sb, struct repository *repo,
639+
const struct object_id *oid, int abbrev_len);
640+
void strbuf_add_unique_abbrev(struct strbuf *sb, const struct object_id *oid,
639641
int abbrev_len);
640642

641643
/**

t/t6437-submodule-merge.sh

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,9 @@ test_description='merging with submodules'
55
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
66
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
77

8+
GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1
9+
export GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB
10+
811
. ./test-lib.sh
912
. "$TEST_DIRECTORY"/lib-merge.sh
1013

0 commit comments

Comments
 (0)