+// Remove various whitespaces and excess lines, because git-notes-add
+// will remove and we have to know exact bytes count
+func cleanupBody(body string) string {
+ lines := strings.Split(string(body), "\n")
+ for i, line := range lines {
+ line = strings.ReplaceAll(line, " ", " ")
+ line = strings.TrimRight(line, " \r")
+ lines[i] = line
+ }
+ for lines[0] == "" {
+ lines = lines[1:]
+ }
+ for lines[len(lines)-1] == "" {
+ lines = lines[:len(lines)-1]
+ }
+ withoutDups := make([]string, 0, len(lines))
+ emptyMet := false
+ for _, line := range lines {
+ if line == "" {
+ if emptyMet {
+ continue
+ }
+ emptyMet = true
+ } else {
+ emptyMet = false
+ }
+ withoutDups = append(withoutDups, line)
+ }
+ return strings.Join(withoutDups, "\n")
+}
+