summaryrefslogtreecommitdiff
path: root/src/blob.c
diff options
context:
space:
mode:
authorVicent Martí <tanoku@gmail.com>2012-03-01 21:19:51 +0100
committerVicent Martí <tanoku@gmail.com>2012-03-01 21:19:51 +0100
commit47a899ffed3c71080e10e73eda092a716f1be168 (patch)
tree181f4f0b52318fbe65fbd9aa3079593533d45715 /src/blob.c
parent788430c8e3fa90dd965b44fb31ba8b2eece2ca37 (diff)
downloadlibgit2-47a899ffed3c71080e10e73eda092a716f1be168.tar.gz
filter: Beautiful refactoring
Comments soothe my soul.
Diffstat (limited to 'src/blob.c')
-rw-r--r--src/blob.c34
1 files changed, 20 insertions, 14 deletions
diff --git a/src/blob.c b/src/blob.c
index 245326157..e1f4a7f6a 100644
--- a/src/blob.c
+++ b/src/blob.c
@@ -115,19 +115,18 @@ static int write_file_filtered(
if (error < GIT_SUCCESS)
return error;
- error = git_filter__apply(&dest, &source, filters);
+ error = git_filters_apply(&dest, &source, filters);
- if (error < GIT_SUCCESS) {
- git_buf_free(&source);
- git_buf_free(&dest);
- return error;
- }
+ /* Free the source as soon as possible. This can be big in memory,
+ * and we don't want to ODB write to choke */
+ git_buf_free(&source);
- error = git_odb_write(oid, odb, dest.ptr, dest.size, GIT_OBJ_BLOB);
+ if (error == GIT_SUCCESS) {
+ /* Write the file to disk if it was properly filtered */
+ error = git_odb_write(oid, odb, dest.ptr, dest.size, GIT_OBJ_BLOB);
+ }
- git_buf_free(&source);
git_buf_free(&dest);
-
return GIT_SUCCESS;
}
@@ -186,18 +185,25 @@ int git_blob_create_fromfile(git_oid *oid, git_repository *repo, const char *pat
error = write_symlink(oid, odb, full_path.ptr, (size_t)size);
} else {
git_vector write_filters = GIT_VECTOR_INIT;
+ int filter_count;
- if ((error = git_filter__load_for_file(
- &write_filters, repo, path, GIT_FILTER_TO_ODB)) < GIT_SUCCESS)
- goto cleanup;
+ /* Load the filters for writing this file to the ODB */
+ filter_count = git_filters_load(&write_filters, repo, path, GIT_FILTER_TO_ODB);
- if (write_filters.length == 0) {
+ if (filter_count < 0) {
+ /* Negative value means there was a critical error */
+ error = filter_count;
+ goto cleanup;
+ } else if (filter_count == 0) {
+ /* No filters need to be applied to the document: we can stream
+ * directly from disk */
error = write_file_stream(oid, odb, full_path.ptr, size);
} else {
+ /* We need to apply one or more filters */
error = write_file_filtered(oid, odb, full_path.ptr, &write_filters);
}
- git_filter__free(&write_filters);
+ git_filters_free(&write_filters);
/*
* TODO: eventually support streaming filtered files, for files which are bigger