merge-recursive: write the commit title in one go

In 66a155b (Enable output buffering in merge-recursive., 2007-01-14), we changed the code such that it prints the output in one go, to avoid interfering with the progress output. Let's make sure that the same holds true when outputting the commit title: previously, we used several printf() statements to stdout and assumed that stdout's buffer is large enough to hold the entire commit title. Apart from making that speculation unnecessary, we change the code to add the message to the output buffer before flushing for another reason: the next commit will introduce a new level of output buffering, where the caller can request the output not to be flushed, but to be retained for further processing. This latter feature will be needed when teaching the sequencer to do rebase -i's brunt work: it wants to control the output of the cherry-picks (i.e. recursive merges). Signed-off-by: Johannes Schindelin <johannes.schindelin@gmx.de> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Johannes Schindelin committed Aug 1, 2016 at 13:44 UTC dde75cb0561fa8a6bbb2de4c3662dbcc33728938
1 file changed +9 -8
merge-recursive.c
+9 -8
@@ -191,25 +191,26 @@ static void output(struct merge_options *o, int v, const char *fmt, ...)
191
192 static void output_commit_title(struct merge_options *o, struct commit *commit)
193 {
194 - int i;
195 - flush_output(o);
196 - for (i = o->call_depth; i--;)
197 - fputs(" ", stdout);
194 + strbuf_addchars(&o->obuf, ' ', o->call_depth * 2);
195 if (commit->util)
199 - printf("virtual %s\n", merge_remote_util(commit)->name);
196 + strbuf_addf(&o->obuf, "virtual %s\n",
197 + merge_remote_util(commit)->name);
198 else {
201 - printf("%s ", find_unique_abbrev(commit->object.oid.hash, DEFAULT_ABBREV));
199 + strbuf_addf(&o->obuf, "%s ",
200 + find_unique_abbrev(commit->object.oid.hash,
201 + DEFAULT_ABBREV));
202 if (parse_commit(commit) != 0)
203 - printf(_("(bad commit)\n"));
203 + strbuf_addf(&o->obuf, _("(bad commit)\n"));
204 else {
205 const char *title;
206 const char *msg = get_commit_buffer(commit, NULL);
207 int len = find_commit_subject(msg, &title);
208 if (len)
209 - printf("%.*s\n", len, title);
209 + strbuf_addf(&o->obuf, "%.*s\n", len, title);
210 unuse_commit_buffer(commit, msg);
211 }
212 }
213 + flush_output(o);
214 }
215
216 static int add_cacheinfo(struct merge_options *o,