From de90581141a886a79cccd0d9adb76814f3e1ab2c Mon Sep 17 00:00:00 2001 From: Elijah Newren Date: Sat, 18 Jun 2022 00:20:57 +0000 Subject: 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: NUL ... NUL NUL The `` field determines how many `` 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 Signed-off-by: Johannes Schindelin Signed-off-by: Junio C Hamano --- merge-ort.c | 22 ++++++++++++++++++++-- 1 file changed, 20 insertions(+), 2 deletions(-) (limited to 'merge-ort.c') diff --git a/merge-ort.c b/merge-ort.c index 6081b29705..01f150ef3b 100644 --- a/merge-ort.c +++ b/merge-ort.c @@ -4413,6 +4413,7 @@ static int record_conflicted_index_entries(struct merge_options *opt) } void merge_display_update_messages(struct merge_options *opt, + int detailed, struct merge_result *result) { struct merge_options_internal *opti = result->priv; @@ -4438,8 +4439,25 @@ void merge_display_update_messages(struct merge_options *opt, /* Iterate over the items, printing them */ for (int path_nr = 0; path_nr < olist.nr; ++path_nr) { struct string_list *conflicts = olist.items[path_nr].util; - for (int i = 0; i < conflicts->nr; i++) + for (int i = 0; i < conflicts->nr; i++) { + struct logical_conflict_info *info = + conflicts->items[i].util; + + if (detailed) { + printf("%lu", (unsigned long)info->paths.nr); + putchar('\0'); + for (int n = 0; n < info->paths.nr; n++) { + fputs(info->paths.v[n], stdout); + putchar('\0'); + } + fputs(type_short_descriptions[info->type], + stdout); + putchar('\0'); + } puts(conflicts->items[i].string); + if (detailed) + putchar('\0'); + } } string_list_clear(&olist, 0); @@ -4519,7 +4537,7 @@ void merge_switch_to_result(struct merge_options *opt, trace2_region_leave("merge", "write_auto_merge", opt->repo); } if (display_update_msgs) - merge_display_update_messages(opt, result); + merge_display_update_messages(opt, /* detailed */ 0, result); merge_finalize(opt, result); } -- cgit v1.2.3