"github.com/go-git/go-git/v5"
"github.com/go-git/go-git/v5/plumbing"
"github.com/go-git/go-git/v5/plumbing/object"
+ "go.cypherpunks.ru/recfile"
)
const (
func parseComments(data []byte) []string {
comments := []string{}
- isBody := false
- comment := make([]string, 0, 4)
- lines := strings.Split(strings.TrimSuffix(string(data), "\n"), "\n")
- if len(lines) == 1 {
- return comments
- }
- for _, s := range lines {
- if s == "" {
- comments = append(comments, strings.Join(comment, "\n"))
- comment = make([]string, 0, 4)
- isBody = false
- continue
- }
- if s == "Body:" {
- isBody = true
- comment = append(comment, "")
- continue
+ r := recfile.NewReader(bytes.NewReader(data))
+ for {
+ fields, err := r.Next()
+ if err != nil {
+ break
}
- if isBody {
- if s == "+" {
- comment = append(comment, "")
- } else {
- comment = append(comment, strings.TrimPrefix(s, "+ "))
- }
+ if len(fields) != 3 ||
+ fields[0].Name != "From" ||
+ fields[1].Name != "Date" ||
+ fields[2].Name != "Body" {
continue
}
- comment = append(comment, s)
- }
- if len(comment) > 1 {
- comments = append(comments, strings.Join(comment, "\n"))
+ comments = append(comments, fmt.Sprintf(
+ "%s: %s\n%s: %s\n%s",
+ fields[0].Name, fields[0].Value,
+ fields[1].Name, fields[1].Value,
+ fields[2].Value,
+ ))
}
return comments
}
github.com/go-git/go-git/v5 v5.1.0
github.com/hjson/hjson-go v3.0.1+incompatible
github.com/imdario/mergo v0.3.11 // indirect
+ go.cypherpunks.ru/recfile v0.1.0
golang.org/x/crypto v0.0.0-20200820211705-5c72a883971a
golang.org/x/net v0.0.0-20200925080053-05aa5d4ee321 // indirect
golang.org/x/sys v0.0.0-20200923182605-d9f96fdee20d // indirect
github.com/stretchr/testify v1.4.0/go.mod h1:j7eGeouHqKxXV5pUuKE4zz7dFj8WfuZ+81PSLYec5m4=
github.com/xanzy/ssh-agent v0.2.1 h1:TCbipTQL2JiiCprBWx9frJ2eJlCYT00NmctrHxVAr70=
github.com/xanzy/ssh-agent v0.2.1/go.mod h1:mLlQY/MoOhWBj+gOGMQkOeiEvkx+8pJSI+0Bx9h2kr4=
+go.cypherpunks.ru/recfile v0.1.0 h1:JNtRwUpA6zXl/mJTBY3zK0ynmh3Dbp4dZb2zN+HUmnk=
+go.cypherpunks.ru/recfile v0.1.0/go.mod h1:p1ZUMeyQQbQg+ICtKH3+Zt59QLI0tCZYZj/75Vp1buk=
golang.org/x/crypto v0.0.0-20190219172222-a4c6cb3142f2/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200302210943-78000ba7a073/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=