Optmize git-fsck options and fix #820

This commit is contained in:
Unknwon 2015-01-02 20:14:43 +08:00
parent 0b56272c13
commit c73e9057ae
6 changed files with 32 additions and 16 deletions

View file

@ -25,6 +25,7 @@ import (
"github.com/macaron-contrib/oauth2" "github.com/macaron-contrib/oauth2"
"github.com/macaron-contrib/session" "github.com/macaron-contrib/session"
"github.com/macaron-contrib/toolbox" "github.com/macaron-contrib/toolbox"
"gopkg.in/ini.v1"
api "github.com/gogits/go-gogs-client" api "github.com/gogits/go-gogs-client"
@ -79,6 +80,7 @@ func checkVersion() {
{"github.com/macaron-contrib/csrf", csrf.Version, "0.0.1"}, {"github.com/macaron-contrib/csrf", csrf.Version, "0.0.1"},
{"github.com/macaron-contrib/i18n", i18n.Version, "0.0.5"}, {"github.com/macaron-contrib/i18n", i18n.Version, "0.0.5"},
{"github.com/macaron-contrib/session", session.Version, "0.1.1"}, {"github.com/macaron-contrib/session", session.Version, "0.1.1"},
{"gopkg.in/ini.v1", ini.Version, "1.0.1"},
} }
for _, c := range checkers { for _, c := range checkers {
ver := strings.Join(strings.Split(c.Version(), ".")[:3], ".") ver := strings.Join(strings.Split(c.Version(), ".")[:3], ".")

View file

@ -260,14 +260,20 @@ DRIVER =
CONN = CONN =
[git] [git]
MAX_GITDIFF_LINES = 10000 MAX_GIT_DIFF_LINES = 10000
; Arguments for command 'git fsck', e.g.: "--unreachable --tags"
; see more on http://git-scm.com/docs/git-fsck/1.7.5
FSCK_ARGS =
; Arguments for command 'git gc', e.g.: "--aggressive --auto" ; Arguments for command 'git gc', e.g.: "--aggressive --auto"
; see more on http://git-scm.com/docs/git-gc/1.7.5 ; see more on http://git-scm.com/docs/git-gc/1.7.5
GC_ARGS = GC_ARGS =
; Git health check.
[git.fsck]
ENABLE = true
; Execution interval in hours. Default is 24.
INTERVAL = 24
; Arguments for command 'git fsck', e.g.: "--unreachable --tags"
; see more on http://git-scm.com/docs/git-fsck/1.7.5
ARGS =
[i18n] [i18n]
LANGS = en-US,zh-CN,zh-HK,de-DE,fr-CA,nl-NL,lv-LV LANGS = en-US,zh-CN,zh-HK,de-DE,fr-CA,nl-NL,lv-LV
NAMES = English,简体中文,繁體中文,Deutsch,Français,Nederlands,Latviešu NAMES = English,简体中文,繁體中文,Deutsch,Français,Nederlands,Latviešu

View file

@ -1228,7 +1228,7 @@ func GitFsck() {
isGitFscking = true isGitFscking = true
defer func() { isGitFscking = false }() defer func() { isGitFscking = false }()
args := append([]string{"fsck"}, setting.GitFsckArgs...) args := append([]string{"fsck"}, setting.Git.Fsck.Args...)
if err := x.Where("id > 0").Iterate(new(Repository), if err := x.Where("id > 0").Iterate(new(Repository),
func(idx int, bean interface{}) error { func(idx int, bean interface{}) error {
repo := bean.(*Repository) repo := bean.(*Repository)
@ -1252,7 +1252,7 @@ func GitFsck() {
} }
func GitGcRepos() error { func GitGcRepos() error {
args := append([]string{"gc"}, setting.GitGcArgs...) args := append([]string{"gc"}, setting.Git.GcArgs...)
return x.Where("id > 0").Iterate(new(Repository), return x.Where("id > 0").Iterate(new(Repository),
func(idx int, bean interface{}) error { func(idx int, bean interface{}) error {
repo := bean.(*Repository) repo := bean.(*Repository)

View file

@ -16,7 +16,9 @@ var c = New()
func NewCronContext() { func NewCronContext() {
c.AddFunc("Update mirrors", "@every 1h", models.MirrorUpdate) c.AddFunc("Update mirrors", "@every 1h", models.MirrorUpdate)
c.AddFunc("Deliver hooks", fmt.Sprintf("@every %dm", setting.WebhookTaskInterval), models.DeliverHooks) c.AddFunc("Deliver hooks", fmt.Sprintf("@every %dm", setting.WebhookTaskInterval), models.DeliverHooks)
c.AddFunc("Repository health check", "@every 1h", models.GitFsck) if setting.Git.Fsck.Enable {
c.AddFunc("Repository health check", fmt.Sprintf("@every %dh", setting.Git.Fsck.Interval), models.GitFsck)
}
c.Start() c.Start()
} }

View file

@ -107,9 +107,15 @@ var (
SessionConfig session.Options SessionConfig session.Options
// Git settings. // Git settings.
Git struct {
MaxGitDiffLines int MaxGitDiffLines int
GitFsckArgs []string GcArgs []string `delim:" "`
GitGcArgs []string Fsck struct {
Enable bool
Interval int
Args []string `delim:" "`
} `ini:"git.fsck"`
}
// I18n settings. // I18n settings.
Langs, Names []string Langs, Names []string
@ -174,6 +180,7 @@ func NewConfigContext() {
} else { } else {
log.Warn("No custom 'conf/app.ini' found, please go to '/install'") log.Warn("No custom 'conf/app.ini' found, please go to '/install'")
} }
Cfg.NameMapper = ini.AllCapsUnderscore
LogRootPath = Cfg.Section("log").Key("ROOT_PATH").MustString(path.Join(workDir, "log")) LogRootPath = Cfg.Section("log").Key("ROOT_PATH").MustString(path.Join(workDir, "log"))
@ -291,10 +298,9 @@ func NewConfigContext() {
} }
DisableGravatar = sec.Key("DISABLE_GRAVATAR").MustBool() DisableGravatar = sec.Key("DISABLE_GRAVATAR").MustBool()
sec = Cfg.Section("git") if err = Cfg.Section("git").MapTo(&Git); err != nil {
MaxGitDiffLines = sec.Key("MAX_GITDIFF_LINES").MustInt(10000) log.Fatal(4, "Fail to map Git settings: %v", err)
GitFsckArgs = sec.Key("FSCK_ARGS").Strings(" ") }
GitGcArgs = sec.Key("GC_ARGS").Strings(" ")
Langs = Cfg.Section("i18n").Key("LANGS").Strings(",") Langs = Cfg.Section("i18n").Key("LANGS").Strings(",")
Names = Cfg.Section("i18n").Key("NAMES").Strings(",") Names = Cfg.Section("i18n").Key("NAMES").Strings(",")

View file

@ -208,7 +208,7 @@ func Diff(ctx *middleware.Context) {
commit := ctx.Repo.Commit commit := ctx.Repo.Commit
commit.CommitMessage = string(base.RenderIssueIndexPattern([]byte(commit.CommitMessage), ctx.Repo.RepoLink)) commit.CommitMessage = string(base.RenderIssueIndexPattern([]byte(commit.CommitMessage), ctx.Repo.RepoLink))
diff, err := models.GetDiffCommit(models.RepoPath(userName, repoName), diff, err := models.GetDiffCommit(models.RepoPath(userName, repoName),
commitId, setting.MaxGitDiffLines) commitId, setting.Git.MaxGitDiffLines)
if err != nil { if err != nil {
ctx.Handle(404, "GetDiffCommit", err) ctx.Handle(404, "GetDiffCommit", err)
return return
@ -272,7 +272,7 @@ func CompareDiff(ctx *middleware.Context) {
} }
diff, err := models.GetDiffRange(models.RepoPath(userName, repoName), beforeCommitId, diff, err := models.GetDiffRange(models.RepoPath(userName, repoName), beforeCommitId,
afterCommitId, setting.MaxGitDiffLines) afterCommitId, setting.Git.MaxGitDiffLines)
if err != nil { if err != nil {
ctx.Handle(404, "GetDiffRange", err) ctx.Handle(404, "GetDiffRange", err)
return return