mirror of
https://github.com/go-gitea/gitea
synced 2025-07-22 18:28:37 +00:00
toutf8 improved & add max git diff lines
This commit is contained in:
@@ -12,6 +12,7 @@ import (
|
||||
"github.com/gogits/gogs/models"
|
||||
"github.com/gogits/gogs/modules/base"
|
||||
"github.com/gogits/gogs/modules/middleware"
|
||||
"github.com/gogits/gogs/modules/setting"
|
||||
)
|
||||
|
||||
const (
|
||||
@@ -114,7 +115,8 @@ func Diff(ctx *middleware.Context) {
|
||||
|
||||
commit := ctx.Repo.Commit
|
||||
|
||||
diff, err := models.GetDiffCommit(models.RepoPath(userName, repoName), commitId)
|
||||
diff, err := models.GetDiffCommit(models.RepoPath(userName, repoName),
|
||||
commitId, setting.MaxGitDiffLines)
|
||||
if err != nil {
|
||||
ctx.Handle(404, "GetDiffCommit", err)
|
||||
return
|
||||
@@ -176,7 +178,8 @@ func CompareDiff(ctx *middleware.Context) {
|
||||
return
|
||||
}
|
||||
|
||||
diff, err := models.GetDiffRange(models.RepoPath(userName, repoName), beforeCommitId, afterCommitId)
|
||||
diff, err := models.GetDiffRange(models.RepoPath(userName, repoName), beforeCommitId,
|
||||
afterCommitId, setting.MaxGitDiffLines)
|
||||
if err != nil {
|
||||
ctx.Handle(404, "GetDiffRange", err)
|
||||
return
|
||||
|
@@ -11,12 +11,9 @@ import (
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"github.com/saintfish/chardet"
|
||||
|
||||
"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/middleware"
|
||||
)
|
||||
|
||||
@@ -24,21 +21,6 @@ const (
|
||||
HOME base.TplName = "repo/home"
|
||||
)
|
||||
|
||||
func toUtf8(content []byte) (error, string) {
|
||||
detector := chardet.NewTextDetector()
|
||||
result, err := detector.DetectBest(content)
|
||||
if err != nil {
|
||||
return err, ""
|
||||
}
|
||||
|
||||
if result.Charset == "utf8" {
|
||||
return nil, string(content)
|
||||
}
|
||||
|
||||
decoder := mahonia.NewDecoder(result.Charset)
|
||||
return nil, decoder.ConvertString(string(content))
|
||||
}
|
||||
|
||||
func Home(ctx *middleware.Context) {
|
||||
ctx.Data["Title"] = ctx.Repo.Repository.Name
|
||||
|
||||
@@ -117,7 +99,7 @@ func Home(ctx *middleware.Context) {
|
||||
if readmeExist {
|
||||
ctx.Data["FileContent"] = string(base.RenderMarkdown(buf, ""))
|
||||
} else {
|
||||
if err, content := toUtf8(buf); err != nil {
|
||||
if err, content := base.ToUtf8WithErr(buf); err != nil {
|
||||
if err != nil {
|
||||
log.Error(4, "Convert content encoding: %s", err)
|
||||
}
|
||||
|
Reference in New Issue
Block a user