diff options
| author | Edward Thomson <ethomson@microsoft.com> | 2014-04-01 23:58:59 -0700 |
|---|---|---|
| committer | Edward Thomson <ethomson@github.com> | 2016-05-26 11:36:11 -0500 |
| commit | 7cb904ba4443c22ff5396769b7d07a7f329c0102 (patch) | |
| tree | 30b2a54983d04ff8b6e55c6c9ff735aad2b9d58b /src/vector.c | |
| parent | 784bb30300eadfa47c9d5632f9b1a111e36bcbbd (diff) | |
| download | libgit2-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.c | 41 |
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) { |
