diff options
Diffstat (limited to 'src/blob.c')
-rw-r--r-- | src/blob.c | 46 |
1 files changed, 22 insertions, 24 deletions
diff --git a/src/blob.c b/src/blob.c index 09b5b5d91..6f57d09e4 100644 --- a/src/blob.c +++ b/src/blob.c @@ -12,6 +12,7 @@ #include "git2/repository.h" #include "git2/odb_backend.h" +#include "buf.h" #include "filebuf.h" #include "filter.h" @@ -35,12 +36,12 @@ git_object_size_t git_blob_rawsize(const git_blob *blob) return (git_object_size_t)git_odb_object_size(blob->data.odb); } -int git_blob__getbuf(git_buf *buffer, git_blob *blob) +int git_blob__getbuf(git_str *buffer, git_blob *blob) { git_object_size_t size = git_blob_rawsize(blob); GIT_ERROR_CHECK_BLOBSIZE(size); - return git_buf_set(buffer, git_blob_rawcontent(blob), (size_t)size); + return git_str_set(buffer, git_blob_rawcontent(blob), (size_t)size); } void git_blob__free(void *_blob) @@ -142,9 +143,9 @@ static int write_file_filtered( git_repository* repo) { int error; - git_buf tgt = GIT_BUF_INIT; + git_str tgt = GIT_STR_INIT; - error = git_filter_list_apply_to_file(&tgt, fl, repo, full_path); + error = git_filter_list__apply_to_file(&tgt, fl, repo, full_path); /* Write the file to disk if it was properly filtered */ if (!error) { @@ -153,7 +154,7 @@ static int write_file_filtered( error = git_odb_write(id, odb, tgt.ptr, tgt.size, GIT_OBJECT_BLOB); } - git_buf_dispose(&tgt); + git_str_dispose(&tgt); return error; } @@ -193,7 +194,7 @@ int git_blob__create_from_paths( git_odb *odb = NULL; git_object_size_t size; mode_t mode; - git_buf path = GIT_BUF_INIT; + git_str path = GIT_STR_INIT; GIT_ASSERT_ARG(hint_path || !try_load_filters); @@ -261,7 +262,7 @@ int git_blob__create_from_paths( done: git_odb_free(odb); - git_buf_dispose(&path); + git_str_dispose(&path); return error; } @@ -276,11 +277,11 @@ int git_blob_create_from_disk( git_oid *id, git_repository *repo, const char *path) { int error; - git_buf full_path = GIT_BUF_INIT; + git_str full_path = GIT_STR_INIT; const char *workdir, *hintpath = NULL; if ((error = git_path_prettify(&full_path, path, NULL)) < 0) { - git_buf_dispose(&full_path); + git_str_dispose(&full_path); return error; } @@ -290,9 +291,9 @@ int git_blob_create_from_disk( hintpath = full_path.ptr + strlen(workdir); error = git_blob__create_from_paths( - id, NULL, repo, git_buf_cstr(&full_path), hintpath, 0, !!hintpath); + id, NULL, repo, git_str_cstr(&full_path), hintpath, 0, !!hintpath); - git_buf_dispose(&full_path); + git_str_dispose(&full_path); return error; } @@ -330,7 +331,7 @@ static int blob_writestream_write(git_writestream *_stream, const char *buffer, int git_blob_create_from_stream(git_writestream **out, git_repository *repo, const char *hintpath) { int error; - git_buf path = GIT_BUF_INIT; + git_str path = GIT_STR_INIT; blob_writestream *stream; GIT_ASSERT_ARG(out); @@ -349,11 +350,11 @@ int git_blob_create_from_stream(git_writestream **out, git_repository *repo, con stream->parent.close = blob_writestream_close; stream->parent.free = blob_writestream_free; - if ((error = git_repository_item_path(&path, repo, GIT_REPOSITORY_ITEM_OBJECTS)) < 0 - || (error = git_buf_joinpath(&path, path.ptr, "streamed")) < 0) + if ((error = git_repository__item_path(&path, repo, GIT_REPOSITORY_ITEM_OBJECTS)) < 0 + || (error = git_str_joinpath(&path, path.ptr, "streamed")) < 0) goto cleanup; - if ((error = git_filebuf_open_withsize(&stream->fbuf, git_buf_cstr(&path), GIT_FILEBUF_TEMPORARY, + if ((error = git_filebuf_open_withsize(&stream->fbuf, git_str_cstr(&path), GIT_FILEBUF_TEMPORARY, 0666, 2 * 1024 * 1024)) < 0) goto cleanup; @@ -363,7 +364,7 @@ cleanup: if (error < 0) blob_writestream_free((git_writestream *) stream); - git_buf_dispose(&path); + git_str_dispose(&path); return error; } @@ -391,16 +392,16 @@ cleanup: int git_blob_is_binary(const git_blob *blob) { - git_buf content = GIT_BUF_INIT; + git_str content = GIT_STR_INIT; git_object_size_t size; GIT_ASSERT_ARG(blob); size = git_blob_rawsize(blob); - git_buf_attach_notowned(&content, git_blob_rawcontent(blob), + git_str_attach_notowned(&content, git_blob_rawcontent(blob), (size_t)min(size, GIT_FILTER_BYTES_TO_CHECK_NUL)); - return git_buf_is_binary(&content); + return git_str_is_binary(&content); } int git_blob_filter_options_init( @@ -418,10 +419,10 @@ int git_blob_filter( const char *path, 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_options filter_opts = GIT_FILTER_OPTIONS_INIT; + git_filter_list *fl = NULL; + int error = 0; GIT_ASSERT_ARG(blob); GIT_ASSERT_ARG(path); @@ -430,9 +431,6 @@ int git_blob_filter( GIT_ERROR_CHECK_VERSION( given_opts, GIT_BLOB_FILTER_OPTIONS_VERSION, "git_blob_filter_options"); - if (git_buf_sanitize(out) < 0) - return -1; - if (given_opts != NULL) memcpy(&opts, given_opts, sizeof(git_blob_filter_options)); |