Skip to content

Commit 8296da5

Browse files
authored
Merge pull request libgit2#4267 from mohseenrm/master
adding GIT_FILTER_VERSION to GIT_FILTER_INIT as part of convention
2 parents 4e257da + a78441b commit 8296da5

File tree

3 files changed

+24
-1
lines changed

3 files changed

+24
-1
lines changed

include/git2/sys/filter.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -271,6 +271,17 @@ struct git_filter {
271271
};
272272

273273
#define GIT_FILTER_VERSION 1
274+
#define GIT_FILTER_INIT {GIT_FILTER_VERSION}
275+
276+
/**
277+
* Initializes a `git_filter` with default values. Equivalent to
278+
* creating an instance with GIT_FILTER_INIT.
279+
*
280+
* @param filter the `git_filter` struct to initialize.
281+
* @param version Version the struct; pass `GIT_FILTER_VERSION`
282+
* @return Zero on success; -1 on failure.
283+
*/
284+
GIT_EXTERN(int) git_filter_init(git_filter *filter, unsigned int version);
274285

275286
/**
276287
* Register a filter under a given name with a given priority.

src/filter.c

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,7 @@ static int stream_list_init(
895895
git_array_size(filters->filters) - 1 - i : i;
896896
git_filter_entry *fe = git_array_get(filters->filters, filter_idx);
897897
git_writestream *filter_stream;
898-
898+
899899
assert(fe->filter->stream || fe->filter->apply);
900900

901901
/* If necessary, create a stream that proxies the traditional
@@ -1022,3 +1022,9 @@ int git_filter_list_stream_blob(
10221022

10231023
return git_filter_list_stream_data(filters, &in, target);
10241024
}
1025+
1026+
int git_filter_init(git_filter *filter, unsigned int version)
1027+
{
1028+
GIT_INIT_STRUCTURE_FROM_TEMPLATE(filter, version, git_filter, GIT_FILTER_INIT);
1029+
return 0;
1030+
}

tests/core/structinit.c

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
#include "clar_libgit2.h"
22
#include <git2/sys/config.h>
3+
#include <git2/sys/filter.h>
34
#include <git2/sys/odb_backend.h>
45
#include <git2/sys/refdb_backend.h>
56
#include <git2/sys/transport.h>
@@ -96,6 +97,11 @@ void test_core_structinit__compare(void)
9697
git_diff_find_options, GIT_DIFF_FIND_OPTIONS_VERSION, \
9798
GIT_DIFF_FIND_OPTIONS_INIT, git_diff_find_init_options);
9899

100+
/* filter */
101+
CHECK_MACRO_FUNC_INIT_EQUAL( \
102+
git_filter, GIT_FILTER_VERSION, \
103+
GIT_FILTER_INIT, git_filter_init);
104+
99105
/* merge_file_input */
100106
CHECK_MACRO_FUNC_INIT_EQUAL( \
101107
git_merge_file_input, GIT_MERGE_FILE_INPUT_VERSION, \

0 commit comments

Comments
 (0)