diff options
| author | Vicent Marti <tanoku@gmail.com> | 2011-02-21 17:05:16 +0200 |
|---|---|---|
| committer | Vicent Marti <tanoku@gmail.com> | 2011-02-21 18:13:43 +0200 |
| commit | 817c28201e2a9564b38a624be491245aa025c77f (patch) | |
| tree | dfcf8639c04f6e1ddfe3eb6b9980dc0b3d06cd21 /src/filebuf.h | |
| parent | 874c3b6f37e291233be389dbacdb7178af85ad2f (diff) | |
| download | libgit2-817c28201e2a9564b38a624be491245aa025c77f.tar.gz | |
Rewrite all file IO for more performance
The new `git_filebuf` structure provides atomic high-performance writes
to disk by using a write cache, and optionally a double-buffered scheme
through a worker thread (not enabled yet).
Writes can be done 3-layered, like in git.git (user code -> write cache
-> disk), or 2-layered, by writing directly on the cache. This makes
index writing considerably faster.
The `git_filebuf` structure contains all the old functionality of
`git_filelock` for atomic file writes and reads. The `git_filelock`
structure has been removed.
Additionally, the `git_filebuf` API allows to automatically hash (SHA1)
all the data as it is written to disk (hashing is done smartly on big
chunks to improve performance).
Signed-off-by: Vicent Marti <tanoku@gmail.com>
Diffstat (limited to 'src/filebuf.h')
| -rw-r--r-- | src/filebuf.h | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/filebuf.h b/src/filebuf.h new file mode 100644 index 000000000..f2e4dba51 --- /dev/null +++ b/src/filebuf.h @@ -0,0 +1,40 @@ +#ifndef INCLUDE_filebuf_h__ +#define INCLUDE_filebuf_h__ + +#include "fileops.h" +#include "hash.h" + +#ifdef GIT_THREADS +# define GIT_FILEBUF_THREADS +#endif + +#define GIT_FILEBUF_HASH_CONTENTS 0x1 +#define GIT_FILEBUF_APPEND 0x2 +#define GIT_FILEBUF_FORCE 0x4 + +struct git_filebuf { + char *path_original; + char *path_lock; + + git_hash_ctx *digest; + + unsigned char *buffer; +#ifdef GIT_FILEBUF_THREADS + unsigned char *buffer_back; +#endif + + size_t buf_size, buf_pos; + git_file fd; +}; + +typedef struct git_filebuf git_filebuf; + +int git_filebuf_write(git_filebuf *lock, void *buff, size_t len); +int git_filebuf_reserve(git_filebuf *file, void **buff, size_t len); + +int git_filebuf_open(git_filebuf *lock, const char *path, int flags); +int git_filebuf_commit(git_filebuf *lock); +void git_filebuf_cleanup(git_filebuf *lock); +int git_filebuf_hash(git_oid *oid, git_filebuf *file); + +#endif |
