summaryrefslogtreecommitdiff
path: root/src/diff_file.c
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-08-28 16:44:04 -0700
committerRussell Belfer <rb@github.com>2013-09-17 09:30:06 -0700
commit85d5481206a932d747b2d5587b6d4c7f69993ba6 (patch)
treea66d55c92d70668509efce5b231517467a3f8b7e /src/diff_file.c
parent0cf77103b218ad3622aff34f3296db1bdd5f0df9 (diff)
downloadlibgit2-85d5481206a932d747b2d5587b6d4c7f69993ba6.tar.gz
Create public filter object and use it
This creates include/sys/filter.h with a basic definition of a git_filter and then converts the internal code to use it. There are related internal objects (git_filter_list) that we will want to publish at some point, but this is a first step.
Diffstat (limited to 'src/diff_file.c')
-rw-r--r--src/diff_file.c46
1 files changed, 20 insertions, 26 deletions
diff --git a/src/diff_file.c b/src/diff_file.c
index bcfef13cd..7602591cf 100644
--- a/src/diff_file.c
+++ b/src/diff_file.c
@@ -296,7 +296,7 @@ static int diff_file_content_load_workdir_file(
git_diff_file_content *fc, git_buf *path)
{
int error = 0;
- git_vector filters = GIT_VECTOR_INIT;
+ 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));
@@ -310,41 +310,35 @@ static int diff_file_content_load_workdir_file(
if (diff_file_content_binary_by_size(fc))
goto cleanup;
- if ((error = git_filters_load(
- &filters, fc->repo, fc->file->path, GIT_FILTER_TO_ODB)) < 0)
+ if ((error = git_filter_list_load(
+ &fl, fc->repo, fc->file->path, GIT_FILTER_TO_ODB)) < 0)
goto cleanup;
- /* error >= is a filter count */
- if (error == 0) {
+ /* if there are no filters, try to mmap the file */
+ if (fl == NULL) {
if (!(error = git_futils_mmap_ro(
- &fc->map, fd, 0, (size_t)fc->file->size)))
+ &fc->map, fd, 0, (size_t)fc->file->size))) {
fc->flags |= GIT_DIFF_FLAG__UNMAP_DATA;
- else /* fall through to try readbuffer below */
- giterr_clear();
- }
-
- if (error != 0) {
- error = git_futils_readbuffer_fd(&raw, fd, (size_t)fc->file->size);
- if (error < 0)
goto cleanup;
-
- if (!filters.length)
- git_buf_swap(&filtered, &raw);
- else
- error = git_filters_apply(&filtered, &raw, &filters);
-
- if (!error) {
- fc->map.len = git_buf_len(&filtered);
- fc->map.data = git_buf_detach(&filtered);
- fc->flags |= GIT_DIFF_FLAG__FREE_DATA;
}
- git_buf_free(&raw);
- git_buf_free(&filtered);
+ /* if mmap failed, fall through to try readbuffer below */
+ 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;
+ }
+
+ git_buf_free(&raw);
+ git_buf_free(&filtered);
+
cleanup:
- git_filters_free(&filters);
+ git_filter_list_free(fl);
p_close(fd);
return error;