Add CreateCommitWithSignature
(#782) #792
37
commit.go
37
commit.go
|
@ -75,40 +75,11 @@ func (c *Commit) WithSignatureUsing(f CommitSigningCallback) (*Oid, error) {
|
|||
|
||||
// WithSignature creates a new signed commit from the given signature and signature field
|
||||
func (c *Commit) WithSignature(signature string, signatureField string) (*Oid, error) {
|
||||
totalCommit := c.ContentToSign()
|
||||
|
||||
oid := new(Oid)
|
||||
|
||||
var csf *C.char = nil
|
||||
if signatureField != "" {
|
||||
csf = C.CString(signatureField)
|
||||
defer C.free(unsafe.Pointer(csf))
|
||||
}
|
||||
|
||||
runtime.LockOSThread()
|
||||
defer runtime.UnlockOSThread()
|
||||
|
||||
cTotalCommit := C.CString(totalCommit)
|
||||
cSignature := C.CString(signature)
|
||||
defer C.free(unsafe.Pointer(cTotalCommit))
|
||||
defer C.free(unsafe.Pointer(cSignature))
|
||||
|
||||
ret := C.git_commit_create_with_signature(
|
||||
oid.toC(),
|
||||
c.Owner().ptr,
|
||||
cTotalCommit,
|
||||
cSignature,
|
||||
csf,
|
||||
return c.Owner().CreateCommitWithSignature(
|
||||
c.ContentToSign(),
|
||||
signature,
|
||||
signatureField,
|
||||
)
|
||||
|
||||
runtime.KeepAlive(c)
|
||||
runtime.KeepAlive(oid)
|
||||
|
||||
if ret < 0 {
|
||||
return nil, MakeGitError(ret)
|
||||
}
|
||||
|
||||
return oid, nil
|
||||
}
|
||||
|
||||
func (c *Commit) ExtractSignature() (string, string, error) {
|
||||
|
|
|
@ -485,6 +485,39 @@ func (v *Repository) CreateCommit(
|
|||
return oid, nil
|
||||
}
|
||||
|
||||
// CreateCommitWithSignature creates a commit object from the given contents and
|
||||
// signature.
|
||||
func (v *Repository) CreateCommitWithSignature(
|
||||
commitContent, signature, signatureField string,
|
||||
) (*Oid, error) {
|
||||
cCommitContent := C.CString(commitContent)
|
||||
defer C.free(unsafe.Pointer(cCommitContent))
|
||||
var cSignature *C.char
|
||||
if signature != "" {
|
||||
cSignature = C.CString(string(signature))
|
||||
defer C.free(unsafe.Pointer(cSignature))
|
||||
}
|
||||
var cSignatureField *C.char
|
||||
if signatureField != "" {
|
||||
cSignatureField = C.CString(string(signatureField))
|
||||
defer C.free(unsafe.Pointer(cSignatureField))
|
||||
}
|
||||
|
||||
runtime.LockOSThread()
|
||||
defer runtime.UnlockOSThread()
|
||||
|
||||
oid := new(Oid)
|
||||
ret := C.git_commit_create_with_signature(oid.toC(), v.ptr, cCommitContent, cSignature, cSignatureField)
|
||||
|
||||
runtime.KeepAlive(v)
|
||||
runtime.KeepAlive(oid)
|
||||
if ret < 0 {
|
||||
return nil, MakeGitError(ret)
|
||||
}
|
||||
|
||||
return oid, nil
|
||||
}
|
||||
|
||||
// CreateCommitBuffer creates a commit and write it into a buffer.
|
||||
func (v *Repository) CreateCommitBuffer(
|
||||
author, committer *Signature,
|
||||
|
|
Loading…
Reference in New Issue