Commit 5bcef522f382042c68d6a7577ec67732687305f2

Edward Thomson 2021-08-27T17:06:50

filter: deprecate apply function

diff --git a/include/git2/sys/filter.h b/include/git2/sys/filter.h
index 098f8f7..b375941 100644
--- a/include/git2/sys/filter.h
+++ b/include/git2/sys/filter.h
@@ -178,6 +178,7 @@ typedef int GIT_CALLBACK(git_filter_check_fn)(
 	const git_filter_source *src,
 	const char             **attr_values);
 
+#ifndef GIT_DEPRECATE_HARD
 /**
  * Callback to actually perform the data filtering
  *
@@ -189,6 +190,8 @@ typedef int GIT_CALLBACK(git_filter_check_fn)(
  *
  * The `payload` value will refer to any payload that was set by the
  * `check` callback.  It may be read from or written to as needed.
+ *
+ * @deprecated use git_filter_stream_fn
  */
 typedef int GIT_CALLBACK(git_filter_apply_fn)(
 	git_filter              *self,
@@ -196,6 +199,7 @@ typedef int GIT_CALLBACK(git_filter_apply_fn)(
 	git_buf                 *to,
 	const git_buf           *from,
 	const git_filter_source *src);
+#endif
 
 /**
  * Callback to perform the data filtering.
@@ -263,12 +267,16 @@ struct git_filter {
 	 */
 	git_filter_check_fn    check;
 
+#ifdef GIT_DEPRECATE_HARD
+	void *reserved;
+#else
 	/**
 	 * Provided for backward compatibility; this will apply the
 	 * filter to the given contents in a `git_buf`.  Callers should
 	 * provide a `stream` function instead.
 	 */
 	git_filter_apply_fn    apply;
+#endif
 
 	/**
 	 * Called to apply the filter, this function will provide a
diff --git a/src/filter.c b/src/filter.c
index 21ae271..f1d9614 100644
--- a/src/filter.c
+++ b/src/filter.c
@@ -939,6 +939,32 @@ int git_filter_buffered_stream_new(
 	return 0;
 }
 
+static int setup_stream(
+	git_writestream **out,
+	git_filter_entry *fe,
+	git_filter_list *filters,
+	git_writestream *last_stream)
+{
+#ifndef GIT_DEPRECATE_HARD
+	GIT_ASSERT(fe->filter->stream || fe->filter->apply);
+
+	/*
+	 * If necessary, create a stream that proxies the traditional
+	 * application.
+	 */
+	if (!fe->filter->stream) {
+		/* Create a stream that proxies the one-shot apply */
+		return git_filter_buffered_stream_new(out,
+			fe->filter, fe->filter->apply, filters->temp_buf,
+			&fe->payload, &filters->source, last_stream);
+	}
+#endif
+
+	GIT_ASSERT(fe->filter->stream);
+	return fe->filter->stream(out, fe->filter,
+		&fe->payload, &filters->source, last_stream);
+}
+
 static int stream_list_init(
 	git_writestream **out,
 	git_vector *streams,
@@ -960,22 +986,11 @@ static int stream_list_init(
 	for (i = 0; i < git_array_size(filters->filters); ++i) {
 		size_t filter_idx = (filters->source.mode == GIT_FILTER_TO_WORKTREE) ?
 			git_array_size(filters->filters) - 1 - i : i;
+
 		git_filter_entry *fe = git_array_get(filters->filters, filter_idx);
 		git_writestream *filter_stream;
 
-		GIT_ASSERT(fe->filter->stream || fe->filter->apply);
-
-		/* If necessary, create a stream that proxies the traditional
-		 * application.
-		 */
-		if (fe->filter->stream)
-			error = fe->filter->stream(&filter_stream, fe->filter,
-				&fe->payload, &filters->source, last_stream);
-		else
-			/* Create a stream that proxies the one-shot apply */
-			error = git_filter_buffered_stream_new(&filter_stream,
-				fe->filter, fe->filter->apply, filters->temp_buf,
-				&fe->payload, &filters->source, last_stream);
+		error = setup_stream(&filter_stream, fe, filters, last_stream);
 
 		if (error < 0)
 			goto out;