summaryrefslogtreecommitdiff
path: root/src/vector.c
diff options
context:
space:
mode:
authorEdward Thomson <ethomson@microsoft.com>2014-04-01 23:58:59 -0700
committerEdward Thomson <ethomson@github.com>2016-05-26 11:36:11 -0500
commit7cb904ba4443c22ff5396769b7d07a7f329c0102 (patch)
tree30b2a54983d04ff8b6e55c6c9ff735aad2b9d58b /src/vector.c
parent784bb30300eadfa47c9d5632f9b1a111e36bcbbd (diff)
downloadlibgit2-7cb904ba4443c22ff5396769b7d07a7f329c0102.tar.gz
Introduce git_apply_patch
The beginnings of patch application from an existing (diff-created) git_patch object: applies the hunks of a git_patch to a buffer.
Diffstat (limited to 'src/vector.c')
-rw-r--r--src/vector.c41
1 files changed, 41 insertions, 0 deletions
diff --git a/src/vector.c b/src/vector.c
index a81d463ef..368467692 100644
--- a/src/vector.c
+++ b/src/vector.c
@@ -330,6 +330,47 @@ int git_vector_resize_to(git_vector *v, size_t new_length)
return 0;
}
+int git_vector_grow_at(git_vector *v, size_t idx, size_t grow_len)
+{
+ size_t new_length = v->length + grow_len;
+ size_t new_idx = idx + grow_len;
+
+ assert(grow_len > 0);
+ assert (idx <= v->length);
+
+ if (new_length < v->length ||
+ (new_length > v->_alloc_size && resize_vector(v, new_length) < 0))
+ return -1;
+
+ memmove(&v->contents[new_idx], &v->contents[idx],
+ sizeof(void *) * (v->length - idx));
+ memset(&v->contents[idx], 0, sizeof(void *) * grow_len);
+
+ v->length = new_length;
+ return 0;
+}
+
+int git_vector_shrink_at(git_vector *v, size_t idx, size_t shrink_len)
+{
+ size_t new_length = v->length - shrink_len;
+ size_t end_idx = idx + shrink_len;
+
+ assert(shrink_len > 0 && shrink_len <= v->length);
+ assert(idx <= v->length);
+
+ if (new_length > v->length)
+ return -1;
+
+ if (idx > v->length)
+ memmove(&v->contents[idx], &v->contents[end_idx],
+ sizeof(void *) * (v->length - idx));
+
+ memset(&v->contents[new_length], 0, sizeof(void *) * shrink_len);
+
+ v->length = new_length;
+ return 0;
+}
+
int git_vector_set(void **old, git_vector *v, size_t position, void *value)
{
if (position + 1 > v->length) {