Skip to content

Commit

Permalink
Merge remote-tracking branch 'giteaofficial/main'
Browse files Browse the repository at this point in the history
* giteaofficial/main:
  [skip ci] Updated licenses and gitignores
  Keep languages defined in .gitattributes (go-gitea#21403)
  [skip ci] Updated translations via Crowdin
  Sync git hooks when config file path changed (go-gitea#21619)
  Allow disable sitemap (go-gitea#21617)
  • Loading branch information
zjjhot committed Oct 30, 2022
2 parents a4797b4 + d33b2d4 commit c79db93
Show file tree
Hide file tree
Showing 11 changed files with 102 additions and 27 deletions.
3 changes: 2 additions & 1 deletion custom/conf/app.example.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
Expand Down
1 change: 1 addition & 0 deletions docs/content/doc/advanced/config-cheat-sheet.en-us.md
Original file line number Diff line number Diff line change
Expand Up @@ -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.
35 changes: 25 additions & 10 deletions modules/git/repo_language_stats_gogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand All @@ -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
}
Expand Down Expand Up @@ -124,22 +133,28 @@ 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
})
if err != nil {
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
Expand Down
35 changes: 26 additions & 9 deletions modules/git/repo_language_stats_nogogit.go
Original file line number Diff line number Diff line change
Expand Up @@ -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():
Expand Down Expand Up @@ -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 != "" {
Expand All @@ -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
}
Expand Down Expand Up @@ -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
Expand Down
2 changes: 2 additions & 0 deletions modules/setting/setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -452,6 +452,7 @@ var (
RunUser string
IsWindows bool
HasRobotsTxt bool
EnableSitemap bool
InternalToken string // internal access token
)

Expand Down Expand Up @@ -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)
Expand Down
3 changes: 2 additions & 1 deletion modules/system/item_runtime.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
11 changes: 11 additions & 0 deletions options/license/FSFULLRWD
Original file line number Diff line number Diff line change
@@ -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.
9 changes: 9 additions & 0 deletions options/license/x11vnc-openssl-exception
Original file line number Diff line number Diff line change
@@ -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.
1 change: 1 addition & 0 deletions options/locale/locale_zh-CN.ini
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
16 changes: 13 additions & 3 deletions routers/init.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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)

Expand Down
13 changes: 10 additions & 3 deletions routers/web/web.go
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand All @@ -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)
Expand Down

0 comments on commit c79db93

Please sign in to comment.