summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorUnknwon <joe2010xtmf@163.com>2015-01-17 15:29:45 +0800
committerUnknwon <joe2010xtmf@163.com>2015-01-17 15:29:45 +0800
commit452cca35e0d1126fa31adc2f89165e64d8cf7afe (patch)
tree045fcbc0bec1fd590ec16d931d5f518f1d3ac77f /models
parent7170011f4d93a50e73cf90232395484b70a3dbb3 (diff)
parentf99690a54573420dab26ba82cb02fc027a8db891 (diff)
downloadgitea-452cca35e0d1126fa31adc2f89165e64d8cf7afe.tar.gz
gitea-452cca35e0d1126fa31adc2f89165e64d8cf7afe.zip
Merge branch 'encoding' of github.com:gogits/gogs into dev
Conflicts: .gopmfile
Diffstat (limited to 'models')
-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 4bbe3c0e8f..7e91626f1d 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
+ }
}
}
}