@@ -167,16 +167,16 @@ typedef void GIT_CALLBACK(git_filter_shutdown_fn)(git_filter *self);
167167 *
168168 * The `payload` will be a pointer to a reference payload for the filter.
169169 * This will start as NULL, but `check` can assign to this pointer for
170- * later use by the `apply ` callback. Note that the value should be heap
171- * allocated (not stack), so that it doesn't go away before the `apply `
170+ * later use by the `stream ` callback. Note that the value should be heap
171+ * allocated (not stack), so that it doesn't go away before the `stream `
172172 * callback can use it. If a filter allocates and assigns a value to the
173173 * `payload`, it will need a `cleanup` callback to free the payload.
174174 */
175175typedef int GIT_CALLBACK (git_filter_check_fn )(
176- git_filter * self ,
177- void * * payload , /* points to NULL ptr on entry, may be set */
176+ git_filter * self ,
177+ void * * payload , /* NULL on entry, may be set */
178178 const git_filter_source * src ,
179- const char * * attr_values );
179+ const char * * attr_values );
180180
181181/**
182182 * Callback to actually perform the data filtering
@@ -191,30 +191,40 @@ typedef int GIT_CALLBACK(git_filter_check_fn)(
191191 * `check` callback. It may be read from or written to as needed.
192192 */
193193typedef int GIT_CALLBACK (git_filter_apply_fn )(
194- git_filter * self ,
195- void * * payload , /* may be read and/or set */
196- git_buf * to ,
197- const git_buf * from ,
194+ git_filter * self ,
195+ void * * payload , /* may be read and/or set */
196+ git_buf * to ,
197+ const git_buf * from ,
198198 const git_filter_source * src );
199199
200+ /**
201+ * Callback to perform the data filtering.
202+ *
203+ * Specified as `filter.stream`, this is a callback that filters data
204+ * in a streaming manner. This function will provide a
205+ * `git_writestream` that will the original data will be written to;
206+ * with that data, the `git_writestream` will then perform the filter
207+ * translation and stream the filtered data out to the `next` location.
208+ */
200209typedef int GIT_CALLBACK (git_filter_stream_fn )(
201- git_writestream * * out ,
202- git_filter * self ,
203- void * * payload ,
210+ git_writestream * * out ,
211+ git_filter * self ,
212+ void * * payload ,
204213 const git_filter_source * src ,
205- git_writestream * next );
214+ git_writestream * next );
206215
207216/**
208217 * Callback to clean up after filtering has been applied
209218 *
210219 * Specified as `filter.cleanup`, this is an optional callback invoked
211- * after the filter has been applied. If the `check` or `apply` callbacks
212- * allocated a `payload` to keep per-source filter state, use this
213- * callback to free that payload and release resources as required.
220+ * after the filter has been applied. If the `check`, `apply`, or
221+ * `stream` callbacks allocated a `payload` to keep per-source filter
222+ * state, use this callback to free that payload and release resources
223+ * as required.
214224 */
215225typedef void GIT_CALLBACK (git_filter_cleanup_fn )(
216- git_filter * self ,
217- void * payload );
226+ git_filter * self ,
227+ void * payload );
218228
219229/**
220230 * Filter structure used to register custom filters.
@@ -248,21 +258,24 @@ struct git_filter {
248258 /**
249259 * Called to determine whether the filter should be invoked for a
250260 * given file. If this function returns `GIT_PASSTHROUGH` then the
251- * `apply` function will not be invoked and the contents will be passed
252- * through unmodified.
261+ * `stream` or ` apply` functions will not be invoked and the
262+ * contents will be passed through unmodified.
253263 */
254264 git_filter_check_fn check ;
255265
256266 /**
257- * Called to actually apply the filter to file contents. If this
258- * function returns `GIT_PASSTHROUGH` then the contents will be passed
259- * through unmodified .
267+ * Provided for backward compatibility; this will apply the
268+ * filter to the given contents in a `git_buf`. Callers should
269+ * provide a `stream` function instead .
260270 */
261271 git_filter_apply_fn apply ;
262272
263273 /**
264- * Called to apply the filter in a streaming manner. If this is not
265- * specified then the system will call `apply` with the whole buffer.
274+ * Called to apply the filter, this function will provide a
275+ * `git_writestream` that will the original data will be
276+ * written to; with that data, the `git_writestream` will then
277+ * perform the filter translation and stream the filtered data
278+ * out to the `next` location.
266279 */
267280 git_filter_stream_fn stream ;
268281
@@ -289,9 +302,9 @@ GIT_EXTERN(int) git_filter_init(git_filter *filter, unsigned int version);
289302 * As mentioned elsewhere, the initialize callback will not be invoked
290303 * immediately. It is deferred until the filter is used in some way.
291304 *
292- * A filter's attribute checks and `check` and `apply` callbacks will be
293- * issued in order of `priority` on smudge (to workdir), and in reverse
294- * order of `priority` on clean (to odb).
305+ * A filter's attribute checks and `check` and `stream` (or `apply`)
306+ * callbacks will be issued in order of `priority` on smudge (to
307+ * workdir), and in reverse order of `priority` on clean (to odb).
295308 *
296309 * Two filters are preregistered with libgit2:
297310 * - GIT_FILTER_CRLF with priority 0
0 commit comments