Enable output buffering in merge-recursive.
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> Signed-off-by: Junio C Hamano <junkio@cox.net>
Shawn O. Pearce committed
Jan 14, 2007 at 00:28 UTC
66a155bc129b12f1f13be8e3f20e57db5ace0e6f
1 file changed
+39
-1
merge-recursive.c
+39
-1
@@ -67,11 +67,19 @@ struct stage_data
67
unsigned processed:1;
68
};
69
70
+struct output_buffer
71
+{
72
+ struct output_buffer *next;
73
+ char *str;
74
+};
75
+
76
static struct path_list current_file_set = {NULL, 0, 0, 1};
77
static struct path_list current_directory_set = {NULL, 0, 0, 1};
78
79
static int call_depth = 0;
80
static int verbosity = 2;
81
+static int buffer_output = 1;
82
+static struct output_buffer *output_list, *output_end;
83
84
static int show (int v)
85
{
@@ -82,7 +90,16 @@ static void output(int v, const char *fmt, ...)
90
{
91
va_list args;
92
va_start(args, fmt);
85
- if (show(v)) {
93
+ if (buffer_output && show(v)) {
94
+ struct output_buffer *b = xmalloc(sizeof(*b));
95
+ nfvasprintf(&b->str, fmt, args);
96
+ b->next = NULL;
97
+ if (output_end)
98
+ output_end->next = b;
99
+ else
100
+ output_list = b;
101
+ output_end = b;
102
+ } else if (show(v)) {
103
int i;
104
for (i = call_depth; i--;)
105
fputs(" ", stdout);
@@ -92,9 +109,27 @@ static void output(int v, const char *fmt, ...)
109
va_end(args);
110
}
111
112
+static void flush_output()
113
+{
114
+ struct output_buffer *b, *n;
115
+ for (b = output_list; b; b = n) {
116
+ int i;
117
+ for (i = call_depth; i--;)
118
+ fputs(" ", stdout);
119
+ fputs(b->str, stdout);
120
+ fputc('\n', stdout);
121
+ n = b->next;
122
+ free(b->str);
123
+ free(b);
124
+ }
125
+ output_list = NULL;
126
+ output_end = NULL;
127
+}
128
+
129
static void output_commit_title(struct commit *commit)
130
{
131
int i;
132
+ flush_output();
133
for (i = call_depth; i--;)
134
fputs(" ", stdout);
135
if (commit->util)
@@ -1175,6 +1210,7 @@ static int merge(struct commit *h1,
1210
commit_list_insert(h1, &(*result)->parents);
1211
commit_list_insert(h2, &(*result)->parents->next);
1212
}
1213
+ flush_output();
1214
return clean;
1215
}
1216
@@ -1252,6 +1288,8 @@ int main(int argc, char *argv[])
1288
1289
branch1 = better_branch_name(branch1);
1290
branch2 = better_branch_name(branch2);
1291
+ if (verbosity >= 5)
1292
+ buffer_output = 0;
1293
if (show(3))
1294
printf("Merging %s with %s\n", branch1, branch2);
1295