Browse Source

#2185 use Go sub-repo to detect encoding

tags/v0.9.99
Unknwon 8 years ago
parent
commit
95f9c85bcc
7 changed files with 11 additions and 21 deletions
  1. 0
    1
      .gopmfile
  2. 2
    2
      README.md
  3. 1
    1
      gogs.go
  4. 2
    2
      models/git_diff.go
  5. 4
    9
      modules/base/tool.go
  6. 1
    5
      modules/template/template.go
  7. 1
    1
      templates/.VERSION

+ 0
- 1
.gopmfile View File

github.com/go-sql-driver/mysql = commit:d512f20 github.com/go-sql-driver/mysql = commit:d512f20
github.com/go-xorm/core = commit:acb6f00 github.com/go-xorm/core = commit:acb6f00
github.com/go-xorm/xorm = commit:a8fba4d github.com/go-xorm/xorm = commit:a8fba4d
github.com/gogits/chardet = commit:2404f77725
github.com/gogits/git-shell = commit:1ffc4bc github.com/gogits/git-shell = commit:1ffc4bc
github.com/gogits/go-gogs-client = commit:4b541fa github.com/gogits/go-gogs-client = commit:4b541fa
github.com/issue9/identicon = commit:f8c0d2c github.com/issue9/identicon = commit:f8c0d2c

+ 2
- 2
README.md View File



![](https://github.com/gogits/gogs/blob/master/public/img/gogs-large-resize.png?raw=true) ![](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 | | Web | UI | Preview |
|:-------------:|:-------:|:-------:| |:-------------:|:-------:|:-------:|


### Screencasts ### 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 ### Deploy to Cloud



+ 1
- 1
gogs.go View File

"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
) )


const APP_VER = "0.8.1.1213"
const APP_VER = "0.8.2.1213"


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

+ 2
- 2
models/git_diff.go View File

buf.WriteString("\n") 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) encoding, _ := charset.Lookup(charsetLabel)
if encoding != nil { if encoding != nil {
d := encoding.NewDecoder() d := encoding.NewDecoder()

+ 4
- 9
modules/base/tool.go View File

"github.com/Unknwon/com" "github.com/Unknwon/com"
"github.com/Unknwon/i18n" "github.com/Unknwon/i18n"
"github.com/microcosm-cc/bluemonday" "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/avatar"
"github.com/gogits/gogs/modules/setting" "github.com/gogits/gogs/modules/setting"
return sha1 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) { func BasicAuthDecode(encoded string) (string, string, error) {

+ 1
- 5
modules/template/template.go View File

} }


func ToUtf8WithErr(content []byte) (error, 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" { if charsetLabel == "UTF-8" {
return nil, string(content) return nil, string(content)
} }

+ 1
- 1
templates/.VERSION View File

0.8.1.1213
0.8.2.1213

Loading…
Cancel
Save