diff options
| author | Edward Thomson <ethomson@edwardthomson.com> | 2019-07-21 10:56:42 +0100 |
|---|---|---|
| committer | Edward Thomson <ethomson@edwardthomson.com> | 2019-08-11 20:47:59 +0100 |
| commit | a32ab076bda0a283806f6690a853729fb43fa3f0 (patch) | |
| tree | 61b56354a3532ffcaacd3b4ef364941dd224e1ba /src/blob.c | |
| parent | c0290e27cc61b8110f1d5565ac4c1eb276217015 (diff) | |
| download | libgit2-a32ab076bda0a283806f6690a853729fb43fa3f0.tar.gz | |
blob: introduce git_blob_filter
Provide a function to filter blobs that allows for more functionality
than the existing `git_blob_filtered_content` function.
Diffstat (limited to 'src/blob.c')
| -rw-r--r-- | src/blob.c | 33 |
1 files changed, 29 insertions, 4 deletions
diff --git a/src/blob.c b/src/blob.c index 31e6ccf86..efc9fc884 100644 --- a/src/blob.c +++ b/src/blob.c @@ -400,25 +400,34 @@ int git_blob_is_binary(const git_blob *blob) return git_buf_text_is_binary(&content); } -int git_blob_filtered_content( +int git_blob_filter( git_buf *out, git_blob *blob, const char *path, - int check_for_binary_data) + git_blob_filter_options *given_opts) { int error = 0; git_filter_list *fl = NULL; + git_blob_filter_options opts = GIT_BLOB_FILTER_OPTIONS_INIT; + git_filter_flag_t flags = GIT_FILTER_DEFAULT; assert(blob && path && out); git_buf_sanitize(out); - if (check_for_binary_data && git_blob_is_binary(blob)) + GIT_ERROR_CHECK_VERSION( + given_opts, GIT_BLOB_FILTER_OPTIONS_VERSION, "git_blob_filter_options"); + + if (given_opts != NULL) + memcpy(&opts, given_opts, sizeof(git_blob_filter_options)); + + if ((opts.flags & GIT_BLOB_FILTER_CHECK_FOR_BINARY) != 0 && + git_blob_is_binary(blob)) return 0; if (!(error = git_filter_list_load( &fl, git_blob_owner(blob), blob, path, - GIT_FILTER_TO_WORKTREE, GIT_FILTER_DEFAULT))) { + GIT_FILTER_TO_WORKTREE, flags))) { error = git_filter_list_apply_to_blob(out, fl, blob); @@ -428,6 +437,22 @@ int git_blob_filtered_content( return error; } +int git_blob_filtered_content( + git_buf *out, + git_blob *blob, + const char *path, + int check_for_binary_data) +{ + git_blob_filter_options opts = GIT_BLOB_FILTER_OPTIONS_INIT; + + if (check_for_binary_data) + opts.flags |= GIT_BLOB_FILTER_CHECK_FOR_BINARY; + else + opts.flags &= ~GIT_BLOB_FILTER_CHECK_FOR_BINARY; + + return git_blob_filter(out, blob, path, &opts); +} + /* Deprecated functions */ int git_blob_create_frombuffer( |
