diff mbox series

[v7,14/17] merge-ort: optionally produce machine-readable output

Message ID 662e97f2ed4b6a0698bb86493efc3650763600d3.1655511660.git.gitgitgadget@gmail.com (mailing list archive)
State Accepted
Commit de90581141a886a79cccd0d9adb76814f3e1ab2c
Headers show
Series In-core git merge-tree ("Server side merges") | expand

Commit Message

Elijah Newren June 18, 2022, 12:20 a.m. UTC
From: Elijah Newren <newren@gmail.com>

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>
---
 builtin/merge-tree.c |  3 ++-
 merge-ort.c          | 22 ++++++++++++++++++++--
 merge-ort.h          |  1 +
 3 files changed, 23 insertions(+), 3 deletions(-)
diff mbox series

Patch

diff --git a/builtin/merge-tree.c b/builtin/merge-tree.c
index c61b5b4a10d..b3c5692498e 100644
--- a/builtin/merge-tree.c
+++ b/builtin/merge-tree.c
@@ -468,7 +468,8 @@  static int real_merge(struct merge_tree_options *o,
 	}
 	if (o->show_messages) {
 		putchar(line_termination);
-		merge_display_update_messages(&opt, &result);
+		merge_display_update_messages(&opt, line_termination == '\0',
+					      &result);
 	}
 	merge_finalize(&opt, &result);
 	return !result.clean; /* result.clean < 0 handled above */
diff --git a/merge-ort.c b/merge-ort.c
index 432937255f6..4a56c189ddf 100644
--- a/merge-ort.c
+++ b/merge-ort.c
@@ -4412,6 +4412,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;
@@ -4437,8 +4438,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);
 
@@ -4518,7 +4536,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);
 }
diff --git a/merge-ort.h b/merge-ort.h
index c4909bcbf96..a994c9a5fcd 100644
--- a/merge-ort.h
+++ b/merge-ort.h
@@ -87,6 +87,7 @@  void merge_switch_to_result(struct merge_options *opt,
  * so only call this when bypassing merge_switch_to_result().
  */
 void merge_display_update_messages(struct merge_options *opt,
+				   int detailed,
 				   struct merge_result *result);
 
 struct stage_info {