Skip to content

Commit 95f9c85

Browse files
committed
#2185 use Go sub-repo to detect encoding
1 parent 79dcd7e commit 95f9c85

File tree

7 files changed

+11
-21
lines changed

7 files changed

+11
-21
lines changed

.gopmfile

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@ github.com/go-macaron/toolbox = commit:ab30a81
1616
github.com/go-sql-driver/mysql = commit:d512f20
1717
github.com/go-xorm/core = commit:acb6f00
1818
github.com/go-xorm/xorm = commit:a8fba4d
19-
github.com/gogits/chardet = commit:2404f77725
2019
github.com/gogits/git-shell = commit:1ffc4bc
2120
github.com/gogits/go-gogs-client = commit:4b541fa
2221
github.com/issue9/identicon = commit:f8c0d2c

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ Gogs - Go Git Service [![Build Status](https://travis-ci.org/gogits/gogs.svg?bra
33

44
![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true)
55

6-
##### Current version: 0.8.1
6+
##### Current version: 0.8.2
77

88
| Web | UI | Preview |
99
|:-------------:|:-------:|:-------:|
@@ -85,7 +85,7 @@ There are 5 ways to install Gogs:
8585

8686
### Screencasts
8787

88-
- [Instalando Gogs no Ubuntu](http://blog.linuxpro.com.br/2015/08/14/instalando-gogs-no-ubuntu/) (Português)
88+
- [Instalando Gogs no Ubuntu](https://www.youtube.com/watch?v=4UkHAR1F7ZA) (Português)
8989

9090
### Deploy to Cloud
9191

gogs.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ import (
1818
"github.com/gogits/gogs/modules/setting"
1919
)
2020

21-
const APP_VER = "0.8.1.1213"
21+
const APP_VER = "0.8.2.1213"
2222

2323
func init() {
2424
runtime.GOMAXPROCS(runtime.NumCPU())

models/git_diff.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ func ParsePatch(maxlines int, reader io.Reader) (*Diff, error) {
244244
buf.WriteString("\n")
245245
}
246246
}
247-
charsetLabel, err := base.DetectEncoding(buf.Bytes())
248-
if charsetLabel != "UTF-8" && err == nil {
247+
charsetLabel := base.DetectEncoding(buf.Bytes())
248+
if charsetLabel != "UTF-8" {
249249
encoding, _ := charset.Lookup(charsetLabel)
250250
if encoding != nil {
251251
d := encoding.NewDecoder()

modules/base/tool.go

Lines changed: 4 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,7 @@ import (
2222
"github.com/Unknwon/com"
2323
"github.com/Unknwon/i18n"
2424
"github.com/microcosm-cc/bluemonday"
25-
26-
"github.com/gogits/chardet"
25+
"golang.org/x/net/html/charset"
2726

2827
"github.com/gogits/gogs/modules/avatar"
2928
"github.com/gogits/gogs/modules/setting"
@@ -52,13 +51,9 @@ func ShortSha(sha1 string) string {
5251
return sha1
5352
}
5453

55-
func DetectEncoding(content []byte) (string, error) {
56-
detector := chardet.NewTextDetector()
57-
result, err := detector.DetectBest(content)
58-
if result.Charset != "UTF-8" && len(setting.Repository.AnsiCharset) > 0 {
59-
return setting.Repository.AnsiCharset, err
60-
}
61-
return result.Charset, err
54+
func DetectEncoding(content []byte) string {
55+
_, name, _ := charset.DetermineEncoding(content, setting.Repository.AnsiCharset)
56+
return name
6257
}
6358

6459
func BasicAuthDecode(encoded string) (string, string, error) {

modules/template/template.go

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,7 @@ func Sha1(str string) string {
127127
}
128128

129129
func ToUtf8WithErr(content []byte) (error, string) {
130-
charsetLabel, err := base.DetectEncoding(content)
131-
if err != nil {
132-
return err, ""
133-
}
134-
130+
charsetLabel := base.DetectEncoding(content)
135131
if charsetLabel == "UTF-8" {
136132
return nil, string(content)
137133
}

templates/.VERSION

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.8.1.1213
1+
0.8.2.1213

0 commit comments

Comments
 (0)