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

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  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. package git
  7. import (
  8. "fmt"
  9. "strings"
  10. "github.com/go-git/go-git/v5/plumbing/object"
  11. )
  12. func convertPGPSignature(c *object.Commit) *CommitGPGSignature {
  13. if c.PGPSignature == "" {
  14. return nil
  15. }
  16. var w strings.Builder
  17. var err error
  18. if _, err = fmt.Fprintf(&w, "tree %s\n", c.TreeHash.String()); err != nil {
  19. return nil
  20. }
  21. for _, parent := range c.ParentHashes {
  22. if _, err = fmt.Fprintf(&w, "parent %s\n", parent.String()); err != nil {
  23. return nil
  24. }
  25. }
  26. if _, err = fmt.Fprint(&w, "author "); err != nil {
  27. return nil
  28. }
  29. if err = c.Author.Encode(&w); err != nil {
  30. return nil
  31. }
  32. if _, err = fmt.Fprint(&w, "\ncommitter "); err != nil {
  33. return nil
  34. }
  35. if err = c.Committer.Encode(&w); err != nil {
  36. return nil
  37. }
  38. if _, err = fmt.Fprintf(&w, "\n\n%s", c.Message); err != nil {
  39. return nil
  40. }
  41. return &CommitGPGSignature{
  42. Signature: c.PGPSignature,
  43. Payload: w.String(),
  44. }
  45. }
  46. func convertCommit(c *object.Commit) *Commit {
  47. return &Commit{
  48. ID: c.Hash,
  49. CommitMessage: c.Message,
  50. Committer: &c.Committer,
  51. Author: &c.Author,
  52. Signature: convertPGPSignature(c),
  53. Parents: c.ParentHashes,
  54. }
  55. }