]> Sergey Matveev's repositories - sgblog.git/blobdiff - cmd/sgblog-comment-add/main.go
Fix tabs issues in comments
[sgblog.git] / cmd / sgblog-comment-add / main.go
index e74558eca40ce65f4ba52048ff6595af3db0a548..719431b37318c1576402c7528531e14b50d7fbdf 100644 (file)
@@ -26,6 +26,7 @@ import (
        "fmt"
        "io/ioutil"
        "log"
+       "mime"
        "net/mail"
        "os"
        "os/exec"
@@ -79,6 +80,10 @@ func main() {
        if len(body) == 0 {
                log.Fatal("no body")
        }
+       from, err = new(mime.WordDecoder).DecodeHeader(from)
+       if err != nil {
+               log.Fatal(err)
+       }
 
        subj = strings.TrimPrefix(subj, "Re: ")
        if h, err := hex.DecodeString(subj); err != nil || len(h) != sha1.Size {
@@ -101,10 +106,13 @@ func main() {
        note = bytes.TrimRight(note, "\r\n")
 
        // Remove trailing whitespaces, because git-notes-add will remove
-       // them anyway, and we have to know exact bytes count
+       // them anyway, and we have to know exact bytes count. Also convert
+       // all tabs into spaces
        lines := strings.Split(string(body), "\n")
        for i, line := range lines {
-               lines[i] = strings.TrimRight(line, " \r")
+               line = strings.ReplaceAll(line, "       ", "    ")
+               line = strings.TrimRight(line, " \r")
+               lines[i] = line
        }
        for lines[len(lines)-1] == "" {
                lines = lines[:len(lines)-1]