mirror of
https://git.proxmox.com/git/libgit2
synced 2025-05-05 17:12:51 +00:00
filebuf: update git_filebuf.write signature to take non-const buffer
z_stream.next_in is non-const. Although currently Zlib doesn't modify buffer content on deflate(), it might be change in the future. gzwrite() already modify it. To avoid this let's change signature of git_filebuf.write and rework git_filebuf_write() accordingly. Signed-off-by: Kirill A. Shutemov <kirill@shutemov.name>
This commit is contained in:
parent
76159921f4
commit
05a62d1a82
@ -97,7 +97,7 @@ GIT_INLINE(int) flush_buffer(git_filebuf *file)
|
||||
return result;
|
||||
}
|
||||
|
||||
static int write_normal(git_filebuf *file, const void *source, size_t len)
|
||||
static int write_normal(git_filebuf *file, void *source, size_t len)
|
||||
{
|
||||
int result = 0;
|
||||
|
||||
@ -110,7 +110,7 @@ static int write_normal(git_filebuf *file, const void *source, size_t len)
|
||||
return result;
|
||||
}
|
||||
|
||||
static int write_deflate(git_filebuf *file, const void *source, size_t len)
|
||||
static int write_deflate(git_filebuf *file, void *source, size_t len)
|
||||
{
|
||||
int result = Z_OK;
|
||||
z_stream *zs = &file->zs;
|
||||
@ -315,8 +315,6 @@ int git_filebuf_write(git_filebuf *file, const void *buff, size_t len)
|
||||
return GIT_SUCCESS;
|
||||
}
|
||||
|
||||
/* flush the cache if it doesn't fit */
|
||||
if (file->buf_pos > 0) {
|
||||
add_to_cache(file, buf, space_left);
|
||||
|
||||
if ((error = flush_buffer(file)) < GIT_SUCCESS)
|
||||
@ -325,15 +323,6 @@ int git_filebuf_write(git_filebuf *file, const void *buff, size_t len)
|
||||
len -= space_left;
|
||||
buf += space_left;
|
||||
}
|
||||
|
||||
/* write too-large chunks immediately */
|
||||
if (len > file->buf_size) {
|
||||
error = file->write(file, buf, len);
|
||||
if (error < GIT_SUCCESS)
|
||||
return git__rethrow(error, "Failed to write to buffer");
|
||||
return GIT_SUCCESS;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int git_filebuf_reserve(git_filebuf *file, void **buffer, size_t len)
|
||||
|
@ -22,8 +22,7 @@ struct git_filebuf {
|
||||
char *path_original;
|
||||
char *path_lock;
|
||||
|
||||
int (*write)(struct git_filebuf *file,
|
||||
const void *source, size_t len);
|
||||
int (*write)(struct git_filebuf *file, void *source, size_t len);
|
||||
|
||||
git_hash_ctx *digest;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user