Commit a9a7bfb5 by Edward Thomson

filter: add docs for `git_filter_stream_fn`

parent 45489a11
...@@ -167,14 +167,14 @@ typedef void GIT_CALLBACK(git_filter_shutdown_fn)(git_filter *self); ...@@ -167,14 +167,14 @@ typedef void GIT_CALLBACK(git_filter_shutdown_fn)(git_filter *self);
* *
* The `payload` will be a pointer to a reference payload for the filter. * The `payload` will be a pointer to a reference payload for the filter.
* This will start as NULL, but `check` can assign to this pointer for * This will start as NULL, but `check` can assign to this pointer for
* later use by the `apply` callback. Note that the value should be heap * later use by the `stream` callback. Note that the value should be heap
* allocated (not stack), so that it doesn't go away before the `apply` * allocated (not stack), so that it doesn't go away before the `stream`
* callback can use it. If a filter allocates and assigns a value to the * callback can use it. If a filter allocates and assigns a value to the
* `payload`, it will need a `cleanup` callback to free the payload. * `payload`, it will need a `cleanup` callback to free the payload.
*/ */
typedef int GIT_CALLBACK(git_filter_check_fn)( typedef int GIT_CALLBACK(git_filter_check_fn)(
git_filter *self, git_filter *self,
void **payload, /* points to NULL ptr on entry, may be set */ void **payload, /* NULL on entry, may be set */
const git_filter_source *src, const git_filter_source *src,
const char **attr_values); const char **attr_values);
...@@ -197,6 +197,15 @@ typedef int GIT_CALLBACK(git_filter_apply_fn)( ...@@ -197,6 +197,15 @@ typedef int GIT_CALLBACK(git_filter_apply_fn)(
const git_buf *from, const git_buf *from,
const git_filter_source *src); const git_filter_source *src);
/**
* Callback to perform the data filtering.
*
* Specified as `filter.stream`, this is a callback that filters data
* in a streaming manner. This function will provide a
* `git_writestream` that will the original data will be written to;
* with that data, the `git_writestream` will then perform the filter
* translation and stream the filtered data out to the `next` location.
*/
typedef int GIT_CALLBACK(git_filter_stream_fn)( typedef int GIT_CALLBACK(git_filter_stream_fn)(
git_writestream **out, git_writestream **out,
git_filter *self, git_filter *self,
...@@ -208,9 +217,10 @@ typedef int GIT_CALLBACK(git_filter_stream_fn)( ...@@ -208,9 +217,10 @@ typedef int GIT_CALLBACK(git_filter_stream_fn)(
* Callback to clean up after filtering has been applied * Callback to clean up after filtering has been applied
* *
* Specified as `filter.cleanup`, this is an optional callback invoked * Specified as `filter.cleanup`, this is an optional callback invoked
* after the filter has been applied. If the `check` or `apply` callbacks * after the filter has been applied. If the `check`, `apply`, or
* allocated a `payload` to keep per-source filter state, use this * `stream` callbacks allocated a `payload` to keep per-source filter
* callback to free that payload and release resources as required. * state, use this callback to free that payload and release resources
* as required.
*/ */
typedef void GIT_CALLBACK(git_filter_cleanup_fn)( typedef void GIT_CALLBACK(git_filter_cleanup_fn)(
git_filter *self, git_filter *self,
...@@ -248,21 +258,24 @@ struct git_filter { ...@@ -248,21 +258,24 @@ struct git_filter {
/** /**
* Called to determine whether the filter should be invoked for a * Called to determine whether the filter should be invoked for a
* given file. If this function returns `GIT_PASSTHROUGH` then the * given file. If this function returns `GIT_PASSTHROUGH` then the
* `apply` function will not be invoked and the contents will be passed * `stream` or `apply` functions will not be invoked and the
* through unmodified. * contents will be passed through unmodified.
*/ */
git_filter_check_fn check; git_filter_check_fn check;
/** /**
* Called to actually apply the filter to file contents. If this * Provided for backward compatibility; this will apply the
* function returns `GIT_PASSTHROUGH` then the contents will be passed * filter to the given contents in a `git_buf`. Callers should
* through unmodified. * provide a `stream` function instead.
*/ */
git_filter_apply_fn apply; git_filter_apply_fn apply;
/** /**
* Called to apply the filter in a streaming manner. If this is not * Called to apply the filter, this function will provide a
* specified then the system will call `apply` with the whole buffer. * `git_writestream` that will the original data will be
* written to; with that data, the `git_writestream` will then
* perform the filter translation and stream the filtered data
* out to the `next` location.
*/ */
git_filter_stream_fn stream; git_filter_stream_fn stream;
...@@ -289,9 +302,9 @@ GIT_EXTERN(int) git_filter_init(git_filter *filter, unsigned int version); ...@@ -289,9 +302,9 @@ GIT_EXTERN(int) git_filter_init(git_filter *filter, unsigned int version);
* As mentioned elsewhere, the initialize callback will not be invoked * As mentioned elsewhere, the initialize callback will not be invoked
* immediately. It is deferred until the filter is used in some way. * immediately. It is deferred until the filter is used in some way.
* *
* A filter's attribute checks and `check` and `apply` callbacks will be * A filter's attribute checks and `check` and `stream` (or `apply`)
* issued in order of `priority` on smudge (to workdir), and in reverse * callbacks will be issued in order of `priority` on smudge (to
* order of `priority` on clean (to odb). * workdir), and in reverse order of `priority` on clean (to odb).
* *
* Two filters are preregistered with libgit2: * Two filters are preregistered with libgit2:
* - GIT_FILTER_CRLF with priority 0 * - GIT_FILTER_CRLF with priority 0
......
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