Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
git2
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
lvzhengyang
git2
Commits
160e4fb7
Commit
160e4fb7
authored
Jan 11, 2013
by
Vicent Martí
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #1230 from arrbee/match-core-git-diff-binary-detection
Match binary file check of core git in diff
parents
6e19edaa
0d65acad
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
42 additions
and
1 deletions
+42
-1
src/buf_text.c
+5
-0
src/buf_text.h
+8
-0
src/diff_output.c
+6
-1
tests-clar/core/buffer.c
+23
-0
No files found.
src/buf_text.c
View file @
160e4fb7
...
...
@@ -109,6 +109,11 @@ bool git_buf_text_is_binary(const git_buf *buf)
return
((
printable
>>
7
)
<
nonprintable
);
}
bool
git_buf_text_contains_nul
(
const
git_buf
*
buf
)
{
return
(
strnlen
(
buf
->
ptr
,
buf
->
size
)
!=
buf
->
size
);
}
int
git_buf_text_detect_bom
(
git_bom_t
*
bom
,
const
git_buf
*
buf
,
size_t
offset
)
{
const
char
*
ptr
;
...
...
src/buf_text.h
View file @
160e4fb7
...
...
@@ -71,6 +71,14 @@ extern int git_buf_text_common_prefix(git_buf *buf, const git_strarray *strs);
extern
bool
git_buf_text_is_binary
(
const
git_buf
*
buf
);
/**
* Check quickly if buffer contains a NUL byte
*
* @param buf Buffer to check
* @return true if buffer contains a NUL byte
*/
extern
bool
git_buf_text_contains_nul
(
const
git_buf
*
buf
);
/**
* Check if a buffer begins with a UTF BOM
*
* @param bom Set to the type of BOM detected or GIT_BOM_NONE
...
...
src/diff_output.c
View file @
160e4fb7
...
...
@@ -142,7 +142,12 @@ static int diff_delta_is_binary_by_content(
GIT_UNUSED
(
ctxt
);
if
((
file
->
flags
&
KNOWN_BINARY_FLAGS
)
==
0
)
{
if
(
git_buf_text_is_binary
(
&
search
))
/* TODO: provide encoding / binary detection callbacks that can
* be UTF-8 aware, etc. For now, instead of trying to be smart,
* let's just use the simple NUL-byte detection that core git uses.
*/
/* previously was: if (git_buf_text_is_binary(&search)) */
if
(
git_buf_text_contains_nul
(
&
search
))
file
->
flags
|=
GIT_DIFF_FILE_BINARY
;
else
file
->
flags
|=
GIT_DIFF_FILE_NOT_BINARY
;
...
...
tests-clar/core/buffer.c
View file @
160e4fb7
...
...
@@ -704,3 +704,26 @@ void test_core_buffer__base64(void)
git_buf_free
(
&
buf
);
}
void
test_core_buffer__classify_with_utf8
(
void
)
{
char
*
data0
=
"Simple text
\n
"
;
size_t
data0len
=
12
;
char
*
data1
=
"Is that UTF-8 data I see…
\n
Yep!
\n
"
;
size_t
data1len
=
31
;
char
*
data2
=
"Internal NUL!!!
\000\n\n
I see you!
\n
"
;
size_t
data2len
=
29
;
git_buf
b
;
b
.
ptr
=
data0
;
b
.
size
=
b
.
asize
=
data0len
;
cl_assert
(
!
git_buf_text_is_binary
(
&
b
));
cl_assert
(
!
git_buf_text_contains_nul
(
&
b
));
b
.
ptr
=
data1
;
b
.
size
=
b
.
asize
=
data1len
;
cl_assert
(
git_buf_text_is_binary
(
&
b
));
cl_assert
(
!
git_buf_text_contains_nul
(
&
b
));
b
.
ptr
=
data2
;
b
.
size
=
b
.
asize
=
data2len
;
cl_assert
(
git_buf_text_is_binary
(
&
b
));
cl_assert
(
git_buf_text_contains_nul
(
&
b
));
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment