diff options
author | Russell Belfer <rb@github.com> | 2013-08-29 03:44:04 +0400 |
---|---|---|
committer | Russell Belfer <rb@github.com> | 2013-09-17 20:30:06 +0400 |
commit | 85d5481206a932d747b2d5587b6d4c7f69993ba6 (patch) | |
tree | a66d55c92d70668509efce5b231517467a3f8b7e /src/blob.c | |
parent | 0cf77103b218ad3622aff34f3296db1bdd5f0df9 (diff) |
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/blob.c')
-rw-r--r-- | src/blob.c | 48 |
1 files changed, 22 insertions, 26 deletions
diff --git a/src/blob.c b/src/blob.c index 6a866538c..3581ee9d1 100644 --- a/src/blob.c +++ b/src/blob.c @@ -108,7 +108,7 @@ static int write_file_filtered( git_off_t *size, git_odb *odb, const char *full_path, - git_vector *filters) + git_filter_list *fl) { int error; git_buf source = GIT_BUF_INIT; @@ -117,7 +117,7 @@ static int write_file_filtered( if ((error = git_futils_readbuffer(&source, full_path)) < 0) return error; - error = git_filters_apply(&dest, &source, filters); + error = git_filter_list_apply(&dest, &source, fl); /* Free the source as soon as possible. This can be big in memory, * and we don't want to ODB write to choke */ @@ -198,29 +198,25 @@ int git_blob__create_from_paths( if (S_ISLNK(mode)) { error = write_symlink(oid, odb, content_path, (size_t)size); } else { - git_vector write_filters = GIT_VECTOR_INIT; - int filter_count = 0; + git_filter_list *fl = NULL; - if (try_load_filters) { + if (try_load_filters) /* Load the filters for writing this file to the ODB */ - filter_count = git_filters_load( - &write_filters, repo, hint_path, GIT_FILTER_TO_ODB); - } + error = git_filter_list_load( + &fl, repo, hint_path, GIT_FILTER_TO_ODB); - if (filter_count < 0) { - /* Negative value means there was a critical error */ - error = filter_count; - } else if (filter_count == 0) { + if (error < 0) + /* well, that didn't work */; + else if (fl == NULL) /* No filters need to be applied to the document: we can stream * directly from disk */ error = write_file_stream(oid, odb, content_path, size); - } else { + else { /* We need to apply one or more filters */ - error = write_file_filtered( - oid, &size, odb, content_path, &write_filters); - } + error = write_file_filtered(oid, &size, odb, content_path, fl); - git_filters_free(&write_filters); + git_filter_list_free(fl); + } /* * TODO: eventually support streaming filtered files, for files @@ -345,9 +341,9 @@ int git_blob_filtered_content( const char *as_path, int check_for_binary_data) { - int error = 0, num_filters = 0; + int error = 0; git_buf filtered = GIT_BUF_INIT, unfiltered = GIT_BUF_INIT; - git_vector filters = GIT_VECTOR_INIT; + git_filter_list *fl = NULL; assert(blob && as_path && out); @@ -359,12 +355,12 @@ int git_blob_filtered_content( if (check_for_binary_data && git_buf_text_is_binary(&filtered)) return 0; - num_filters = git_filters_load( - &filters, git_blob_owner(blob), as_path, GIT_FILTER_TO_WORKTREE); - if (num_filters < 0) - return num_filters; + error = git_filter_list_load( + &fl, git_blob_owner(blob), as_path, GIT_FILTER_TO_WORKTREE); + if (error < 0) + return error; - if (num_filters > 0) { + if (fl != NULL) { if (out->ptr && out->available) { filtered.ptr = out->ptr; filtered.size = out->size; @@ -374,9 +370,9 @@ int git_blob_filtered_content( } if (!(error = git_blob__getbuf(&unfiltered, blob))) - error = git_filters_apply(&filtered, &unfiltered, &filters); + error = git_filter_list_apply(&filtered, &unfiltered, fl); - git_filters_free(&filters); + git_filter_list_free(fl); git_buf_free(&unfiltered); } |