From 95f9c85bcc8f915d823f57cd5923302dfc156504 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Sun, 13 Dec 2015 19:56:33 -0500 Subject: [PATCH] #2185 use Go sub-repo to detect encoding --- .gopmfile | 1 - README.md | 4 ++-- gogs.go | 2 +- models/git_diff.go | 4 ++-- modules/base/tool.go | 13 ++++--------- modules/template/template.go | 6 +----- templates/.VERSION | 2 +- 7 files changed, 11 insertions(+), 21 deletions(-) diff --git a/.gopmfile b/.gopmfile index e28b41d4285..5154aad0cd8 100644 --- a/.gopmfile +++ b/.gopmfile @@ -16,7 +16,6 @@ github.com/go-macaron/toolbox = commit:ab30a81 github.com/go-sql-driver/mysql = commit:d512f20 github.com/go-xorm/core = commit:acb6f00 github.com/go-xorm/xorm = commit:a8fba4d -github.com/gogits/chardet = commit:2404f77725 github.com/gogits/git-shell = commit:1ffc4bc github.com/gogits/go-gogs-client = commit:4b541fa github.com/issue9/identicon = commit:f8c0d2c diff --git a/README.md b/README.md index d151b5cf50a..ca82dc7a3c2 100644 --- a/README.md +++ b/README.md @@ -3,7 +3,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra ![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true) -##### Current version: 0.8.1 +##### Current version: 0.8.2 | Web | UI | Preview | |:-------------:|:-------:|:-------:| @@ -85,7 +85,7 @@ There are 5 ways to install Gogs: ### Screencasts -- [Instalando Gogs no Ubuntu](http://blog.linuxpro.com.br/2015/08/14/instalando-gogs-no-ubuntu/) (Português) +- [Instalando Gogs no Ubuntu](https://www.youtube.com/watch?v=4UkHAR1F7ZA) (Português) ### Deploy to Cloud diff --git a/gogs.go b/gogs.go index a9835cf156d..d43dd53aca7 100644 --- a/gogs.go +++ b/gogs.go @@ -18,7 +18,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.8.1.1213" +const APP_VER = "0.8.2.1213" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/models/git_diff.go b/models/git_diff.go index a94ea0abc7c..725806699ef 100644 --- a/models/git_diff.go +++ b/models/git_diff.go @@ -244,8 +244,8 @@ func ParsePatch(maxlines int, reader io.Reader) (*Diff, error) { buf.WriteString("\n") } } - charsetLabel, err := base.DetectEncoding(buf.Bytes()) - if charsetLabel != "UTF-8" && err == nil { + charsetLabel := base.DetectEncoding(buf.Bytes()) + if charsetLabel != "UTF-8" { encoding, _ := charset.Lookup(charsetLabel) if encoding != nil { d := encoding.NewDecoder() diff --git a/modules/base/tool.go b/modules/base/tool.go index b1d945117ca..46eeca9b2b2 100644 --- a/modules/base/tool.go +++ b/modules/base/tool.go @@ -22,8 +22,7 @@ import ( "github.com/Unknwon/com" "github.com/Unknwon/i18n" "github.com/microcosm-cc/bluemonday" - - "github.com/gogits/chardet" + "golang.org/x/net/html/charset" "github.com/gogits/gogs/modules/avatar" "github.com/gogits/gogs/modules/setting" @@ -52,13 +51,9 @@ func ShortSha(sha1 string) string { return sha1 } -func DetectEncoding(content []byte) (string, error) { - detector := chardet.NewTextDetector() - result, err := detector.DetectBest(content) - if result.Charset != "UTF-8" && len(setting.Repository.AnsiCharset) > 0 { - return setting.Repository.AnsiCharset, err - } - return result.Charset, err +func DetectEncoding(content []byte) string { + _, name, _ := charset.DetermineEncoding(content, setting.Repository.AnsiCharset) + return name } func BasicAuthDecode(encoded string) (string, string, error) { diff --git a/modules/template/template.go b/modules/template/template.go index 9d63452dd38..cc670a651f6 100644 --- a/modules/template/template.go +++ b/modules/template/template.go @@ -127,11 +127,7 @@ func Sha1(str string) string { } func ToUtf8WithErr(content []byte) (error, string) { - charsetLabel, err := base.DetectEncoding(content) - if err != nil { - return err, "" - } - + charsetLabel := base.DetectEncoding(content) if charsetLabel == "UTF-8" { return nil, string(content) } diff --git a/templates/.VERSION b/templates/.VERSION index 945200b36fb..999b994412c 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.8.1.1213 \ No newline at end of file +0.8.2.1213 \ No newline at end of file