merge-ort: optionally produce machine-readable output
With the new `detailed` parameter, a new mode can be triggered when displaying the merge messages: The `detailed` mode prints NUL-delimited fields of the following form: <path-count> NUL <path>... NUL <conflict-type> NUL <message> The `<path-count>` field determines how many `<path>` fields there are. The intention of this mode is to support server-side operations, where worktree-less merges can lead to conflicts and depending on the type and/or path count, the caller might know how to handle said conflict. Signed-off-by: Elijah Newren <newren@gmail.com> Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Elijah Newren committed
Jun 18, 2022 at 00:20 UTC
de90581141a886a79cccd0d9adb76814f3e1ab2c
3 files changed
+23
-3
builtin/merge-tree.c
+2
-1
@@ -468,7 +468,8 @@ static int real_merge(struct merge_tree_options *o,
468
}
469
if (o->show_messages) {
470
putchar(line_termination);
471
- merge_display_update_messages(&opt, &result);
471
+ merge_display_update_messages(&opt, line_termination == '\0',
472
+ &result);
473
}
474
merge_finalize(&opt, &result);
475
return !result.clean; /* result.clean < 0 handled above */
merge-ort.c
+20
-2
@@ -4413,6 +4413,7 @@ static int record_conflicted_index_entries(struct merge_options *opt)
4413
}
4414
4415
void merge_display_update_messages(struct merge_options *opt,
4416
+ int detailed,
4417
struct merge_result *result)
4418
{
4419
struct merge_options_internal *opti = result->priv;
@@ -4438,8 +4439,25 @@ void merge_display_update_messages(struct merge_options *opt,
4439
/* Iterate over the items, printing them */
4440
for (int path_nr = 0; path_nr < olist.nr; ++path_nr) {
4441
struct string_list *conflicts = olist.items[path_nr].util;
4441
- for (int i = 0; i < conflicts->nr; i++)
4442
+ for (int i = 0; i < conflicts->nr; i++) {
4443
+ struct logical_conflict_info *info =
4444
+ conflicts->items[i].util;
4445
+
4446
+ if (detailed) {
4447
+ printf("%lu", (unsigned long)info->paths.nr);
4448
+ putchar('\0');
4449
+ for (int n = 0; n < info->paths.nr; n++) {
4450
+ fputs(info->paths.v[n], stdout);
4451
+ putchar('\0');
4452
+ }
4453
+ fputs(type_short_descriptions[info->type],
4454
+ stdout);
4455
+ putchar('\0');
4456
+ }
4457
puts(conflicts->items[i].string);
4458
+ if (detailed)
4459
+ putchar('\0');
4460
+ }
4461
}
4462
string_list_clear(&olist, 0);
4463
@@ -4519,7 +4537,7 @@ void merge_switch_to_result(struct merge_options *opt,
4537
trace2_region_leave("merge", "write_auto_merge", opt->repo);
4538
}
4539
if (display_update_msgs)
4522
- merge_display_update_messages(opt, result);
4540
+ merge_display_update_messages(opt, /* detailed */ 0, result);
4541
4542
merge_finalize(opt, result);
4543
}
merge-ort.h
+1
@@ -87,6 +87,7 @@ void merge_switch_to_result(struct merge_options *opt,
87
* so only call this when bypassing merge_switch_to_result().
88
*/
89
void merge_display_update_messages(struct merge_options *opt,
90
+ int detailed,
91
struct merge_result *result);
92
93
struct stage_info {