Commit 646364e7 by Edward Thomson Committed by Edward Thomson

checkout: maintain temporary buffer for filters

Let the filters use the checkout data's temporary buffer, instead
of having to allocate new buffers each time.
parent e78f5c9f
...@@ -1444,6 +1444,9 @@ static int blob_content_to_file( ...@@ -1444,6 +1444,9 @@ static int blob_content_to_file(
GIT_FILTER_TO_WORKTREE, GIT_FILTER_OPT_DEFAULT))) GIT_FILTER_TO_WORKTREE, GIT_FILTER_OPT_DEFAULT)))
return error; return error;
if (fl)
git_filter_list__set_temp_buf(fl, &data->tmp);
/* setup the writer */ /* setup the writer */
memset(&writer, 0, sizeof(struct checkout_stream)); memset(&writer, 0, sizeof(struct checkout_stream));
writer.base.write = checkout_stream_write; writer.base.write = checkout_stream_write;
......
...@@ -34,6 +34,7 @@ typedef struct { ...@@ -34,6 +34,7 @@ typedef struct {
struct git_filter_list { struct git_filter_list {
git_array_t(git_filter_entry) filters; git_array_t(git_filter_entry) filters;
git_filter_source source; git_filter_source source;
git_buf *temp_buf;
char path[GIT_FLEX_ARRAY]; char path[GIT_FLEX_ARRAY];
}; };
...@@ -522,7 +523,6 @@ int git_filter_list__load_with_attr_session( ...@@ -522,7 +523,6 @@ int git_filter_list__load_with_attr_session(
fe = git_array_alloc(fl->filters); fe = git_array_alloc(fl->filters);
GITERR_CHECK_ALLOC(fe); GITERR_CHECK_ALLOC(fe);
fe->filter = fdef->filter; fe->filter = fdef->filter;
fe->stream = NULL;
fe->payload = payload; fe->payload = payload;
} }
} }
...@@ -549,6 +549,11 @@ int git_filter_list_load( ...@@ -549,6 +549,11 @@ int git_filter_list_load(
filters, repo, NULL, blob, path, mode, options); filters, repo, NULL, blob, path, mode, options);
} }
void git_filter_list__set_temp_buf(git_filter_list *fl, git_buf *temp_buf)
{
fl->temp_buf = temp_buf;
}
void git_filter_list_free(git_filter_list *fl) void git_filter_list_free(git_filter_list *fl)
{ {
uint32_t i; uint32_t i;
...@@ -591,7 +596,6 @@ int git_filter_list_push( ...@@ -591,7 +596,6 @@ int git_filter_list_push(
fe = git_array_alloc(fl->filters); fe = git_array_alloc(fl->filters);
GITERR_CHECK_ALLOC(fe); GITERR_CHECK_ALLOC(fe);
fe->filter = filter; fe->filter = filter;
fe->stream = NULL;
fe->payload = payload; fe->payload = payload;
return 0; return 0;
...@@ -745,7 +749,8 @@ struct proxy_stream { ...@@ -745,7 +749,8 @@ struct proxy_stream {
const git_filter_source *source; const git_filter_source *source;
void **payload; void **payload;
git_buf input; git_buf input;
git_buf output; git_buf temp_buf;
git_buf *output;
git_filter_stream *target; git_filter_stream *target;
}; };
...@@ -769,15 +774,15 @@ static int proxy_stream_close(git_filter_stream *s) ...@@ -769,15 +774,15 @@ static int proxy_stream_close(git_filter_stream *s)
error = proxy_stream->filter->apply( error = proxy_stream->filter->apply(
proxy_stream->filter, proxy_stream->filter,
proxy_stream->payload, proxy_stream->payload,
&proxy_stream->output, proxy_stream->output,
&proxy_stream->input, &proxy_stream->input,
proxy_stream->source); proxy_stream->source);
if (error == GIT_PASSTHROUGH) { if (error == GIT_PASSTHROUGH) {
writebuf = &proxy_stream->input; writebuf = &proxy_stream->input;
} else if (error == 0) { } else if (error == 0) {
git_buf_sanitize(&proxy_stream->output); git_buf_sanitize(proxy_stream->output);
writebuf = &proxy_stream->output; writebuf = proxy_stream->output;
} else { } else {
return error; return error;
} }
...@@ -795,13 +800,14 @@ static void proxy_stream_free(git_filter_stream *s) ...@@ -795,13 +800,14 @@ static void proxy_stream_free(git_filter_stream *s)
assert(proxy_stream); assert(proxy_stream);
git_buf_free(&proxy_stream->input); git_buf_free(&proxy_stream->input);
git_buf_free(&proxy_stream->output); git_buf_free(&proxy_stream->temp_buf);
git__free(proxy_stream); git__free(proxy_stream);
} }
static int proxy_stream_init( static int proxy_stream_init(
git_filter_stream **out, git_filter_stream **out,
git_filter *filter, git_filter *filter,
git_buf *temp_buf,
void **payload, void **payload,
const git_filter_source *source, const git_filter_source *source,
git_filter_stream *target) git_filter_stream *target)
...@@ -816,6 +822,7 @@ static int proxy_stream_init( ...@@ -816,6 +822,7 @@ static int proxy_stream_init(
proxy_stream->payload = payload; proxy_stream->payload = payload;
proxy_stream->source = source; proxy_stream->source = source;
proxy_stream->target = target; proxy_stream->target = target;
proxy_stream->output = temp_buf ? temp_buf : &proxy_stream->temp_buf;
*out = (git_filter_stream *)proxy_stream; *out = (git_filter_stream *)proxy_stream;
return 0; return 0;
...@@ -844,18 +851,20 @@ static int stream_list_init( ...@@ -844,18 +851,20 @@ static int stream_list_init(
git_array_size(filters->filters) - 1 - i : i; git_array_size(filters->filters) - 1 - i : i;
git_filter_entry *fe = git_array_get(filters->filters, filter_idx); git_filter_entry *fe = git_array_get(filters->filters, filter_idx);
git_filter_stream *filter_stream; git_filter_stream *filter_stream;
git_filter_stream_fn stream_init;
assert(fe->filter->stream || fe->filter->apply); assert(fe->filter->stream || fe->filter->apply);
/* If necessary, create a stream that proxies the traditional /* If necessary, create a stream that proxies the traditional
* application. * application.
*/ */
stream_init = fe->filter->stream ? if (fe->filter->stream)
fe->filter->stream : proxy_stream_init; error = fe->filter->stream(&filter_stream, fe->filter,
error = stream_init(&filter_stream, fe->filter,
&fe->payload, &filters->source, last_stream); &fe->payload, &filters->source, last_stream);
else
/* Create a stream that proxies the one-shot apply */
error = proxy_stream_init(&filter_stream, fe->filter,
filters->temp_buf, &fe->payload, &filters->source,
last_stream);
if (error < 0) if (error < 0)
return error; return error;
......
...@@ -24,6 +24,9 @@ typedef enum { ...@@ -24,6 +24,9 @@ typedef enum {
GIT_CRLF_AUTO, GIT_CRLF_AUTO,
} git_crlf_t; } git_crlf_t;
extern void git_filter_list__set_temp_buf(
git_filter_list *fl, git_buf *temp_buf);
extern void git_filter_free(git_filter *filter); extern void git_filter_free(git_filter *filter);
extern int git_filter_list__load_with_attr_session( extern int git_filter_list__load_with_attr_session(
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment