summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@edwardthomson.com>2021-05-12 22:36:44 +0100
committerEdward Thomson <ethomson@edwardthomson.com>2021-05-12 22:39:22 +0100
commitf4ba679a4b1213f55390d298aaea102f7551fd60 (patch)
tree41468d700b359e947b5e1afe334d5cbe440d6a71
parent6c14610a6494ea680720114c6ec6934286f40c0e (diff)
downloadlibgit2-ethomson/filter_driver_git_buf.tar.gz
filter: filter drivers stop taking git_buf as user inputethomson/filter_driver_git_buf
-rw-r--r--include/git2/sys/filter.h3
-rw-r--r--src/crlf.c9
-rw-r--r--src/filter.c3
-rw-r--r--src/ident.c11
-rw-r--r--tests/filter/custom_helpers.c28
-rw-r--r--tests/filter/custom_helpers.h6
-rw-r--r--tests/filter/wildcard.c7
7 files changed, 40 insertions, 27 deletions
diff --git a/include/git2/sys/filter.h b/include/git2/sys/filter.h
index 512860871..f474416c1 100644
--- a/include/git2/sys/filter.h
+++ b/include/git2/sys/filter.h
@@ -194,7 +194,8 @@ typedef int GIT_CALLBACK(git_filter_apply_fn)(
git_filter *self,
void **payload, /* may be read and/or set */
git_buf *to,
- const git_buf *from,
+ const char *from,
+ size_t from_len,
const git_filter_source *src);
/**
diff --git a/src/crlf.c b/src/crlf.c
index 1de9d8c3b..9c69dee8c 100644
--- a/src/crlf.c
+++ b/src/crlf.c
@@ -369,9 +369,12 @@ static int crlf_apply(
git_filter *self,
void **payload, /* may be read and/or set */
git_buf *to,
- const git_buf *from,
+ const char *from_cstr,
+ size_t from_len,
const git_filter_source *src)
{
+ const git_buf from = GIT_BUF_INIT_CONST(from_cstr, from_len);
+
/* initialize payload in case `check` was bypassed */
if (!*payload) {
int error = crlf_check(self, payload, src, NULL);
@@ -381,9 +384,9 @@ static int crlf_apply(
}
if (git_filter_source_mode(src) == GIT_FILTER_SMUDGE)
- return crlf_apply_to_workdir(*payload, to, from);
+ return crlf_apply_to_workdir(*payload, to, &from);
else
- return crlf_apply_to_odb(*payload, to, from, src);
+ return crlf_apply_to_odb(*payload, to, &from, src);
}
static void crlf_cleanup(
diff --git a/src/filter.c b/src/filter.c
index 6c09a6ad5..c1a389a8f 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -847,7 +847,8 @@ static int proxy_stream_close(git_writestream *s)
proxy_stream->filter,
proxy_stream->payload,
proxy_stream->output,
- &proxy_stream->input,
+ proxy_stream->input.ptr,
+ proxy_stream->input.size,
proxy_stream->source);
if (error == GIT_PASSTHROUGH) {
diff --git a/src/ident.c b/src/ident.c
index ae3ef1b45..4c6a7a874 100644
--- a/src/ident.c
+++ b/src/ident.c
@@ -98,19 +98,22 @@ static int ident_apply(
git_filter *self,
void **payload,
git_buf *to,
- const git_buf *from,
+ const char *from_cstr,
+ size_t from_len,
const git_filter_source *src)
{
+ git_buf from = GIT_BUF_INIT_CONST(from_cstr, from_len);
+
GIT_UNUSED(self); GIT_UNUSED(payload);
/* Don't filter binary files */
- if (git_buf_is_binary(from))
+ if (git_buf_is_binary(&from))
return GIT_PASSTHROUGH;
if (git_filter_source_mode(src) == GIT_FILTER_SMUDGE)
- return ident_insert_id(to, from, src);
+ return ident_insert_id(to, &from, src);
else
- return ident_remove_id(to, from);
+ return ident_remove_id(to, &from);
}
git_filter *git_ident_filter_new(void)
diff --git a/tests/filter/custom_helpers.c b/tests/filter/custom_helpers.c
index 233ba3219..784c794f6 100644
--- a/tests/filter/custom_helpers.c
+++ b/tests/filter/custom_helpers.c
@@ -9,10 +9,11 @@ int bitflip_filter_apply(
git_filter *self,
void **payload,
git_buf *to,
- const git_buf *from,
+ const char *from,
+ size_t from_len,
const git_filter_source *source)
{
- const unsigned char *src = (const unsigned char *)from->ptr;
+ const unsigned char *src = (const unsigned char *)from;
unsigned char *dst;
size_t i;
@@ -22,17 +23,17 @@ int bitflip_filter_apply(
cl_assert_equal_i(
0, git__strncmp("hero", git_filter_source_path(source), 4));
- if (!from->size)
+ if (!from_len)
return 0;
- cl_git_pass(git_buf_grow(to, from->size));
+ cl_git_pass(git_buf_grow(to, from_len));
dst = (unsigned char *)to->ptr;
- for (i = 0; i < from->size; i++)
+ for (i = 0; i < from_len; i++)
dst[i] = VERY_SECURE_ENCRYPTION(src[i]);
- to->size = from->size;
+ to->size = from_len;
return 0;
}
@@ -60,11 +61,12 @@ int reverse_filter_apply(
git_filter *self,
void **payload,
git_buf *to,
- const git_buf *from,
+ const char *from,
+ size_t from_len,
const git_filter_source *source)
{
- const unsigned char *src = (const unsigned char *)from->ptr;
- const unsigned char *end = src + from->size;
+ const unsigned char *src = (const unsigned char *)from;
+ const unsigned char *end = src + from_len;
unsigned char *dst;
GIT_UNUSED(self); GIT_UNUSED(payload); GIT_UNUSED(source);
@@ -73,17 +75,17 @@ int reverse_filter_apply(
cl_assert_equal_i(
0, git__strncmp("hero", git_filter_source_path(source), 4));
- if (!from->size)
+ if (!from_len)
return 0;
- cl_git_pass(git_buf_grow(to, from->size));
+ cl_git_pass(git_buf_grow(to, from_len));
- dst = (unsigned char *)to->ptr + from->size - 1;
+ dst = (unsigned char *)to->ptr + from_len - 1;
while (src < end)
*dst-- = *src++;
- to->size = from->size;
+ to->size = from_len;
return 0;
}
diff --git a/tests/filter/custom_helpers.h b/tests/filter/custom_helpers.h
index 537a51da2..4b7982cb6 100644
--- a/tests/filter/custom_helpers.h
+++ b/tests/filter/custom_helpers.h
@@ -8,12 +8,14 @@ extern int bitflip_filter_apply(
git_filter *self,
void **payload,
git_buf *to,
- const git_buf *from,
+ const char *from,
+ size_t from_len,
const git_filter_source *source);
extern int reverse_filter_apply(
git_filter *self,
void **payload,
git_buf *to,
- const git_buf *from,
+ const char *from,
+ size_t from_len,
const git_filter_source *source);
diff --git a/tests/filter/wildcard.c b/tests/filter/wildcard.c
index ca1ba1a28..237754021 100644
--- a/tests/filter/wildcard.c
+++ b/tests/filter/wildcard.c
@@ -79,15 +79,16 @@ static int wildcard_filter_apply(
git_filter *self,
void **payload,
git_buf *to,
- const git_buf *from,
+ const char *from_cstr,
+ size_t from_len,
const git_filter_source *source)
{
const char *filtername = *payload;
if (filtername && strcmp(filtername, "wcflip") == 0)
- return bitflip_filter_apply(self, payload, to, from, source);
+ return bitflip_filter_apply(self, payload, to, from_cstr, from_len, source);
else if (filtername && strcmp(filtername, "wcreverse") == 0)
- return reverse_filter_apply(self, payload, to, from, source);
+ return reverse_filter_apply(self, payload, to, from_cstr, from_len, source);
cl_fail("Unexpected attribute");
return GIT_PASSTHROUGH;