diff --git a/models/repo/repo.go b/models/repo/repo.go index 12181ef71bb..21c0c097ab5 100644 --- a/models/repo/repo.go +++ b/models/repo/repo.go @@ -162,8 +162,8 @@ type Repository struct { BaseRepo *Repository `xorm:"-"` IsTemplate bool `xorm:"INDEX NOT NULL DEFAULT false"` TemplateID int64 `xorm:"INDEX"` - Size int64 `xorm:"NOT NULL DEFAULT 0"` SizeLimit int64 `xorm:"NOT NULL DEFAULT 0"` + Size int64 `xorm:"NOT NULL DEFAULT 0"` EnableSizeLimit bool `xorm:"NOT NULL DEFAULT true"` CodeIndexerStatus *RepoIndexerStatus `xorm:"-"` StatsIndexerStatus *RepoIndexerStatus `xorm:"-"` @@ -538,9 +538,17 @@ func (repo *Repository) IsOwnedBy(userID int64) bool { // return repo.updateSize(ctx.e) // } +func (repo *Repository) GetActualSizeLimit() int64 { + sizeLimit := repo.SizeLimit + if setting.RepoSizeLimit > 0 && sizeLimit == 0 { + sizeLimit = setting.RepoSizeLimit + } + return sizeLimit +} + // RepoSizeIsOversized return if is over size limitation func (repo *Repository) RepoSizeIsOversized(additionalSize int64) bool { - return repo.SizeLimit > 0 && repo.Size+additionalSize > repo.SizeLimit + return setting.EnableSizeLimit && repo.GetActualSizeLimit() > 0 && repo.Size+additionalSize > repo.GetActualSizeLimit() } // CanCreateBranch returns true if repository meets the requirements for creating new branches. diff --git a/modules/setting/repository.go b/modules/setting/repository.go index a495f471d6b..57eeaf99ce6 100644 --- a/modules/setting/repository.go +++ b/modules/setting/repository.go @@ -289,8 +289,8 @@ func loadRepositoryFrom(rootCfg ConfigProvider) { // Determine and create root git repository path. sec := rootCfg.Section("repository") - EnableSizeLimit = sec.Key("ENABLE_SIZE_LIMIT").MustBool() - RepoSizeLimit = sec.Key("REPO_SIZE_LIMIT").MustInt64(0) + EnableSizeLimit = sec.Key("ENABLE_SIZE_LIMIT").MustBool(true) + RepoSizeLimit = sec.Key("REPO_SIZE_LIMIT").MustInt64(1024 * 1024 * 10) Repository.DisableHTTPGit = sec.Key("DISABLE_HTTP_GIT").MustBool() Repository.UseCompatSSHURI = sec.Key("USE_COMPAT_SSH_URI").MustBool() Repository.MaxCreationLimit = sec.Key("MAX_CREATION_LIMIT").MustInt(-1) diff --git a/options/locale/locale_en-US.ini b/options/locale/locale_en-US.ini index 5a922c0eda0..d6a28a9c0fd 100644 --- a/options/locale/locale_en-US.ini +++ b/options/locale/locale_en-US.ini @@ -3009,6 +3009,12 @@ config.picture_service = Picture Service config.disable_gravatar = Disable Gravatar config.enable_federated_avatar = Enable Federated Avatars +config.repository_config = Repository Configuration +config.enable_size_limit = Enable Size Limit +config.repo_size_limit = Default Repository Size Limit +config.invalid_repo_size = Invalid repository size. +config.repository_setting_success = Global repository setting has been updated. + config.git_config = Git Configuration config.git_disable_diff_highlight = Disable Diff Syntax Highlight config.git_max_diff_lines = Max Diff Lines (for a single file) diff --git a/routers/web/admin/repos.go b/routers/web/admin/repos.go index 2287f81fe1f..13c4962c349 100644 --- a/routers/web/admin/repos.go +++ b/routers/web/admin/repos.go @@ -66,9 +66,6 @@ func UpdateRepoPost(ctx *context.Context) { } setting.SaveGlobalRepositorySetting(form.EnableSizeLimit, repo_size_limit) - ctx.Flash.Success(ctx.Tr("admin.config.repository_setting_success")) - - ctx.Data["RepoSizeLimit"] = base.FileSize(setting.RepoSizeLimit) ctx.Flash.Success(ctx.Tr("admin.config.repository_setting_success")) ctx.Redirect(setting.AppSubURL + "/admin/repos") diff --git a/routers/web/repo/setting.go b/routers/web/repo/setting.go index c30276c4265..2999fc247e7 100644 --- a/routers/web/repo/setting.go +++ b/routers/web/repo/setting.go @@ -67,7 +67,9 @@ func SettingsCtxData(ctx *context.Context) { ctx.Data["DisableNewPushMirrors"] = setting.Mirror.DisableNewPush ctx.Data["DefaultMirrorInterval"] = setting.Mirror.DefaultInterval ctx.Data["MinimumMirrorInterval"] = setting.Mirror.MinInterval - ctx.Data["Err_RepoSize"] = ctx.Repo.Repository.RepoSizeIsOversized(ctx.Repo.Repository.SizeLimit / 10) // less than 10% left + ctx.Data["Err_RepoSize"] = ctx.Repo.Repository.RepoSizeIsOversized(ctx.Repo.Repository.GetActualSizeLimit() / 10) // less than 10% left + ctx.Data["ActualSizeLimit"] = ctx.Repo.Repository.GetActualSizeLimit() + ctx.Data["EnableSizeLimit"] = setting.EnableSizeLimit signing, _ := asymkey_service.SigningKey(ctx, ctx.Repo.Repository.RepoPath()) ctx.Data["SigningKeyAvailable"] = len(signing) > 0 diff --git a/templates/repo/settings/options.tmpl b/templates/repo/settings/options.tmpl index b1932337742..0a8232f58bd 100644 --- a/templates/repo/settings/options.tmpl +++ b/templates/repo/settings/options.tmpl @@ -13,14 +13,18 @@
- - {{FileSize .Repository.Size}}{{if .Repository.SizeLimit}}/{{FileSize .Repository.SizeLimit}}{{end}} + + {{FileSize .Repository.Size}} + {{if and .Repository.SizeLimit .EnableSizeLimit}} + /{{FileSize .ActualSizeLimit}} + {{end}} +
- - - {{FileSize .Repository.Size}} +