"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
}