diff.c: move line ending check into emit_hunk_header
The emit_hunk_header() function is responsible for assembling a hunk header and calling emit_line() to send the hunk header to the output file. Its only caller fn_out_consume() needs to prepare for a case where the function emits an incomplete line and add the terminating LF. Instead make sure emit_hunk_header() to always send a completed line to emit_line(). Signed-off-by: Stefan Beller <sbeller@google.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>
Stefan Beller committed
Jun 29, 2017 at 17:06 UTC
dfb7728f637e8178189f9f8f0092797403c73509
1 file changed
+2
-2
diff.c
+2
-2
@@ -678,6 +678,8 @@ static void emit_hunk_header(struct emit_callback *ecbdata,
678
}
679
680
strbuf_add(&msgbuf, line + len, org_len - len);
681
+ strbuf_complete_line(&msgbuf);
682
+
683
emit_line(ecbdata->opt, "", "", msgbuf.buf, msgbuf.len);
684
strbuf_release(&msgbuf);
685
}
@@ -1315,8 +1317,6 @@ static void fn_out_consume(void *priv, char *line, unsigned long len)
1317
len = sane_truncate_line(ecbdata, line, len);
1318
find_lno(line, ecbdata);
1319
emit_hunk_header(ecbdata, line, len);
1318
- if (line[len-1] != '\n')
1319
- putc('\n', o->file);
1320
return;
1321
}
1322