Skip to content

Commit 5bcef52

Browse files
committed
filter: deprecate apply function
1 parent c089d5a commit 5bcef52

File tree

2 files changed

+36
-13
lines changed

2 files changed

+36
-13
lines changed

include/git2/sys/filter.h

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,7 @@ typedef int GIT_CALLBACK(git_filter_check_fn)(
178178
const git_filter_source *src,
179179
const char **attr_values);
180180

181+
#ifndef GIT_DEPRECATE_HARD
181182
/**
182183
* Callback to actually perform the data filtering
183184
*
@@ -189,13 +190,16 @@ typedef int GIT_CALLBACK(git_filter_check_fn)(
189190
*
190191
* The `payload` value will refer to any payload that was set by the
191192
* `check` callback. It may be read from or written to as needed.
193+
*
194+
* @deprecated use git_filter_stream_fn
192195
*/
193196
typedef int GIT_CALLBACK(git_filter_apply_fn)(
194197
git_filter *self,
195198
void **payload, /* may be read and/or set */
196199
git_buf *to,
197200
const git_buf *from,
198201
const git_filter_source *src);
202+
#endif
199203

200204
/**
201205
* Callback to perform the data filtering.
@@ -263,12 +267,16 @@ struct git_filter {
263267
*/
264268
git_filter_check_fn check;
265269

270+
#ifdef GIT_DEPRECATE_HARD
271+
void *reserved;
272+
#else
266273
/**
267274
* Provided for backward compatibility; this will apply the
268275
* filter to the given contents in a `git_buf`. Callers should
269276
* provide a `stream` function instead.
270277
*/
271278
git_filter_apply_fn apply;
279+
#endif
272280

273281
/**
274282
* Called to apply the filter, this function will provide a

src/filter.c

Lines changed: 28 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -939,6 +939,32 @@ int git_filter_buffered_stream_new(
939939
return 0;
940940
}
941941

942+
static int setup_stream(
943+
git_writestream **out,
944+
git_filter_entry *fe,
945+
git_filter_list *filters,
946+
git_writestream *last_stream)
947+
{
948+
#ifndef GIT_DEPRECATE_HARD
949+
GIT_ASSERT(fe->filter->stream || fe->filter->apply);
950+
951+
/*
952+
* If necessary, create a stream that proxies the traditional
953+
* application.
954+
*/
955+
if (!fe->filter->stream) {
956+
/* Create a stream that proxies the one-shot apply */
957+
return git_filter_buffered_stream_new(out,
958+
fe->filter, fe->filter->apply, filters->temp_buf,
959+
&fe->payload, &filters->source, last_stream);
960+
}
961+
#endif
962+
963+
GIT_ASSERT(fe->filter->stream);
964+
return fe->filter->stream(out, fe->filter,
965+
&fe->payload, &filters->source, last_stream);
966+
}
967+
942968
static int stream_list_init(
943969
git_writestream **out,
944970
git_vector *streams,
@@ -960,22 +986,11 @@ static int stream_list_init(
960986
for (i = 0; i < git_array_size(filters->filters); ++i) {
961987
size_t filter_idx = (filters->source.mode == GIT_FILTER_TO_WORKTREE) ?
962988
git_array_size(filters->filters) - 1 - i : i;
989+
963990
git_filter_entry *fe = git_array_get(filters->filters, filter_idx);
964991
git_writestream *filter_stream;
965992

966-
GIT_ASSERT(fe->filter->stream || fe->filter->apply);
967-
968-
/* If necessary, create a stream that proxies the traditional
969-
* application.
970-
*/
971-
if (fe->filter->stream)
972-
error = fe->filter->stream(&filter_stream, fe->filter,
973-
&fe->payload, &filters->source, last_stream);
974-
else
975-
/* Create a stream that proxies the one-shot apply */
976-
error = git_filter_buffered_stream_new(&filter_stream,
977-
fe->filter, fe->filter->apply, filters->temp_buf,
978-
&fe->payload, &filters->source, last_stream);
993+
error = setup_stream(&filter_stream, fe, filters, last_stream);
979994

980995
if (error < 0)
981996
goto out;

0 commit comments

Comments
 (0)