Exemplo n.º 1
0
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…\nYep!\n";
	size_t data1len = 31;
	char *data2 = "Internal NUL!!!\000\n\nI see you!\n";
	size_t data2len = 29;
	char *data3 = "\xef\xbb\xbfThis is UTF-8 with a BOM.\n";
	size_t data3len = 20;
	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));

	b.ptr = data3; b.size = b.asize = data3len;
	cl_assert(!git_buf_text_is_binary(&b));
	cl_assert(!git_buf_text_contains_nul(&b));
}
Exemplo n.º 2
0
int git_blob_is_binary(const git_blob *blob)
{
	git_buf content = GIT_BUF_INIT;

	assert(blob);

	git_buf_attach_notowned(&content, git_blob_rawcontent(blob),
		min(git_blob_rawsize(blob),
		GIT_FILTER_BYTES_TO_CHECK_NUL));
	return git_buf_text_is_binary(&content);
}
Exemplo n.º 3
0
int git_blob_is_binary(const git_blob *blob)
{
	git_buf content = GIT_BUF_INIT;

	assert(blob);

	git_buf_attach_notowned(&content, blob->odb_object->buffer,
		min(blob->odb_object->cached.size,
		GIT_FILTER_BYTES_TO_CHECK_NUL));
	return git_buf_text_is_binary(&content);
}
Exemplo n.º 4
0
Arquivo: blob.c Projeto: 0CV0/libgit2
int git_blob_is_binary(git_blob *blob)
{
	git_buf content;

	assert(blob);

	content.ptr = blob->odb_object->buffer;
	content.size = min(blob->odb_object->cached.size, 4000);

	return git_buf_text_is_binary(&content);
}
Exemplo n.º 5
0
int git_blob_is_binary(git_blob *blob)
{
	git_buf content;

	assert(blob);

	content.ptr = blob->odb_object->raw.data;
	content.size = min(blob->odb_object->raw.len, 4000);

	return git_buf_text_is_binary(&content);
}
Exemplo n.º 6
0
int git_blob_is_binary(const git_blob *blob)
{
	git_buf content;

	assert(blob);

	content.ptr   = (char*) blob->odb_object->buffer;
	content.size  =
		min(blob->odb_object->cached.size, GIT_FILTER_BYTES_TO_CHECK_NUL);
	content.asize = 0;

	return git_buf_text_is_binary(&content);
}
Exemplo n.º 7
0
static int ident_apply(
	git_filter     *self,
	void          **payload,
	git_buf        *to,
	const git_buf  *from,
	const git_filter_source *src)
{
	GIT_UNUSED(self); GIT_UNUSED(payload);

	/* Don't filter binary files */
	if (git_buf_text_is_binary(from))
		return GIT_PASSTHROUGH;

	if (git_filter_source_mode(src) == GIT_FILTER_SMUDGE)
		return ident_insert_id(to, from, src);
	else
		return ident_remove_id(to, from);
}
Exemplo n.º 8
0
static int crlf_apply_to_workdir(
	struct crlf_attrs *ca, git_buf *to, const git_buf *from)
{
	const char *workdir_ending = NULL;

	/* Empty file? Nothing to do. */
	if (git_buf_len(from) == 0)
		return 0;

	/* Don't filter binary files */
	if (git_buf_text_is_binary(from))
		return GIT_PASSTHROUGH;

	/* Determine proper line ending */
	workdir_ending = line_ending(ca);
	if (!workdir_ending)
		return -1;

	/* only LF->CRLF conversion is supported, do nothing on LF platforms */
	if (strcmp(workdir_ending, "\r\n") != 0)
		return GIT_PASSTHROUGH;

	return git_buf_text_lf_to_crlf(to, from);
}