summaryrefslogtreecommitdiff
path: root/src/buffer.c
diff options
context:
space:
mode:
authorRussell Belfer <rb@github.com>2013-09-10 16:33:32 -0700
committerRussell Belfer <rb@github.com>2013-09-17 09:31:44 -0700
commit2a7d224f99a053d93079644947d04e7cc085930f (patch)
tree5a9082e68e98cd85e0bde8d8e399d386158ad390 /src/buffer.c
parent974774c7b00c08585b05ff87174872be005a1f29 (diff)
downloadlibgit2-2a7d224f99a053d93079644947d04e7cc085930f.tar.gz
Extend public filter api with filter lists
This moves the git_filter_list into the public API so that users can create, apply, and dispose of filter lists. This allows more granular application of filters to user data outside of libgit2 internals. This also converts all the internal usage of filters to the public APIs along with a few small tweaks to make it easier to use the public git_buffer stuff alongside the internal git_buf.
Diffstat (limited to 'src/buffer.c')
-rw-r--r--src/buffer.c23
1 files changed, 20 insertions, 3 deletions
diff --git a/src/buffer.c b/src/buffer.c
index a92133674..aaebac776 100644
--- a/src/buffer.c
+++ b/src/buffer.c
@@ -501,7 +501,8 @@ void git_buffer_free(git_buffer *buffer)
git__memzero(buffer, sizeof(*buffer));
}
-int git_buffer_resize(git_buffer *buffer, size_t want_size)
+static int git_buffer__resize(
+ git_buffer *buffer, size_t want_size, int preserve_data)
{
int non_allocated_buffer = 0;
char *new_ptr;
@@ -514,7 +515,7 @@ int git_buffer_resize(git_buffer *buffer, size_t want_size)
if (non_allocated_buffer && !want_size)
want_size = buffer->size;
- if (buffer->available <= want_size)
+ if (buffer->available >= want_size)
return 0;
if (non_allocated_buffer) {
@@ -530,7 +531,7 @@ int git_buffer_resize(git_buffer *buffer, size_t want_size)
new_ptr = git__realloc(new_ptr, want_size);
GITERR_CHECK_ALLOC(new_ptr);
- if (non_allocated_buffer)
+ if (non_allocated_buffer && preserve_data)
memcpy(new_ptr, buffer->ptr, buffer->size);
buffer->ptr = new_ptr;
@@ -538,3 +539,19 @@ int git_buffer_resize(git_buffer *buffer, size_t want_size)
return 0;
}
+
+int git_buffer_resize(git_buffer *buffer, size_t want_size)
+{
+ return git_buffer__resize(buffer, want_size, true);
+}
+
+int git_buffer_copy(
+ git_buffer *buffer, const void *data, size_t datalen)
+{
+ if (git_buffer__resize(buffer, datalen, false) < 0)
+ return -1;
+ memcpy(buffer->ptr, data, datalen);
+ buffer->size = datalen;
+ return 0;
+}
+