git/list[1] front-page[2] threads[3] people[4] search[5] about
 

[PATCH 3/4] Enable output buffering in merge-recursive.

From
Shawn O. Pearce <spearce@spearce.org>
Date
Jan 14, 2007, 05:28 UTC
Message-ID
<20070114052853.GC19113@spearce.org>
In-Reply-To
<d352c8adb1ec1c4e74b33d51d397d5756b82ceac.1168752482.git.spearce@spearce.org>

Buffering all message output until a merge invocation is complete is necessary to prevent intereferring with a progress meter that would indicate the number of files completely merged, and how many remain. This change does not introduce a progress meter, but merely lays the groundwork to buffer the output.

To aid debugging output buffering is only enabled if verbosity is lower than 5. When using verbosity levels above 5 the user is probably debugging the merge program itself and does not want to see the output delayed, especially if they are stepping through portions of the code in a debugger.

Signed-off-by: Shawn O. Pearce <spearce@spearce.org>
---
 merge-recursive.c |   40 +++++++++++++++++++++++++++++++++++++++-
 1 files changed, 39 insertions(+), 1 deletions(-)
diff --git a/merge-recursive.c b/merge-recursive.c
index 05f9311..c16062b 100644
--- a/merge-recursive.c
+++ b/merge-recursive.c
@@ -67,11 +67,19 @@ struct stage_data
 	unsigned processed:1;
 };
 
+struct output_buffer
+{
+	struct output_buffer *next;
+	char *str;
+};
+
 static struct path_list current_file_set = {NULL, 0, 0, 1};
 static struct path_list current_directory_set = {NULL, 0, 0, 1};
 
 static int call_depth = 0;
 static int verbosity = 2;
+static int buffer_output = 1;
+static struct output_buffer *output_list, *output_end;
 
 static int show (int v)
 {
@@ -82,7 +90,16 @@ static void output(int v, const char *fmt, ...)
 {
 	va_list args;
 	va_start(args, fmt);
-	if (show(v)) {
+	if (buffer_output && show(v)) {
+		struct output_buffer *b = xmalloc(sizeof(*b));
+		nfvasprintf(&b->str, fmt, args);
+		b->next = NULL;
+		if (output_end)
+			output_end->next = b;
+		else
+			output_list = b;
+		output_end = b;
+	} else if (show(v)) {
 		int i;
 		for (i = call_depth; i--;)
 			fputs("  ", stdout);
@@ -92,9 +109,27 @@ static void output(int v, const char *fmt, ...)
 	va_end(args);
 }
 
+static void flush_output()
+{
+	struct output_buffer *b, *n;
+	for (b = output_list; b; b = n) {
+		int i;
+		for (i = call_depth; i--;)
+			fputs("  ", stdout);
+		fputs(b->str, stdout);
+		fputc('\n', stdout);
+		n = b->next;
+		free(b->str);
+		free(b);
+	}
+	output_list = NULL;
+	output_end = NULL;
+}
+
 static void output_commit_title(struct commit *commit)
 {
 	int i;
+	flush_output();
 	for (i = call_depth; i--;)
 		fputs("  ", stdout);
 	if (commit->util)
@@ -1175,6 +1210,7 @@ static int merge(struct commit *h1,
 		commit_list_insert(h1, &(*result)->parents);
 		commit_list_insert(h2, &(*result)->parents->next);
 	}
+	flush_output();
 	return clean;
 }
 
@@ -1252,6 +1288,8 @@ int main(int argc, char *argv[])
 
 	branch1 = better_branch_name(branch1);
 	branch2 = better_branch_name(branch2);
+	if (verbosity >= 5)
+		buffer_output = 0;
 	if (show(3))
 		printf("Merging %s with %s\n", branch1, branch2);
 
-- 
1.5.0.rc1.g4494
Previous: Shawn O. PearceNext: Shawn O. Pearce
Message 2 of 6 in “Allow the user to control the verbosity of merge-recursive.”
  1. 2/4 Allow the user to control the verbosity of merge-recursive.Shawn O. Pearce, Jan 14, 2007
  2. 3/4 Enable output buffering in merge-recursive.Shawn O. Pearce, Jan 14, 2007
  3. 4/4 Display a progress meter during merge-recursive.Shawn O. Pearce, Jan 14, 2007
  4. Johannes SchindelinJan 14, 2007
  5. Junio C HamanoJan 14, 2007
  6. Shawn O. PearceJan 14, 2007

Read the whole thread, see it on lore, or plain text.

$ cat FOOTERMessages come from the public archive at lore.kernel.org/git, fetched every hour. The front page is chosen and written each morning by an AI editor and can be wrong; the threads themselves are the record. About and API. For agents: an MCP server at https://gitlist.dev/mcp, and any thread, story or person page as Markdown by adding .md to its URL (or sending Accept: text/markdown). Details in /llms.txt.