merge-ort: split out a separate display_update_messages() function
This patch includes no new code; it simply moves a bunch of lines into a new function. As such, there are no functional changes. This is just a preparatory step to allow the printed messages to be handled differently by other callers, such as in `git merge-tree --write-tree`. (Patch best viewed with --color-moved --color-moved-ws=allow-indentation-change to see that it is a simple code movement.) Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Elijah Newren committed
Jun 18, 2022 at 00:20 UTC
a34edae68a26f8f97f6ba69f408abbd3480ed90c
2 files changed
+49
-37
merge-ort.c
+41
-37
@@ -4257,6 +4257,45 @@ static int record_conflicted_index_entries(struct merge_options *opt)
4257
return errs;
4258
}
4259
4260
+void merge_display_update_messages(struct merge_options *opt,
4261
+ struct merge_result *result)
4262
+{
4263
+ struct merge_options_internal *opti = result->priv;
4264
+ struct hashmap_iter iter;
4265
+ struct strmap_entry *e;
4266
+ struct string_list olist = STRING_LIST_INIT_NODUP;
4267
+ int i;
4268
+
4269
+ if (opt->record_conflict_msgs_as_headers)
4270
+ BUG("Either display conflict messages or record them as headers, not both");
4271
+
4272
+ trace2_region_enter("merge", "display messages", opt->repo);
4273
+
4274
+ /* Hack to pre-allocate olist to the desired size */
4275
+ ALLOC_GROW(olist.items, strmap_get_size(&opti->output),
4276
+ olist.alloc);
4277
+
4278
+ /* Put every entry from output into olist, then sort */
4279
+ strmap_for_each_entry(&opti->output, &iter, e) {
4280
+ string_list_append(&olist, e->key)->util = e->value;
4281
+ }
4282
+ string_list_sort(&olist);
4283
+
4284
+ /* Iterate over the items, printing them */
4285
+ for (i = 0; i < olist.nr; ++i) {
4286
+ struct strbuf *sb = olist.items[i].util;
4287
+
4288
+ printf("%s", sb->buf);
4289
+ }
4290
+ string_list_clear(&olist, 0);
4291
+
4292
+ /* Also include needed rename limit adjustment now */
4293
+ diff_warn_rename_limit("merge.renamelimit",
4294
+ opti->renames.needed_limit, 0);
4295
+
4296
+ trace2_region_leave("merge", "display messages", opt->repo);
4297
+}
4298
+
4299
void merge_switch_to_result(struct merge_options *opt,
4300
struct tree *head,
4301
struct merge_result *result,
@@ -4294,43 +4333,8 @@ void merge_switch_to_result(struct merge_options *opt,
4333
fclose(fp);
4334
trace2_region_leave("merge", "write_auto_merge", opt->repo);
4335
}
4297
-
4298
- if (display_update_msgs) {
4299
- struct merge_options_internal *opti = result->priv;
4300
- struct hashmap_iter iter;
4301
- struct strmap_entry *e;
4302
- struct string_list olist = STRING_LIST_INIT_NODUP;
4303
- int i;
4304
-
4305
- if (opt->record_conflict_msgs_as_headers)
4306
- BUG("Either display conflict messages or record them as headers, not both");
4307
-
4308
- trace2_region_enter("merge", "display messages", opt->repo);
4309
-
4310
- /* Hack to pre-allocate olist to the desired size */
4311
- ALLOC_GROW(olist.items, strmap_get_size(&opti->output),
4312
- olist.alloc);
4313
-
4314
- /* Put every entry from output into olist, then sort */
4315
- strmap_for_each_entry(&opti->output, &iter, e) {
4316
- string_list_append(&olist, e->key)->util = e->value;
4317
- }
4318
- string_list_sort(&olist);
4319
-
4320
- /* Iterate over the items, printing them */
4321
- for (i = 0; i < olist.nr; ++i) {
4322
- struct strbuf *sb = olist.items[i].util;
4323
-
4324
- printf("%s", sb->buf);
4325
- }
4326
- string_list_clear(&olist, 0);
4327
-
4328
- /* Also include needed rename limit adjustment now */
4329
- diff_warn_rename_limit("merge.renamelimit",
4330
- opti->renames.needed_limit, 0);
4331
-
4332
- trace2_region_leave("merge", "display messages", opt->repo);
4333
- }
4336
+ if (display_update_msgs)
4337
+ merge_display_update_messages(opt, result);
4338
4339
merge_finalize(opt, result);
4340
}
merge-ort.h
+8
@@ -80,6 +80,14 @@ void merge_switch_to_result(struct merge_options *opt,
80
int update_worktree_and_index,
81
int display_update_msgs);
82
83
+/*
84
+ * Display messages about conflicts and which files were 3-way merged.
85
+ * Automatically called by merge_switch_to_result() with stream == stdout,
86
+ * so only call this when bypassing merge_switch_to_result().
87
+ */
88
+void merge_display_update_messages(struct merge_options *opt,
89
+ struct merge_result *result);
90
+
91
/* Do needed cleanup when not calling merge_switch_to_result() */
92
void merge_finalize(struct merge_options *opt,
93
struct merge_result *result);