diff options
author | Vicent Martà <vicent@github.com> | 2012-11-02 10:00:28 -0700 |
---|---|---|
committer | Vicent Martà <vicent@github.com> | 2012-11-02 10:00:28 -0700 |
commit | 1362a983165abb5e85e66c2b0474157ba697966a (patch) | |
tree | 2dcd99e991224a26eb860d36151405219ff202bd /src/vector.c | |
parent | 473a7a1e70d05ec125309304d56f060c3e3ad40e (diff) | |
parent | db106d01f093b3e61170e3738d6651a2866cb76e (diff) | |
download | libgit2-1362a983165abb5e85e66c2b0474157ba697966a.tar.gz |
Merge pull request #1014 from arrbee/diff-rename-detection
Initial implementation of diff rename detection
Diffstat (limited to 'src/vector.c')
-rw-r--r-- | src/vector.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/vector.c b/src/vector.c index d9c4c9900..4763792f5 100644 --- a/src/vector.c +++ b/src/vector.c @@ -255,3 +255,33 @@ void git_vector_swap(git_vector *a, git_vector *b) memcpy(a, b, sizeof(t)); memcpy(b, &t, sizeof(t)); } + +int git_vector_resize_to(git_vector *v, size_t new_length) +{ + if (new_length <= v->length) + return 0; + + while (new_length >= v->_alloc_size) + if (resize_vector(v) < 0) + return -1; + + memset(&v->contents[v->length], 0, + sizeof(void *) * (new_length - v->length)); + + v->length = new_length; + + return 0; +} + +int git_vector_set(void **old, git_vector *v, size_t position, void *value) +{ + if (git_vector_resize_to(v, position + 1) < 0) + return -1; + + if (old != NULL) + *old = v->contents[position]; + + v->contents[position] = value; + + return 0; +} |