summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCarlos Martín Nieto <carlos@cmartin.tk>2012-04-05 23:37:38 +0200
committerCarlos Martín Nieto <carlos@cmartin.tk>2012-04-13 09:50:41 +0200
commit4d53f3e214aee0a2c7370ba099bbb5af70d89f35 (patch)
tree4d2d430124e354196c537d8dc762383eecbe7728
parent6a62543597e401adc85bad12a3153995705200f3 (diff)
downloadlibgit2-4d53f3e214aee0a2c7370ba099bbb5af70d89f35.tar.gz
filebuf: add option not to buffer the contents at all
The new indexer needs to be able to bypass any kind of buffering, as it's trying to map data that it has just written to disk.
-rw-r--r--src/filebuf.c12
-rw-r--r--src/filebuf.h4
2 files changed, 13 insertions, 3 deletions
diff --git a/src/filebuf.c b/src/filebuf.c
index a9de165d5..6538aea66 100644
--- a/src/filebuf.c
+++ b/src/filebuf.c
@@ -194,14 +194,19 @@ int git_filebuf_open(git_filebuf *file, const char *path, int flags)
memset(file, 0x0, sizeof(git_filebuf));
+ if (flags & GIT_FILEBUF_DO_NOT_BUFFER)
+ file->do_not_buffer = true;
+
file->buf_size = WRITE_BUFFER_SIZE;
file->buf_pos = 0;
file->fd = -1;
file->last_error = BUFERR_OK;
/* Allocate the main cache buffer */
- file->buffer = git__malloc(file->buf_size);
- GITERR_CHECK_ALLOC(file->buffer);
+ if (!file->do_not_buffer) {
+ file->buffer = git__malloc(file->buf_size);
+ GITERR_CHECK_ALLOC(file->buffer);
+ }
/* If we are hashing on-write, allocate a new hash context */
if (flags & GIT_FILEBUF_HASH_CONTENTS) {
@@ -345,6 +350,9 @@ int git_filebuf_write(git_filebuf *file, const void *buff, size_t len)
ENSURE_BUF_OK(file);
+ if (file->do_not_buffer)
+ return file->write(file, (void *)buff, len);
+
for (;;) {
size_t space_left = file->buf_size - file->buf_pos;
diff --git a/src/filebuf.h b/src/filebuf.h
index 19e17975b..72563b57a 100644
--- a/src/filebuf.h
+++ b/src/filebuf.h
@@ -19,7 +19,8 @@
#define GIT_FILEBUF_APPEND (1 << 2)
#define GIT_FILEBUF_FORCE (1 << 3)
#define GIT_FILEBUF_TEMPORARY (1 << 4)
-#define GIT_FILEBUF_DEFLATE_SHIFT (5)
+#define GIT_FILEBUF_DO_NOT_BUFFER (1 << 5)
+#define GIT_FILEBUF_DEFLATE_SHIFT (6)
#define GIT_FILELOCK_EXTENSION ".lock\0"
#define GIT_FILELOCK_EXTLENGTH 6
@@ -41,6 +42,7 @@ struct git_filebuf {
size_t buf_size, buf_pos;
git_file fd;
bool fd_is_open;
+ bool do_not_buffer;
int last_error;
};