From e76c970b57392b68997979de5c7e700115e54272 Mon Sep 17 00:00:00 2001 From: Michael Boulton Date: Tue, 18 Aug 2020 08:55:17 +0100 Subject: [PATCH] Fix godoc and make name of signing callback better --- commit.go | 6 +++--- git_test.go | 6 +++--- rebase.go | 20 ++++++++++---------- rebase_test.go | 8 ++++---- 4 files changed, 20 insertions(+), 20 deletions(-) diff --git a/commit.go b/commit.go index c58d2be..bf12e58 100644 --- a/commit.go +++ b/commit.go @@ -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 diff --git a/git_test.go b/git_test.go index 941d224..91ade73 100644 --- a/git_test.go +++ b/git_test.go @@ -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) diff --git a/rebase.go b/rebase.go index ac0224c..2144329 100644 --- a/rebase.go +++ b/rebase.go @@ -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) @@ -129,13 +129,13 @@ func commitSignCallback(_signature *C.git_buf, _signature_field *C.git_buf, _com // RebaseOptions are used to tell the rebase machinery how to operate type RebaseOptions struct { - Version uint - Quiet int - InMemory int - RewriteNotesRef string - MergeOptions MergeOptions - CheckoutOptions CheckoutOpts - SigningCallback CommitSigningCb + Version uint + Quiet int + InMemory int + RewriteNotesRef string + MergeOptions MergeOptions + CheckoutOptions CheckoutOpts + 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) } diff --git a/rebase_test.go b/rebase_test.go index 0a63a90..a78e6c7 100644 --- a/rebase_test.go +++ b/rebase_test.go @@ -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 }