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.3KB

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