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 <jonathantanmy@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Jonathan Tan committed
Oct 8, 2021 at 14:08 UTC
155b517d5c8701f3b8bef78fe59d8fe33adbee96
5 files changed
+40
-40
merge-ort.c
+4
-14
@@ -609,6 +609,7 @@ static int err(struct merge_options *opt, const char *err, ...)
609
610
static void format_commit(struct strbuf *sb,
611
int indent,
612
+ struct repository *repo,
613
struct commit *commit)
614
{
615
struct merge_remote_desc *desc;
@@ -622,7 +623,7 @@ static void format_commit(struct strbuf *sb,
623
return;
624
}
625
625
- format_commit_message(commit, "%h %s", sb, &ctx);
626
+ repo_format_commit_message(repo, commit, "%h %s", sb, &ctx);
627
strbuf_addch(sb, '\n');
628
}
629
@@ -1578,17 +1579,6 @@ static int merge_submodule(struct merge_options *opt,
1579
if (is_null_oid(b))
1580
return 0;
1581
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
-
1582
if (repo_submodule_init(&subrepo, opt->repo, path, null_oid())) {
1583
path_msg(opt, path, 0,
1584
_("Failed to merge submodule %s (not checked out)"),
@@ -1653,7 +1643,7 @@ static int merge_submodule(struct merge_options *opt,
1643
break;
1644
1645
case 1:
1656
- format_commit(&sb, 4,
1646
+ format_commit(&sb, 4, &subrepo,
1647
(struct commit *)merges.objects[0].item);
1648
path_msg(opt, path, 0,
1649
_("Failed to merge submodule %s, but a possible merge "
@@ -1670,7 +1660,7 @@ static int merge_submodule(struct merge_options *opt,
1660
break;
1661
default:
1662
for (i = 0; i < merges.nr; i++)
1673
- format_commit(&sb, 4,
1663
+ format_commit(&sb, 4, &subrepo,
1664
(struct commit *)merges.objects[i].item);
1665
path_msg(opt, path, 0,
1666
_("Failed to merge submodule %s, but multiple "
merge-recursive.c
+20
-21
@@ -334,7 +334,9 @@ static void output(struct merge_options *opt, int v, const char *fmt, ...)
334
flush_output(opt);
335
}
336
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)
340
{
341
struct merge_remote_desc *desc;
342
@@ -343,23 +345,29 @@ static void output_commit_title(struct merge_options *opt, struct commit *commit
345
if (desc)
346
strbuf_addf(&opt->obuf, "virtual %s\n", desc->name);
347
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);
351
strbuf_addch(&opt->obuf, ' ');
349
- if (parse_commit(commit) != 0)
352
+ if (repo_parse_commit(repo, commit) != 0)
353
strbuf_addstr(&opt->obuf, _("(bad commit)\n"));
354
else {
355
const char *title;
353
- const char *msg = get_commit_buffer(commit, NULL);
356
+ const char *msg = repo_get_commit_buffer(repo, commit, NULL);
357
int len = find_commit_subject(msg, &title);
358
if (len)
359
strbuf_addf(&opt->obuf, "%.*s\n", len, title);
357
- unuse_commit_buffer(commit, msg);
360
+ repo_unuse_commit_buffer(repo, commit, msg);
361
}
362
}
363
flush_output(opt);
364
}
365
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
+
371
static int add_cacheinfo(struct merge_options *opt,
372
const struct diff_filespec *blob,
373
const char *path, int stage, int refresh, int options)
@@ -1149,14 +1157,14 @@ static int find_first_merges(struct repository *repo,
1157
return result->nr;
1158
}
1159
1152
-static void print_commit(struct commit *commit)
1160
+static void print_commit(struct repository *repo, struct commit *commit)
1161
{
1162
struct strbuf sb = STRBUF_INIT;
1163
struct pretty_print_context ctx = {0};
1164
ctx.date_mode.type = DATE_NORMAL;
1165
/* FIXME: Merge this with output_commit_title() */
1166
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);
1168
fprintf(stderr, "%s\n", sb.buf);
1169
strbuf_release(&sb);
1170
}
@@ -1196,15 +1204,6 @@ static int merge_submodule(struct merge_options *opt,
1204
if (is_null_oid(b))
1205
return 0;
1206
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
-
1207
if (repo_submodule_init(&subrepo, opt->repo, path, null_oid())) {
1208
output(opt, 1, _("Failed to merge submodule %s (not checked out)"), path);
1209
return 0;
@@ -1229,7 +1228,7 @@ static int merge_submodule(struct merge_options *opt,
1228
oidcpy(result, b);
1229
if (show(opt, 3)) {
1230
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);
1232
} else if (show(opt, 2))
1233
output(opt, 2, _("Fast-forwarding submodule %s"), path);
1234
else
@@ -1242,7 +1241,7 @@ static int merge_submodule(struct merge_options *opt,
1241
oidcpy(result, a);
1242
if (show(opt, 3)) {
1243
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);
1245
} else if (show(opt, 2))
1246
output(opt, 2, _("Fast-forwarding submodule %s"), path);
1247
else
@@ -1274,7 +1273,7 @@ static int merge_submodule(struct merge_options *opt,
1273
case 1:
1274
output(opt, 1, _("Failed to merge submodule %s (not fast-forward)"), path);
1275
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);
1277
output(opt, 2, _(
1278
"If this is correct simply add it to the index "
1279
"for example\n"
@@ -1287,7 +1286,7 @@ static int merge_submodule(struct merge_options *opt,
1286
default:
1287
output(opt, 1, _("Failed to merge submodule %s (multiple merges found)"), path);
1288
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);
1290
}
1291
1292
object_array_clear(&merges);
strbuf.c
+9
-3
@@ -1059,15 +1059,21 @@ void strbuf_addftime(struct strbuf *sb, const char *fmt, const struct tm *tm,
1059
strbuf_setlen(sb, sb->len + len);
1060
}
1061
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)
1064
{
1065
int r;
1066
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);
1068
strbuf_setlen(sb, sb->len + r);
1069
}
1070
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
+
1077
/*
1078
* Returns the length of a line, without trailing spaces.
1079
*
strbuf.h
+4
-2
@@ -634,8 +634,10 @@ void strbuf_list_free(struct strbuf **list);
634
* Add the abbreviation, as generated by find_unique_abbrev, of `sha1` to
635
* the strbuf `sb`.
636
*/
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,
641
int abbrev_len);
642
643
/**
t/t6437-submodule-merge.sh
+3
@@ -5,6 +5,9 @@ test_description='merging with submodules'
5
GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME=main
6
export GIT_TEST_DEFAULT_INITIAL_BRANCH_NAME
7
8
+GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB=1
9
+export GIT_TEST_FATAL_REGISTER_SUBMODULE_ODB
10
+
11
. ./test-lib.sh
12
. "$TEST_DIRECTORY"/lib-merge.sh
13