Example #1
0
int git_blob_filtered_content(
	git_buf *out,
	git_blob *blob,
	const char *path,
	int check_for_binary_data)
{
	int error = 0;
	git_filter_list *fl = NULL;

	assert(blob && path && out);

	git_buf_sanitize(out);

	if (check_for_binary_data && git_blob_is_binary(blob))
		return 0;

	if (!(error = git_filter_list_load(
			&fl, git_blob_owner(blob), blob, path,
			GIT_FILTER_TO_WORKTREE, GIT_FILTER_DEFAULT))) {

		error = git_filter_list_apply_to_blob(out, fl, blob);

		git_filter_list_free(fl);
	}

	return error;
}
Example #2
0
File: blob.c Project: ipmcc/pygit2
PyObject *
Blob_is_binary__get__(Blob *self)
{
    if (git_blob_is_binary(self->blob))
        Py_RETURN_TRUE;
    Py_RETURN_FALSE;
}
/*
 *  call-seq:
 *    blob.binary? -> true or false
 *
 *  Determine if the blob content is most certainly binary or not.
 *
 *  The heuristic used to guess if a file is binary is taken from core git:
 *  Searching for NUL bytes and looking for a reasonable ratio of printable
 *  to non-printable characters among the first 4000 bytes.
 *
 */
static VALUE rb_git_blob_is_binary(VALUE self)
{
	git_blob *blob;
	Data_Get_Struct(self, git_blob, blob);
	return git_blob_is_binary(blob) ? Qtrue : Qfalse;
}
Example #4
0
void test_diff_blob__can_correctly_detect_a_textual_blob_as_non_binary(void)
{
	/* tests/resources/attr/root_test4.txt */
	cl_assert_equal_i(false, git_blob_is_binary(d));
}
Example #5
0
void test_diff_blob__can_correctly_detect_a_binary_blob_as_binary(void)
{
	/* alien.png */
	cl_assert_equal_i(true, git_blob_is_binary(alien));
}