Skip to content

Commit 9869f1e

Browse files
committed
filter: deprecate git_filter_list_stream_data
`git_filter_list_stream_data` takes user input in a `git_buf`. `git_buf` should only be used when libgit2 itself needs to allocate data and returned to a user that they can free when they wish. Replace it with `git_filter_list_stream_buffer` that takes a data buffer and length.
1 parent 4bd1720 commit 9869f1e

File tree

3 files changed

+53
-13
lines changed

3 files changed

+53
-13
lines changed

include/git2/deprecated.h

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
#include "describe.h"
1919
#include "diff.h"
2020
#include "errors.h"
21+
#include "filter.h"
2122
#include "index.h"
2223
#include "indexer.h"
2324
#include "merge.h"
@@ -119,6 +120,29 @@ GIT_EXTERN(int) git_blob_filtered_content(
119120

120121
/**@}*/
121122

123+
/** @name Deprecated Filter Functions
124+
*
125+
* These functions are retained for backward compatibility. The
126+
* newer versions of these functions should be preferred in all
127+
* new code.
128+
*
129+
* There is no plan to remove these backward compatibility values at
130+
* this time.
131+
*/
132+
/**@{*/
133+
134+
/** Deprecated in favor of `git_filter_list_stream_buffer`.
135+
*
136+
* @deprecated Use git_filter_list_stream_buffer
137+
* @see Use git_filter_list_stream_buffer
138+
*/
139+
GIT_EXTERN(int) git_filter_list_stream_data(
140+
git_filter_list *filters,
141+
git_buf *data,
142+
git_writestream *target);
143+
144+
/**@}*/
145+
122146
/** @name Deprecated Tree Functions
123147
*
124148
* These functions are retained for backward compatibility. The

include/git2/filter.h

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -175,12 +175,14 @@ GIT_EXTERN(int) git_filter_list_apply_to_blob(
175175
* Apply a filter list to an arbitrary buffer as a stream
176176
*
177177
* @param filters the list of filters to apply
178-
* @param data the buffer to filter
178+
* @param buffer the buffer to filter
179+
* @param len the size of the buffer
179180
* @param target the stream into which the data will be written
180181
*/
181-
GIT_EXTERN(int) git_filter_list_stream_data(
182+
GIT_EXTERN(int) git_filter_list_stream_buffer(
182183
git_filter_list *filters,
183-
git_buf *data,
184+
const char *buffer,
185+
size_t len,
184186
git_writestream *target);
185187

186188
/**

src/filter.c

Lines changed: 24 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -737,8 +737,8 @@ int git_filter_list_apply_to_data(
737737

738738
buf_stream_init(&writer, tgt);
739739

740-
if ((error = git_filter_list_stream_data(filters, src,
741-
&writer.parent)) < 0)
740+
if ((error = git_filter_list_stream_buffer(filters,
741+
src->ptr, src->size, &writer.parent)) < 0)
742742
return error;
743743

744744
GIT_ASSERT(writer.complete);
@@ -1002,24 +1002,21 @@ int git_filter_list_stream_file(
10021002
return error;
10031003
}
10041004

1005-
int git_filter_list_stream_data(
1005+
int git_filter_list_stream_buffer(
10061006
git_filter_list *filters,
1007-
git_buf *data,
1007+
const char *buffer,
1008+
size_t len,
10081009
git_writestream *target)
10091010
{
10101011
git_vector filter_streams = GIT_VECTOR_INIT;
10111012
git_writestream *stream_start;
10121013
int error, initialized = 0;
10131014

1014-
if ((error = git_buf_sanitize(data)) < 0)
1015-
return error;
1016-
10171015
if ((error = stream_list_init(&stream_start, &filter_streams, filters, target)) < 0)
10181016
goto out;
10191017
initialized = 1;
10201018

1021-
if ((error = stream_start->write(
1022-
stream_start, data->ptr, data->size)) < 0)
1019+
if ((error = stream_start->write(stream_start, buffer, len)) < 0)
10231020
goto out;
10241021

10251022
out:
@@ -1043,11 +1040,28 @@ int git_filter_list_stream_blob(
10431040
if (filters)
10441041
git_oid_cpy(&filters->source.oid, git_blob_id(blob));
10451042

1046-
return git_filter_list_stream_data(filters, &in, target);
1043+
return git_filter_list_stream_buffer(filters, in.ptr, in.size, target);
10471044
}
10481045

10491046
int git_filter_init(git_filter *filter, unsigned int version)
10501047
{
10511048
GIT_INIT_STRUCTURE_FROM_TEMPLATE(filter, version, git_filter, GIT_FILTER_INIT);
10521049
return 0;
10531050
}
1051+
1052+
#ifndef GIT_DEPRECATE_HARD
1053+
1054+
int git_filter_list_stream_data(
1055+
git_filter_list *filters,
1056+
git_buf *data,
1057+
git_writestream *target)
1058+
{
1059+
int error;
1060+
1061+
if ((error = git_buf_sanitize(data)) < 0)
1062+
return error;
1063+
1064+
return git_filter_list_stream_buffer(filters, data->ptr, data->size, target);
1065+
}
1066+
1067+
#endif

0 commit comments

Comments
 (0)