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
a50bbba1
Unverified
Commit
a50bbba1
authored
Dec 23, 2021
by
Edward Thomson
Committed by
GitHub
Dec 23, 2021
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #6142 from libgit2/ethomson/blob_data_is_binary
blob: identify binary content
parents
05c3d972
4591e76a
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
37 additions
and
0 deletions
+37
-0
include/git2/blob.h
+12
-0
src/blob.c
+9
-0
tests/diff/blob.c
+16
-0
No files found.
include/git2/blob.h
View file @
a50bbba1
...
@@ -285,6 +285,18 @@ GIT_EXTERN(int) git_blob_create_from_buffer(
...
@@ -285,6 +285,18 @@ GIT_EXTERN(int) git_blob_create_from_buffer(
GIT_EXTERN
(
int
)
git_blob_is_binary
(
const
git_blob
*
blob
);
GIT_EXTERN
(
int
)
git_blob_is_binary
(
const
git_blob
*
blob
);
/**
/**
* Determine if the given content is most certainly binary or not;
* this is the same mechanism used by `git_blob_is_binary` but only
* looking at raw data.
*
* @param data The blob data which content should be analyzed
* @param len The length of the data
* @return 1 if the content of the blob is detected
* as binary; 0 otherwise.
*/
GIT_EXTERN
(
int
)
git_blob_data_is_binary
(
const
char
*
data
,
size_t
len
);
/**
* Create an in-memory copy of a blob. The copy must be explicitly
* Create an in-memory copy of a blob. The copy must be explicitly
* free'd or it will leak.
* free'd or it will leak.
*
*
...
...
src/blob.c
View file @
a50bbba1
...
@@ -404,6 +404,15 @@ int git_blob_is_binary(const git_blob *blob)
...
@@ -404,6 +404,15 @@ int git_blob_is_binary(const git_blob *blob)
return
git_str_is_binary
(
&
content
);
return
git_str_is_binary
(
&
content
);
}
}
int
git_blob_data_is_binary
(
const
char
*
str
,
size_t
len
)
{
git_str
content
=
GIT_STR_INIT
;
git_str_attach_notowned
(
&
content
,
str
,
len
);
return
git_str_is_binary
(
&
content
);
}
int
git_blob_filter_options_init
(
int
git_blob_filter_options_init
(
git_blob_filter_options
*
opts
,
git_blob_filter_options
*
opts
,
unsigned
int
version
)
unsigned
int
version
)
...
...
tests/diff/blob.c
View file @
a50bbba1
...
@@ -604,12 +604,28 @@ void test_diff_blob__can_correctly_detect_a_binary_blob_as_binary(void)
...
@@ -604,12 +604,28 @@ void test_diff_blob__can_correctly_detect_a_binary_blob_as_binary(void)
cl_assert_equal_i
(
true
,
git_blob_is_binary
(
alien
));
cl_assert_equal_i
(
true
,
git_blob_is_binary
(
alien
));
}
}
void
test_diff_blob__can_correctly_detect_binary_blob_data_as_binary
(
void
)
{
/* alien.png */
const
char
*
content
=
git_blob_rawcontent
(
alien
);
size_t
len
=
(
size_t
)
git_blob_rawsize
(
alien
);
cl_assert_equal_i
(
true
,
git_blob_data_is_binary
(
content
,
len
));
}
void
test_diff_blob__can_correctly_detect_a_textual_blob_as_non_binary
(
void
)
void
test_diff_blob__can_correctly_detect_a_textual_blob_as_non_binary
(
void
)
{
{
/* tests/resources/attr/root_test4.txt */
/* tests/resources/attr/root_test4.txt */
cl_assert_equal_i
(
false
,
git_blob_is_binary
(
d
));
cl_assert_equal_i
(
false
,
git_blob_is_binary
(
d
));
}
}
void
test_diff_blob__can_correctly_detect_textual_blob_data_as_non_binary
(
void
)
{
/* tests/resources/attr/root_test4.txt */
const
char
*
content
=
git_blob_rawcontent
(
d
);
size_t
len
=
(
size_t
)
git_blob_rawsize
(
d
);
cl_assert_equal_i
(
false
,
git_blob_data_is_binary
(
content
,
len
));
}
/*
/*
* git_diff_blob_to_buffer tests
* git_diff_blob_to_buffer tests
*/
*/
...
...
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