summaryrefslogtreecommitdiff
path: root/src/diff_file.c
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-09-10 16:33:32 -0700
committerRussell Belfer <rb@github.com>2013-09-17 09:31:44 -0700
commit2a7d224f99a053d93079644947d04e7cc085930f (patch)
tree5a9082e68e98cd85e0bde8d8e399d386158ad390 /src/diff_file.c
parent974774c7b00c08585b05ff87174872be005a1f29 (diff)
downloadlibgit2-2a7d224f99a053d93079644947d04e7cc085930f.tar.gz
Extend public filter api with filter lists
This moves the git_filter_list into the public API so that users can create, apply, and dispose of filter lists. This allows more granular application of filters to user data outside of libgit2 internals. This also converts all the internal usage of filters to the public APIs along with a few small tweaks to make it easier to use the public git_buffer stuff alongside the internal git_buf.
Diffstat (limited to 'src/diff_file.c')
-rw-r--r--src/diff_file.c23
1 files changed, 13 insertions, 10 deletions
diff --git a/src/diff_file.c b/src/diff_file.c
index 7602591cf..e0e244b65 100644
--- a/src/diff_file.c
+++ b/src/diff_file.c
@@ -297,8 +297,8 @@ static int diff_file_content_load_workdir_file(
{
int error = 0;
git_filter_list *fl = NULL;
- git_buf raw = GIT_BUF_INIT, filtered = GIT_BUF_INIT;
git_file fd = git_futils_open_ro(git_buf_cstr(path));
+ git_buf raw = GIT_BUF_INIT;
if (fd < 0)
return fd;
@@ -326,16 +326,19 @@ static int diff_file_content_load_workdir_file(
giterr_clear();
}
- if (!(error = git_futils_readbuffer_fd(&raw, fd, (size_t)fc->file->size)) &&
- !(error = git_filter_list_apply(&filtered, &raw, fl)))
- {
- fc->map.len = git_buf_len(&filtered);
- fc->map.data = git_buf_detach(&filtered);
- fc->flags |= GIT_DIFF_FLAG__FREE_DATA;
- }
+ if (!(error = git_futils_readbuffer_fd(&raw, fd, (size_t)fc->file->size))) {
+ git_buffer in = GIT_BUFFER_FROM_BUF(&raw), out = GIT_BUFFER_INIT;
+
+ error = git_filter_list_apply_to_data(&out, fl, &in);
+
+ git_buffer_free(&in);
- git_buf_free(&raw);
- git_buf_free(&filtered);
+ if (!error) {
+ fc->map.len = out.size;
+ fc->map.data = out.ptr;
+ fc->flags |= GIT_DIFF_FLAG__FREE_DATA;
+ }
+ }
cleanup:
git_filter_list_free(fl);