@matheusbsbs / matheus-bagliano / commits / 9130ac9fe1
Fork 0

rev-list: handle %x00 NUL in user format

The code paths for showing commits in "git log" and "git rev-list --graph" correctly handle embedded NULs by looking only at the resulting strbuf's length, and never treating it as a C string. The code path for regular rev-list, however, used printf("%s"), which resulted in truncated output. This patch uses fwrite instead, like the --graph code path. Signed-off-by: Jeff King <peff@peff.net> Signed-off-by: Junio C Hamano <gitster@pobox.com>

Jeff King committed Oct 7, 2010 at 14:25 UTC 9130ac9fe17831445690ebbb60f09b86f96516b3
4 files changed +16 -6
builtin/rev-list.c
+4 -2
@@ -147,8 +147,10 @@ static void show_commit(struct commit *commit, void *data)
147 }
148 } else {
149 if (revs->commit_format != CMIT_FMT_USERFORMAT ||
150 - buf.len)
151 - printf("%s%c", buf.buf, info->hdr_termination);
150 + buf.len) {
151 + fwrite(buf.buf, 1, buf.len, stdout);
152 + putchar(info->hdr_termination);
153 + }
154 }
155 strbuf_release(&buf);
156 } else {
t/t4012-diff-binary.sh
-4
@@ -77,10 +77,6 @@ test_expect_success 'apply binary patch' \
77 tree1=`git write-tree` &&
78 test "$tree1" = "$tree0"'
79
80 -nul_to_q() {
81 - perl -pe 'y/\000/Q/'
82 -}
83 -
80 test_expect_success 'diff --no-index with binary creation' '
81 echo Q | q_to_nul >binary &&
82 (: hide error code from diff, which just indicates differences
t/t6006-rev-list-format.sh
+8
@@ -162,6 +162,14 @@ commit 131a310eb913d107dd3c09a65d1651175898735d
162 commit 86c75cfd708a0e5868dc876ed5b8bb66c80b4873
163 EOF
164
165 +test_expect_success '%x00 shows NUL' '
166 + echo >expect commit f58db70b055c5718631e5c61528b28b12090cdea &&
167 + echo >>expect fooQbar &&
168 + git rev-list -1 --format=foo%x00bar HEAD >actual.nul &&
169 + nul_to_q <actual.nul >actual &&
170 + test_cmp expect actual
171 +'
172 +
173 test_expect_success '%ad respects --date=' '
174 echo 2005-04-07 >expect.ad-short &&
175 git log -1 --date=short --pretty=tformat:%ad >output.ad-short master &&
t/test-lib.sh
+4
@@ -248,6 +248,10 @@ test_decode_color () {
248 -e 's/.\[m/<RESET>/g'
249 }
250
251 +nul_to_q () {
252 + perl -pe 'y/\000/Q/'
253 +}
254 +
255 q_to_nul () {
256 perl -pe 'y/Q/\000/'
257 }