rev-list: use hdr_termination instead of a always using a newline

When adding support for prefixing output of log and other commands using --line-prefix, commit 660e113ce118 ("graph: add support for --line-prefix on all graph-aware output", 2016-08-31) accidentally broke rev-list --header output. In order to make the output appear with a line-prefix, the flow was changed to always use the graph subsystem for display. Unfortunately the graph flow in rev-list did not use info->hdr_termination as it was assumed that graph output would never need to putput NULs. Since we now always use the graph code in order to handle the case of line-prefix, simply replace putchar('\n') with putchar(info->hdr_termination) which will correct this issue. Add a test for the --header case to make sure we don't break it in the future. Reported-by: Dennis Kaarsemaker <dennis@kaarsemaker.net> Signed-off-by: Jacob Keller <jacob.keller@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com> Signed-off-by: Jacob Keller <jacob.keller@gmail.com> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jacob Keller committed Oct 20, 2016 at 13:41 UTC 98985c6911ca0d475ae7b4e5401e6eae58ed8489
2 files changed +15 -1
builtin/rev-list.c
+1 -1
@@ -145,7 +145,7 @@ static void show_commit(struct commit *commit, void *data)
145 */
146 if (buf.len && buf.buf[buf.len - 1] == '\n')
147 graph_show_padding(revs->graph);
148 - putchar('\n');
148 + putchar(info->hdr_termination);
149 } else {
150 /*
151 * If the message buffer is empty, just show
t/t6000-rev-list-misc.sh
+14
@@ -100,4 +100,18 @@ test_expect_success '--bisect and --first-parent can not be combined' '
100 test_must_fail git rev-list --bisect --first-parent HEAD
101 '
102
103 +test_expect_success '--header shows a NUL after each commit' '
104 + # We know that there is no Q in the true payload; names and
105 + # addresses of the authors and the committers do not have
106 + # any, and object names or header names do not, either.
107 + git rev-list --header --max-count=2 HEAD |
108 + nul_to_q |
109 + grep "^Q" >actual &&
110 + cat >expect <<-EOF &&
111 + Q$(git rev-parse HEAD~1)
112 + Q
113 + EOF
114 + test_cmp expect actual
115 +'
116 +
117 test_done