diff options
| author | Russell Belfer <rb@github.com> | 2012-10-25 10:55:03 -0700 |
|---|---|---|
| committer | Russell Belfer <rb@github.com> | 2012-10-25 10:55:03 -0700 |
| commit | 1b9346897b3be1c8f659e12a6ee84c74858fc32e (patch) | |
| tree | 16b415e58f1343d45111376eae4ecd7ebc77e3d3 /src/buffer.c | |
| parent | 505f37b41a7d80c539a33d28aec947cd87bb1b6c (diff) | |
| parent | fcccf3045f6fbeae5139af7263c2ab986818f154 (diff) | |
| download | libgit2-1b9346897b3be1c8f659e12a6ee84c74858fc32e.tar.gz | |
Merge pull request #925 from nulltoken/topic/moving-branch-updates-config
Updates config upon moving and deletion of branches
Diffstat (limited to 'src/buffer.c')
| -rw-r--r-- | src/buffer.c | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/src/buffer.c b/src/buffer.c index b40b16b66..e55b0a230 100644 --- a/src/buffer.c +++ b/src/buffer.c @@ -549,3 +549,31 @@ void git_buf_unescape(git_buf *buf) { buf->size = git__unescape(buf->ptr); } + +int git_buf_splice( + git_buf *buf, + size_t where, + size_t nb_to_remove, + const char *data, + size_t nb_to_insert) +{ + assert(buf && + where <= git_buf_len(buf) && + where + nb_to_remove <= git_buf_len(buf)); + + /* Ported from git.git + * https://github.com/git/git/blob/16eed7c/strbuf.c#L159-176 + */ + if (git_buf_grow(buf, git_buf_len(buf) + nb_to_insert - nb_to_remove) < 0) + return -1; + + memmove(buf->ptr + where + nb_to_insert, + buf->ptr + where + nb_to_remove, + buf->size - where - nb_to_remove); + + memcpy(buf->ptr + where, data, nb_to_insert); + + buf->size = buf->size + nb_to_insert - nb_to_remove; + buf->ptr[buf->size] = '\0'; + return 0; +} |
