diff options
author | Carlos Martín Nieto <cmn@dwim.me> | 2013-08-15 13:48:35 +0200 |
---|---|---|
committer | Carlos Martín Nieto <cmn@dwim.me> | 2013-08-15 14:29:27 +0200 |
commit | 376e6c9f96ffcd572ba974c9cc4d13b4f1e31474 (patch) | |
tree | 8f8cfb27e725e962e3c7cec5e7fa2c4bfa2987bd /src | |
parent | 2af9bcb2dbb47adafa7eecbf41ff113da7fa9d1b (diff) | |
download | libgit2-376e6c9f96ffcd572ba974c9cc4d13b4f1e31474.tar.gz |
odb: wrap the stream reading and writing functions
This is in preparation for moving the hashing to the frontend, which
requires us to handle the incoming data before passing it to the
backend's stream.
Diffstat (limited to 'src')
-rw-r--r-- | src/blob.c | 14 | ||||
-rw-r--r-- | src/odb.c | 26 | ||||
-rw-r--r-- | src/tag.c | 6 | ||||
-rw-r--r-- | src/transports/local.c | 6 |
4 files changed, 36 insertions, 16 deletions
diff --git a/src/blob.c b/src/blob.c index 5bb51f7cf..6a289f43b 100644 --- a/src/blob.c +++ b/src/blob.c @@ -60,10 +60,10 @@ int git_blob_create_frombuffer(git_oid *oid, git_repository *repo, const void *b (error = git_odb_open_wstream(&stream, odb, len, GIT_OBJ_BLOB)) < 0) return error; - if ((error = stream->write(stream, buffer, len)) == 0) - error = stream->finalize_write(oid, stream); + if ((error = git_odb_stream_write(stream, buffer, len)) == 0) + error = git_odb_stream_finalize_write(oid, stream); - stream->free(stream); + git_odb_stream_free(stream); return error; } @@ -80,12 +80,12 @@ static int write_file_stream( return error; if ((fd = git_futils_open_ro(path)) < 0) { - stream->free(stream); + git_odb_stream_free(stream); return -1; } while (!error && (read_len = p_read(fd, buffer, sizeof(buffer))) > 0) { - error = stream->write(stream, buffer, read_len); + error = git_odb_stream_write(stream, buffer, read_len); written += read_len; } @@ -97,9 +97,9 @@ static int write_file_stream( } if (!error) - error = stream->finalize_write(oid, stream); + error = git_odb_stream_finalize_write(oid, stream); - stream->free(stream); + git_odb_stream_free(stream); return error; } @@ -864,9 +864,9 @@ int git_odb_write( if ((error = git_odb_open_wstream(&stream, db, len, type)) != 0) return error; - stream->write(stream, data, len); - error = stream->finalize_write(oid, stream); - stream->free(stream); + git_odb_stream_write(stream, data, len); + error = git_odb_stream_finalize_write(oid, stream); + git_odb_stream_free(stream); return error; } @@ -904,6 +904,26 @@ int git_odb_open_wstream( return error; } +int git_odb_stream_write(git_odb_stream *stream, const char *buffer, size_t len) +{ + return stream->write(stream, buffer, len); +} + +int git_odb_stream_finalize_write(git_oid *out, git_odb_stream *stream) +{ + return stream->finalize_write(out, stream); +} + +int git_odb_stream_read(git_odb_stream *stream, char *buffer, size_t len) +{ + return stream->read(stream, buffer, len); +} + +void git_odb_stream_free(git_odb_stream *stream) +{ + stream->free(stream); +} + int git_odb_open_rstream(git_odb_stream **stream, git_odb *db, const git_oid *oid) { size_t i, reads = 0; @@ -366,10 +366,10 @@ int git_tag_create_frombuffer(git_oid *oid, git_repository *repo, const char *bu if (git_odb_open_wstream(&stream, odb, strlen(buffer), GIT_OBJ_TAG) < 0) return -1; - stream->write(stream, buffer, strlen(buffer)); + git_odb_stream_write(stream, buffer, strlen(buffer)); - error = stream->finalize_write(oid, stream); - stream->free(stream); + error = git_odb_stream_finalize_write(oid, stream); + git_odb_stream_free(stream); if (error < 0) { git_buf_free(&ref_name); diff --git a/src/transports/local.c b/src/transports/local.c index a9da8146c..8a75de727 100644 --- a/src/transports/local.c +++ b/src/transports/local.c @@ -287,9 +287,9 @@ static int local_push_copy_object( odb_obj_size, odb_obj_type)) < 0) goto on_error; - if (odb_stream->write(odb_stream, (char *)git_odb_object_data(odb_obj), + if (git_odb_stream_write(odb_stream, (char *)git_odb_object_data(odb_obj), odb_obj_size) < 0 || - odb_stream->finalize_write(&remote_odb_obj_oid, odb_stream) < 0) { + git_odb_stream_finalize_write(&remote_odb_obj_oid, odb_stream) < 0) { error = -1; } else if (git_oid__cmp(&obj->id, &remote_odb_obj_oid) != 0) { giterr_set(GITERR_ODB, "Error when writing object to remote odb " @@ -298,7 +298,7 @@ static int local_push_copy_object( error = -1; } - odb_stream->free(odb_stream); + git_odb_stream_free(odb_stream); on_error: git_odb_object_free(odb_obj); |