Skip to content

Commit de90581

Browse files
newrengitster
authored andcommitted
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 <[email protected]> Signed-off-by: Johannes Schindelin <[email protected]> Signed-off-by: Junio C Hamano <[email protected]>
1 parent cb26077 commit de90581

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

builtin/merge-tree.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -468,7 +468,8 @@ static int real_merge(struct merge_tree_options *o,
468468
}
469469
if (o->show_messages) {
470470
putchar(line_termination);
471-
merge_display_update_messages(&opt, &result);
471+
merge_display_update_messages(&opt, line_termination == '\0',
472+
&result);
472473
}
473474
merge_finalize(&opt, &result);
474475
return !result.clean; /* result.clean < 0 handled above */

merge-ort.c

Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4413,6 +4413,7 @@ static int record_conflicted_index_entries(struct merge_options *opt)
44134413
}
44144414

44154415
void merge_display_update_messages(struct merge_options *opt,
4416+
int detailed,
44164417
struct merge_result *result)
44174418
{
44184419
struct merge_options_internal *opti = result->priv;
@@ -4438,8 +4439,25 @@ void merge_display_update_messages(struct merge_options *opt,
44384439
/* Iterate over the items, printing them */
44394440
for (int path_nr = 0; path_nr < olist.nr; ++path_nr) {
44404441
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+
}
44424457
puts(conflicts->items[i].string);
4458+
if (detailed)
4459+
putchar('\0');
4460+
}
44434461
}
44444462
string_list_clear(&olist, 0);
44454463

@@ -4519,7 +4537,7 @@ void merge_switch_to_result(struct merge_options *opt,
45194537
trace2_region_leave("merge", "write_auto_merge", opt->repo);
45204538
}
45214539
if (display_update_msgs)
4522-
merge_display_update_messages(opt, result);
4540+
merge_display_update_messages(opt, /* detailed */ 0, result);
45234541

45244542
merge_finalize(opt, result);
45254543
}

merge-ort.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,6 +87,7 @@ void merge_switch_to_result(struct merge_options *opt,
8787
* so only call this when bypassing merge_switch_to_result().
8888
*/
8989
void merge_display_update_messages(struct merge_options *opt,
90+
int detailed,
9091
struct merge_result *result);
9192

9293
struct stage_info {

0 commit comments

Comments
 (0)