"syscall"
"time"
- "go.cypherpunks.ru/netstring/v2"
"go.stargrave.org/sgblog"
)
// 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 {
+func cleanupBody(body string) []string {
lines := strings.Split(string(body), "\n")
for i, line := range lines {
line = strings.ReplaceAll(line, " ", " ")
}
withoutDups = append(withoutDups, line)
}
- return strings.Join(withoutDups, "\n")
+ return withoutDups
}
func main() {
note = bytes.TrimRight(note, "\r\n")
buf := bytes.NewBuffer(note)
- w := netstring.NewWriter(buf)
- w.WriteChunk([]byte(fmt.Sprintf(
- "From: %s\nDate: %s\n\n%s",
+ buf.WriteString(fmt.Sprintf(
+ "\n\nFrom: %s\nDate: %s\nBody:\n",
from,
time.Now().UTC().Format(sgblog.WhenFmt),
- cleanupBody(string(body)),
- )))
+ ))
+ for _, s := range cleanupBody(string(body)) {
+ buf.WriteString("+ ")
+ buf.WriteString(s)
+ buf.WriteString("\n")
+ }
if *dryRun {
fmt.Print(buf.String())