Skip to content

Commit d9c1538

Browse files
committed
blob: add git_blob_filter_options_init
The `git_blob_filter_options_init` function should be included, to allow callers in FFI environments to let us initialize an options structure for them.
1 parent f1151fb commit d9c1538

File tree

3 files changed

+26
-0
lines changed

3 files changed

+26
-0
lines changed

include/git2/blob.h

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,18 @@ typedef struct {
132132
#define GIT_BLOB_FILTER_OPTIONS_VERSION 1
133133
#define GIT_BLOB_FILTER_OPTIONS_INIT {GIT_BLOB_FILTER_OPTIONS_VERSION, GIT_BLOB_FILTER_CHECK_FOR_BINARY}
134134

135+
/**
136+
* Initialize git_blob_filter_options structure
137+
*
138+
* Initializes a `git_blob_filter_options` with default values. Equivalent
139+
* to creating an instance with `GIT_BLOB_FILTER_OPTIONS_INIT`.
140+
*
141+
* @param opts The `git_blob_filter_options` struct to initialize.
142+
* @param version The struct version; pass `GIT_BLOB_FILTER_OPTIONS_VERSION`.
143+
* @return Zero on success; -1 on failure.
144+
*/
145+
GIT_EXTERN(int) git_blob_filter_options_init(git_blob_filter_options *opts, unsigned int version);
146+
135147
/**
136148
* Get a buffer with the filtered content of a blob.
137149
*

src/blob.c

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -408,6 +408,15 @@ int git_blob_is_binary(const git_blob *blob)
408408
return git_buf_text_is_binary(&content);
409409
}
410410

411+
int git_blob_filter_options_init(
412+
git_blob_filter_options *opts,
413+
unsigned int version)
414+
{
415+
GIT_INIT_STRUCTURE_FROM_TEMPLATE(opts, version,
416+
git_blob_filter_options, GIT_BLOB_FILTER_OPTIONS_INIT);
417+
return 0;
418+
}
419+
411420
int git_blob_filter(
412421
git_buf *out,
413422
git_blob *blob,

tests/core/structinit.c

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,6 +82,11 @@ void test_core_structinit__compare(void)
8282
git_blame_options, GIT_BLAME_OPTIONS_VERSION, \
8383
GIT_BLAME_OPTIONS_INIT, git_blame_options_init);
8484

85+
/* blob_filter_options */
86+
CHECK_MACRO_FUNC_INIT_EQUAL( \
87+
git_blob_filter_options, GIT_BLOB_FILTER_OPTIONS_VERSION, \
88+
GIT_BLOB_FILTER_OPTIONS_INIT, git_blob_filter_options_init);
89+
8590
/* checkout */
8691
CHECK_MACRO_FUNC_INIT_EQUAL( \
8792
git_checkout_options, GIT_CHECKOUT_OPTIONS_VERSION, \

0 commit comments

Comments
 (0)