aboutsummaryrefslogtreecommitdiff
path: root/models/git_diff.go
diff options
context:
space:
mode:
author无闻 <u@gogs.io>2014-12-22 05:30:49 -0500
committer无闻 <u@gogs.io>2014-12-22 05:30:49 -0500
commite193005c66e3c61593efd2d44005efbca0fab33a (patch)
treeb5e51343456338eeea89d09bb24d93e7142f5d99 /models/git_diff.go
parentebbe6177a91e9eb6b4001342728ff099cafd5d65 (diff)
parentfff8109567f8296f81954dbf6280eb3049bb3db8 (diff)
Merge pull request #773 from phsmit/golang_x_text_encoding
Golang x text encoding
Diffstat (limited to 'models/git_diff.go')
-rw-r--r--models/git_diff.go18
1 files changed, 12 insertions, 6 deletions
diff --git a/models/git_diff.go b/models/git_diff.go
index 4bbe3c0e..7e91626f 100644
--- a/models/git_diff.go
+++ b/models/git_diff.go
@@ -14,12 +14,14 @@ import (
"strings"
"time"
+ "golang.org/x/net/html/charset"
+ "golang.org/x/text/transform"
+
"github.com/Unknwon/com"
"github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/git"
"github.com/gogits/gogs/modules/log"
- "github.com/gogits/gogs/modules/mahonia"
"github.com/gogits/gogs/modules/process"
)
@@ -192,14 +194,18 @@ func ParsePatch(pid int64, maxlines int, cmd *exec.Cmd, reader io.Reader) (*Diff
}
// FIXME: use first 30 lines to detect file encoding.
- charset, err := base.DetectEncoding(buf.Bytes())
- if charset != "utf8" && err == nil {
- decoder := mahonia.NewDecoder(charset)
- if decoder != nil {
+ charsetLabel, err := base.DetectEncoding(buf.Bytes())
+ if charsetLabel != "utf8" && err == nil {
+ encoding, _ := charset.Lookup(charsetLabel)
+
+ if encoding != nil {
+ d := encoding.NewDecoder()
for _, f := range diff.Files {
for _, sec := range f.Sections {
for _, l := range sec.Lines {
- l.Content = decoder.ConvertString(l.Content)
+ if c, _, err := transform.String(d, l.Content); err == nil {
+ l.Content = c
+ }
}
}
}