Welcome to mirror list, hosted at ThFree Co, Russian Federation.

github.com/mono/libgit2.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-08-27 10:17:07 +0400
committerRussell Belfer <rb@github.com>2013-09-17 20:30:06 +0400
commit0cf77103b218ad3622aff34f3296db1bdd5f0df9 (patch)
treef60998088c2617f3a289942d7928112f0fe683e9 /src/buffer.c
parent4581f9d8ab72e9b97817e1eaa7154bcec1c7f0b1 (diff)
Start of filter API + git_blob_filtered_content
This begins the process of exposing git_filter objects to the public API. This includes: * new public type and API for `git_buffer` through which an allocated buffer can be passed to the user * new API `git_blob_filtered_content` * make the git_filter type and GIT_FILTER_TO_... constants public
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c54
1 files changed, 54 insertions, 0 deletions
diff --git a/src/buffer.c b/src/buffer.c
index b5b2fd678..a92133674 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -6,6 +6,7 @@
*/
#include "buffer.h"
#include "posix.h"
+#include "git2/buffer.h"
#include <stdarg.h>
#include <ctype.h>
@@ -484,3 +485,56 @@ int git_buf_splice(
buf->ptr[buf->size] = '\0';
return 0;
}
+
+/*
+ * Public buffers API
+ */
+
+void git_buffer_free(git_buffer *buffer)
+{
+ if (!buffer)
+ return;
+
+ if (buffer->ptr != NULL && buffer->available > 0)
+ git__free(buffer->ptr);
+
+ git__memzero(buffer, sizeof(*buffer));
+}
+
+int git_buffer_resize(git_buffer *buffer, size_t want_size)
+{
+ int non_allocated_buffer = 0;
+ char *new_ptr;
+
+ assert(buffer);
+
+ /* check if buffer->ptr points to memory owned elsewhere */
+ non_allocated_buffer = (buffer->ptr != NULL && buffer->available == 0);
+
+ if (non_allocated_buffer && !want_size)
+ want_size = buffer->size;
+
+ if (buffer->available <= want_size)
+ return 0;
+
+ if (non_allocated_buffer) {
+ new_ptr = NULL;
+ if (want_size < buffer->size)
+ want_size = buffer->size;
+ } else {
+ new_ptr = buffer->ptr;
+ }
+
+ want_size = (want_size + 7) & ~7; /* round up to multiple of 8 */
+
+ new_ptr = git__realloc(new_ptr, want_size);
+ GITERR_CHECK_ALLOC(new_ptr);
+
+ if (non_allocated_buffer)
+ memcpy(new_ptr, buffer->ptr, buffer->size);
+
+ buffer->ptr = new_ptr;
+ buffer->available = want_size;
+
+ return 0;
+}