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>
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
diff --git a/src/filebuf.c b/src/filebuf.c
index 1fbbaa3..6d398a7 100644
--- a/src/filebuf.c
+++ b/src/filebuf.c
@@ -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,24 +315,13 @@ 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);
+ add_to_cache(file, buf, space_left);
- if ((error = flush_buffer(file)) < GIT_SUCCESS)
- return git__rethrow(error, "Failed to write to buffer");
-
- len -= space_left;
- buf += space_left;
- }
+ if ((error = flush_buffer(file)) < GIT_SUCCESS)
+ return git__rethrow(error, "Failed to write to buffer");
- /* 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;
- }
+ len -= space_left;
+ buf += space_left;
}
}
diff --git a/src/filebuf.h b/src/filebuf.h
index 1567b11..9154cab 100644
--- a/src/filebuf.h
+++ b/src/filebuf.h
@@ -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;