Add support for creating signed commits and signing commits during a rebase #626

Merged
mbfr merged 25 commits from master into master 2020-08-18 11:25:31 -05:00
2 changed files with 3 additions and 13 deletions
Showing only changes of commit 0fc857204a - Show all commits

View File

@ -3,7 +3,6 @@ package git
/* /*
#include <git2.h> #include <git2.h>
extern void _go_git_buf_fill_null(git_buf *buf);
extern void _go_git_populate_commit_sign_cb(git_rebase_options *opts); extern void _go_git_populate_commit_sign_cb(git_rebase_options *opts);
*/ */
import "C" import "C"
@ -98,13 +97,9 @@ func commitSignCallback(_signature *C.git_buf, _signature_field *C.git_buf, _com
cstr := unsafe.Pointer(C.CString(bufData)) cstr := unsafe.Pointer(C.CString(bufData))
defer C.free(cstr) defer C.free(cstr)
// over-assign by a byte (see below) // libgit2 requires the contents of the buffer to be NULL-terminated.
if int(C.git_buf_grow(buf, clen+1)) != 0 { // C.CString() guarantees that the returned buffer will be
lhchavez commented 2020-08-14 08:58:38 -05:00 (Migrated from github.com)
Review

in order to support callback authors being able to set a specific libgit2 error, we could do something like:

if gitError, ok := err.(*GitError); ok {
    return C.int(gitError.Code)
}
return C.int(-1)
in order to support callback authors being able to set a specific libgit2 error, we could do something like: ```go if gitError, ok := err.(*GitError); ok { return C.int(gitError.Code) } return C.int(-1) ```
mbfr commented 2020-08-14 09:53:17 -05:00 (Migrated from github.com)
Review

Good idea, added

Good idea, added
return errors.New("could not grow buffer") // NULL-terminated, so we can safely copy the terminator.
}
C._go_git_buf_fill_null(buf)
if int(C.git_buf_set(buf, cstr, clen+1)) != 0 { if int(C.git_buf_set(buf, cstr, clen+1)) != 0 {
return errors.New("could not set buffer") return errors.New("could not set buffer")
} }

View File

@ -12,11 +12,6 @@ void _go_git_populate_apply_cb(git_apply_options *options)
options->hunk_cb = (git_apply_hunk_cb)hunkApplyCallback; options->hunk_cb = (git_apply_hunk_cb)hunkApplyCallback;
} }
void _go_git_buf_fill_null(git_buf *buf)
{
memset(buf->ptr, '\0', buf->asize*sizeof(char));
}
void _go_git_populate_commit_sign_cb(git_rebase_options *opts) void _go_git_populate_commit_sign_cb(git_rebase_options *opts)
{ {
opts->signing_cb = (git_commit_signing_cb)commitSignCallback; opts->signing_cb = (git_commit_signing_cb)commitSignCallback;