diff --git a/custom/conf/app.example.ini b/custom/conf/app.example.ini index ec0b7c5235d5..b59ceee4f1db 100644 --- a/custom/conf/app.example.ini +++ b/custom/conf/app.example.ini @@ -2196,7 +2196,8 @@ ROUTER = console ;SHOW_FOOTER_VERSION = true ;; Show template execution time in the footer ;SHOW_FOOTER_TEMPLATE_LOAD_TIME = true - +;; Generate sitemap. Defaults to `true`. +; ENABLE_SITEMAP = true ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; diff --git a/docs/content/doc/advanced/config-cheat-sheet.en-us.md b/docs/content/doc/advanced/config-cheat-sheet.en-us.md index ebc860c45742..df1911934c88 100644 --- a/docs/content/doc/advanced/config-cheat-sheet.en-us.md +++ b/docs/content/doc/advanced/config-cheat-sheet.en-us.md @@ -1233,3 +1233,4 @@ PROXY_HOSTS = *.github.com - `SHOW_FOOTER_BRANDING`: **false**: Show Gitea branding in the footer. - `SHOW_FOOTER_VERSION`: **true**: Show Gitea and Go version information in the footer. - `SHOW_FOOTER_TEMPLATE_LOAD_TIME`: **true**: Show time of template execution in the footer. +- `ENABLE_SITEMAP`: **true**: Generate sitemap. diff --git a/modules/git/repo_language_stats_gogit.go b/modules/git/repo_language_stats_gogit.go index 34b0dc45d374..503e774e7a33 100644 --- a/modules/git/repo_language_stats_gogit.go +++ b/modules/git/repo_language_stats_gogit.go @@ -44,7 +44,15 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err checker, deferable := repo.CheckAttributeReader(commitID) defer deferable() + // sizes contains the current calculated size of all files by language sizes := make(map[string]int64) + // by default we will only count the sizes of programming languages or markup languages + // unless they are explicitly set using linguist-language + includedLanguage := map[string]bool{} + // or if there's only one language in the repository + firstExcludedLanguage := "" + firstExcludedLanguageSize := int64(0) + err = tree.Files().ForEach(func(f *object.File) error { if f.Size == 0 { return nil @@ -75,8 +83,8 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err language = group } + // this language will always be added to the size sizes[language] += f.Size - return nil } else if language, has := attrs["gitlab-language"]; has && language != "unspecified" && language != "" { // strip off a ? if present @@ -90,6 +98,7 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err language = group } + // this language will always be added to the size sizes[language] += f.Size return nil } @@ -124,7 +133,18 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err language = group } - sizes[language] += f.Size + included, checked := includedLanguage[language] + if !checked { + langtype := enry.GetLanguageType(language) + included = langtype == enry.Programming || langtype == enry.Markup + includedLanguage[language] = included + } + if included { + sizes[language] += f.Size + } else if len(sizes) == 0 && (firstExcludedLanguage == "" || firstExcludedLanguage == language) { + firstExcludedLanguage = language + firstExcludedLanguageSize += f.Size + } return nil }) @@ -132,14 +152,9 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err return nil, err } - // filter special languages unless they are the only language - if len(sizes) > 1 { - for language := range sizes { - langtype := enry.GetLanguageType(language) - if langtype != enry.Programming && langtype != enry.Markup { - delete(sizes, language) - } - } + // If there are no included languages add the first excluded language + if len(sizes) == 0 && firstExcludedLanguage != "" { + sizes[firstExcludedLanguage] = firstExcludedLanguageSize } return sizes, nil diff --git a/modules/git/repo_language_stats_nogogit.go b/modules/git/repo_language_stats_nogogit.go index 7388ef403b92..baeb1149098f 100644 --- a/modules/git/repo_language_stats_nogogit.go +++ b/modules/git/repo_language_stats_nogogit.go @@ -67,7 +67,16 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err contentBuf := bytes.Buffer{} var content []byte + + // sizes contains the current calculated size of all files by language sizes := make(map[string]int64) + // by default we will only count the sizes of programming languages or markup languages + // unless they are explicitly set using linguist-language + includedLanguage := map[string]bool{} + // or if there's only one language in the repository + firstExcludedLanguage := "" + firstExcludedLanguageSize := int64(0) + for _, f := range entries { select { case <-repo.Ctx.Done(): @@ -107,6 +116,7 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err language = group } + // this language will always be added to the size sizes[language] += f.Size() continue } else if language, has := attrs["gitlab-language"]; has && language != "unspecified" && language != "" { @@ -121,6 +131,7 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err language = group } + // this language will always be added to the size sizes[language] += f.Size() continue } @@ -180,18 +191,24 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err language = group } - sizes[language] += f.Size() + included, checked := includedLanguage[language] + if !checked { + langtype := enry.GetLanguageType(language) + included = langtype == enry.Programming || langtype == enry.Markup + includedLanguage[language] = included + } + if included { + sizes[language] += f.Size() + } else if len(sizes) == 0 && (firstExcludedLanguage == "" || firstExcludedLanguage == language) { + firstExcludedLanguage = language + firstExcludedLanguageSize += f.Size() + } continue } - // filter special languages unless they are the only language - if len(sizes) > 1 { - for language := range sizes { - langtype := enry.GetLanguageType(language) - if langtype != enry.Programming && langtype != enry.Markup { - delete(sizes, language) - } - } + // If there are no included languages add the first excluded language + if len(sizes) == 0 && firstExcludedLanguage != "" { + sizes[firstExcludedLanguage] = firstExcludedLanguageSize } return sizes, nil diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 9c4f4ced12a2..043acb733d52 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -452,6 +452,7 @@ var ( RunUser string IsWindows bool HasRobotsTxt bool + EnableSitemap bool InternalToken string // internal access token ) @@ -1100,6 +1101,7 @@ func loadFromConf(allowEmpty bool, extraConfig string) { ShowFooterBranding = Cfg.Section("other").Key("SHOW_FOOTER_BRANDING").MustBool(false) ShowFooterVersion = Cfg.Section("other").Key("SHOW_FOOTER_VERSION").MustBool(true) ShowFooterTemplateLoadTime = Cfg.Section("other").Key("SHOW_FOOTER_TEMPLATE_LOAD_TIME").MustBool(true) + EnableSitemap = Cfg.Section("other").Key("ENABLE_SITEMAP").MustBool(true) UI.ShowUserEmail = Cfg.Section("ui").Key("SHOW_USER_EMAIL").MustBool(true) UI.DefaultShowFullName = Cfg.Section("ui").Key("DEFAULT_SHOW_FULL_NAME").MustBool(false) diff --git a/modules/system/item_runtime.go b/modules/system/item_runtime.go index ef758a5675e1..e022a0daad84 100644 --- a/modules/system/item_runtime.go +++ b/modules/system/item_runtime.go @@ -6,7 +6,8 @@ package system // RuntimeState contains app state for runtime, and we can save remote version for update checker here in future type RuntimeState struct { - LastAppPath string `json:"last_app_path"` + LastAppPath string `json:"last_app_path"` + LastCustomConf string `json:"last_custom_conf"` } // Name returns the item name diff --git a/options/license/FSFULLRWD b/options/license/FSFULLRWD new file mode 100644 index 000000000000..8dc0b2e5f0fa --- /dev/null +++ b/options/license/FSFULLRWD @@ -0,0 +1,11 @@ +Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002, +2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc. + +This Makefile.in is free software; the Free Software Foundation +gives unlimited permission to copy and/or distribute it, +with or without modifications, as long as this notice is preserved. + +This program is distributed in the hope that it will be useful, +but WITHOUT ANY WARRANTY, to the extent permitted by law; without +even the implied warranty of MERCHANTABILITY or FITNESS FOR A +PARTICULAR PURPOSE. diff --git a/options/license/x11vnc-openssl-exception b/options/license/x11vnc-openssl-exception new file mode 100644 index 000000000000..040e31c7a90c --- /dev/null +++ b/options/license/x11vnc-openssl-exception @@ -0,0 +1,9 @@ +In addition, as a special exception, Karl J. Runge +gives permission to link the code of its release of x11vnc with the +OpenSSL project's "OpenSSL" library (or with modified versions of it +that use the same license as the "OpenSSL" library), and distribute +the linked executables. You must obey the GNU General Public License +in all respects for all of the code used other than "OpenSSL". If you +modify this file, you may extend this exception to your version of the +file, but you are not obligated to do so. If you do not wish to do +so, delete this exception statement from your version. diff --git a/options/locale/locale_zh-CN.ini b/options/locale/locale_zh-CN.ini index 7b9941aff938..6d8f03edf4c1 100644 --- a/options/locale/locale_zh-CN.ini +++ b/options/locale/locale_zh-CN.ini @@ -749,6 +749,7 @@ create_oauth2_application_button=创建应用 create_oauth2_application_success=您已成功创建了一个新的 OAuth2 应用。 update_oauth2_application_success=您已成功更新了此 OAuth2 应用。 oauth2_application_name=应用名称 +oauth2_confidential_client=机密客户端。是否是能够维持凭据机密性的应用,比如网页应用程序。如果是本地应用程序请不要勾选,包括桌面和移动端应用。 oauth2_redirect_uri=重定向 URI save_application=保存 oauth2_client_id=客户端ID diff --git a/routers/init.go b/routers/init.go index 9045437f872b..53b33f468f66 100644 --- a/routers/init.go +++ b/routers/init.go @@ -76,21 +76,31 @@ func InitGitServices() { mustInit(repo_service.Init) } -func syncAppPathForGit(ctx context.Context) error { +func syncAppConfForGit(ctx context.Context) error { runtimeState := new(system.RuntimeState) if err := system.AppState.Get(runtimeState); err != nil { return err } + + updated := false if runtimeState.LastAppPath != setting.AppPath { log.Info("AppPath changed from '%s' to '%s'", runtimeState.LastAppPath, setting.AppPath) + runtimeState.LastAppPath = setting.AppPath + updated = true + } + if runtimeState.LastCustomConf != setting.CustomConf { + log.Info("CustomConf changed from '%s' to '%s'", runtimeState.LastCustomConf, setting.CustomConf) + runtimeState.LastCustomConf = setting.CustomConf + updated = true + } + if updated { log.Info("re-sync repository hooks ...") mustInitCtx(ctx, repo_service.SyncRepositoryHooks) log.Info("re-write ssh public keys ...") mustInit(asymkey_model.RewriteAllPublicKeys) - runtimeState.LastAppPath = setting.AppPath return system.AppState.Set(runtimeState) } return nil @@ -153,7 +163,7 @@ func GlobalInitInstalled(ctx context.Context) { mustInit(repo_migrations.Init) eventsource.GetManager().Init() - mustInitCtx(ctx, syncAppPathForGit) + mustInitCtx(ctx, syncAppConfForGit) mustInit(ssh.Init) diff --git a/routers/web/web.go b/routers/web/web.go index 9b814c3f5424..0b16e756e182 100644 --- a/routers/web/web.go +++ b/routers/web/web.go @@ -296,12 +296,19 @@ func RegisterRoutes(m *web.Route) { } } + sitemapEnabled := func(ctx *context.Context) { + if !setting.EnableSitemap { + ctx.Error(http.StatusNotFound) + return + } + } + // FIXME: not all routes need go through same middleware. // Especially some AJAX requests, we can reduce middleware number to improve performance. // Routers. // for health check m.Get("/", Home) - m.Get("/sitemap.xml", ignExploreSignIn, HomeSitemap) + m.Get("/sitemap.xml", sitemapEnabled, ignExploreSignIn, HomeSitemap) m.Group("/.well-known", func() { m.Get("/openid-configuration", auth.OIDCWellKnown) m.Group("", func() { @@ -318,9 +325,9 @@ func RegisterRoutes(m *web.Route) { ctx.Redirect(setting.AppSubURL + "/explore/repos") }) m.Get("/repos", explore.Repos) - m.Get("/repos/sitemap-{idx}.xml", explore.Repos) + m.Get("/repos/sitemap-{idx}.xml", sitemapEnabled, explore.Repos) m.Get("/users", explore.Users) - m.Get("/users/sitemap-{idx}.xml", explore.Users) + m.Get("/users/sitemap-{idx}.xml", sitemapEnabled, explore.Users) m.Get("/organizations", explore.Organizations) m.Get("/code", explore.Code) m.Get("/topics/search", explore.TopicSearch)