You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

commit_convert_gogit.go 1.4KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. // Copyright 2015 The Gogs Authors. All rights reserved.
  2. // Copyright 2018 The Gitea Authors. All rights reserved.
  3. // Use of this source code is governed by a MIT-style
  4. // license that can be found in the LICENSE file.
  5. //go:build gogit
  6. // +build gogit
  7. package git
  8. import (
  9. "fmt"
  10. "strings"
  11. "github.com/go-git/go-git/v5/plumbing/object"
  12. )
  13. func convertPGPSignature(c *object.Commit) *CommitGPGSignature {
  14. if c.PGPSignature == "" {
  15. return nil
  16. }
  17. var w strings.Builder
  18. var err error
  19. if _, err = fmt.Fprintf(&w, "tree %s\n", c.TreeHash.String()); err != nil {
  20. return nil
  21. }
  22. for _, parent := range c.ParentHashes {
  23. if _, err = fmt.Fprintf(&w, "parent %s\n", parent.String()); err != nil {
  24. return nil
  25. }
  26. }
  27. if _, err = fmt.Fprint(&w, "author "); err != nil {
  28. return nil
  29. }
  30. if err = c.Author.Encode(&w); err != nil {
  31. return nil
  32. }
  33. if _, err = fmt.Fprint(&w, "\ncommitter "); err != nil {
  34. return nil
  35. }
  36. if err = c.Committer.Encode(&w); err != nil {
  37. return nil
  38. }
  39. if _, err = fmt.Fprintf(&w, "\n\n%s", c.Message); err != nil {
  40. return nil
  41. }
  42. return &CommitGPGSignature{
  43. Signature: c.PGPSignature,
  44. Payload: w.String(),
  45. }
  46. }
  47. func convertCommit(c *object.Commit) *Commit {
  48. return &Commit{
  49. ID: c.Hash,
  50. CommitMessage: c.Message,
  51. Committer: &c.Committer,
  52. Author: &c.Author,
  53. Signature: convertPGPSignature(c),
  54. Parents: c.ParentHashes,
  55. }
  56. }