1 From 49424f9357a6428c72f660a11fe8e68c45f512b1 Mon Sep 17 00:00:00 2001
2 From: Sven Strickroth <email@cs-ware.de>
3 Date: Thu, 13 Nov 2014 19:30:47 +0100
4 Subject: [PATCH] Make binary detection work similar to vanilla git
6 Main change: Don't treat chars > 128 as non-printable (common in UTF-8 files)
8 Signed-off-by: Sven Strickroth <email@cs-ware.de>
11 tests/core/buffer.c | 2 +-
12 2 files changed, 2 insertions(+), 2 deletions(-)
14 diff --git a/src/buf_text.c b/src/buf_text.c
15 index 8d2b141..99abefa 100644
18 @@ -190,7 +190,7 @@ bool git_buf_text_is_binary(const git_buf *buf)
20 unsigned char c = *scan++;
22 - if (c > 0x1F && c < 0x7F)
23 + if ((c > 0x1F && c != 127) || c == '\b' || c == '\033' || c == '\014') /* handle BS, ESC and FF and all (chars > 0x1F excluding DEL) as printable */
27 diff --git a/tests/core/buffer.c b/tests/core/buffer.c
28 index 641fed6..4549d9f 100644
29 --- a/tests/core/buffer.c
30 +++ b/tests/core/buffer.c
31 @@ -831,7 +831,7 @@ void test_core_buffer__classify_with_utf8(void)
32 cl_assert(!git_buf_text_contains_nul(&b));
34 b.ptr = data1; b.size = b.asize = data1len;
35 - cl_assert(git_buf_text_is_binary(&b));
36 + cl_assert(!git_buf_text_is_binary(&b)); // UTF-8 files are not considered binary (in vanilly git)
37 cl_assert(!git_buf_text_contains_nul(&b));
39 b.ptr = data2; b.size = b.asize = data2len;