libgit2/libgit2 — pull request #503 by arrbee (2011-11-30 00:49:55+00:00)
Title: Make git_buf functions always maintain a valid cstr

I'm not sure what you'll think of this, but at a tiny cost (1 extra byte per allocation and one NULL-byte assignment), this patch makes all `git_buf` functions maintain the buffer contents in a NULL-terminated state. That guarantees that `git_buf_cstr` will always succeed, which simplifies error checking when trying to convert things to use dynamic allocation.

This patch also adds a new function (`git_buf_copy_cstr`) for copying the cstr data directly into an external buffer.

This doesn't preclude using `git_buf`s for data which is not NULL terminated, of course. It just makes it much easier to work with string data.