Fix godoc and make name of signing callback better

This commit is contained in:
Michael Boulton 2020-08-18 08:55:17 +01:00
parent 5d83180aef
commit e76c970b57
No known key found for this signature in database
GPG Key ID: 8A62CA0BE2E0197E
4 changed files with 20 additions and 20 deletions

View File

@ -51,11 +51,11 @@ func (c *Commit) ContentToSign() string {
return c.RawHeader() + "\n" + c.RawMessage()
}
// CommitSigningCb defines a function type that takes some data to sign and returns (signature, signature_field, error)
type CommitSigningCb func(string) (string, string, error)
// CommitSigningCallback defines a function type that takes some data to sign and returns (signature, signature_field, error)
type CommitSigningCallback func(string) (signature, signatureField string, err error)
// WithSignatureUsing creates a new signed commit from this one using the given signing callback
func (c *Commit) WithSignatureUsing(f CommitSigningCb) (*Oid, error) {
func (c *Commit) WithSignatureUsing(f CommitSigningCallback) (*Oid, error) {
signature, signatureField, err := f(c.ContentToSign())
if err != nil {
return nil, err

View File

@ -47,7 +47,7 @@ func createBareTestRepo(t *testing.T) *Repository {
// commitOpts contains any extra options for creating commits in the seed repo
type commitOpts struct {
CommitSigningCb
CommitSigningCallback
}
func seedTestRepo(t *testing.T, repo *Repository) (*Oid, *Oid) {
@ -78,11 +78,11 @@ func seedTestRepoOpt(t *testing.T, repo *Repository, opts commitOpts) (*Oid, *Oi
commitId, err := repo.CreateCommit("HEAD", sig, sig, message, tree)
checkFatal(t, err)
if opts.CommitSigningCb != nil {
if opts.CommitSigningCallback != nil {
commit, err := repo.LookupCommit(commitId)
checkFatal(t, err)
signature, signatureField, err := opts.CommitSigningCb(commit.ContentToSign())
signature, signatureField, err := opts.CommitSigningCallback(commit.ContentToSign())
checkFatal(t, err)
oid, err := commit.WithSignature(signature, signatureField)

View File

@ -79,13 +79,13 @@ func commitSignCallback(_signature *C.git_buf, _signature_field *C.git_buf, _com
panic("invalid sign payload")
}
if opts.SigningCallback == nil {
if opts.CommitSigningCallback == nil {
return C.GIT_PASSTHROUGH
}
commitContent := C.GoString(_commit_content)
signature, signatureField, err := opts.SigningCallback(commitContent)
signature, signatureField, err := opts.CommitSigningCallback(commitContent)
if err != nil {
if gitError, ok := err.(*GitError); ok {
return C.int(gitError.Code)
@ -135,7 +135,7 @@ type RebaseOptions struct {
RewriteNotesRef string
MergeOptions MergeOptions
CheckoutOptions CheckoutOpts
SigningCallback CommitSigningCb
CommitSigningCallback CommitSigningCallback
}
// DefaultRebaseOptions returns a RebaseOptions with default values.
@ -176,7 +176,7 @@ func (ro *RebaseOptions) toC() *C.git_rebase_options {
checkout_options: *ro.CheckoutOptions.toC(),
}
if ro.SigningCallback != nil {
if ro.CommitSigningCallback != nil {
C._go_git_populate_commit_sign_cb(opts)
opts.payload = pointerHandles.Track(ro)
}

View File

@ -155,10 +155,10 @@ func TestRebaseGpgSigned(t *testing.T) {
return cipherText.String(), "", nil
}
opts.SigningCallback = signCommitContent
opts.CommitSigningCallback = signCommitContent
commitOpts := commitOpts{
CommitSigningCb: signCommitContent,
CommitSigningCallback: signCommitContent,
}
// Inputs
@ -441,13 +441,13 @@ func commitSomething(repo *Repository, something, content string, commitOpts com
return nil, err
}
if commitOpts.CommitSigningCb != nil {
if commitOpts.CommitSigningCallback != nil {
commit, err := repo.LookupCommit(commit)
if err != nil {
return nil, err
}
oid, err := commit.WithSignatureUsing(commitOpts.CommitSigningCb)
oid, err := commit.WithSignatureUsing(commitOpts.CommitSigningCallback)
if err != nil {
return nil, err
}