From e4f031e34b08e3217c10942e682920a6939308a0 Mon Sep 17 00:00:00 2001 From: Jeff King Date: Tue, 30 Jun 2015 09:26:53 -0400 Subject: strbuf: make strbuf_addftime more robust The return value of strftime is poorly designed; when it returns 0, the caller cannot tell if the buffer was not large enough, or if the output was actually 0 bytes. In the original implementation of strbuf_addftime, we simply punted and guessed that our 128-byte hint would be large enough. We can do better, though, if we're willing to treat strftime like less of a black box. We can munge the incoming format to make sure that it never produces 0-length output, and then "fix" the resulting output. That lets us reliably grow the buffer based on strftime's return value. Clever-idea-by: Eric Sunshine Signed-off-by: Jeff King Signed-off-by: Junio C Hamano --- t/t6300-for-each-ref.sh | 10 ++++++++++ 1 file changed, 10 insertions(+) (limited to 't/t6300-for-each-ref.sh') diff --git a/t/t6300-for-each-ref.sh b/t/t6300-for-each-ref.sh index c7f368c77..7c9bec763 100755 --- a/t/t6300-for-each-ref.sh +++ b/t/t6300-for-each-ref.sh @@ -235,6 +235,16 @@ test_expect_success 'Check format of strftime date fields' ' test_cmp expected actual ' +test_expect_success 'exercise strftime with odd fields' ' + echo >expected && + git for-each-ref --format="%(authordate:format:)" refs/heads >actual && + test_cmp expected actual && + long="long format -- $_z40$_z40$_z40$_z40$_z40$_z40$_z40" && + echo $long >expected && + git for-each-ref --format="%(authordate:format:$long)" refs/heads >actual && + test_cmp expected actual +' + cat >expected <<\EOF refs/heads/master refs/remotes/origin/master -- cgit v1.2.1