Skip to content

Commit c79db93

Browse files
committed
Merge remote-tracking branch 'giteaofficial/main'
* 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)
2 parents a4797b4 + d33b2d4 commit c79db93

File tree

11 files changed

+102
-27
lines changed

11 files changed

+102
-27
lines changed

custom/conf/app.example.ini

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2196,7 +2196,8 @@ ROUTER = console
21962196
;SHOW_FOOTER_VERSION = true
21972197
;; Show template execution time in the footer
21982198
;SHOW_FOOTER_TEMPLATE_LOAD_TIME = true
2199-
2199+
;; Generate sitemap. Defaults to `true`.
2200+
; ENABLE_SITEMAP = true
22002201

22012202
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
22022203
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

docs/content/doc/advanced/config-cheat-sheet.en-us.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1233,3 +1233,4 @@ PROXY_HOSTS = *.github.com
12331233
- `SHOW_FOOTER_BRANDING`: **false**: Show Gitea branding in the footer.
12341234
- `SHOW_FOOTER_VERSION`: **true**: Show Gitea and Go version information in the footer.
12351235
- `SHOW_FOOTER_TEMPLATE_LOAD_TIME`: **true**: Show time of template execution in the footer.
1236+
- `ENABLE_SITEMAP`: **true**: Generate sitemap.

modules/git/repo_language_stats_gogit.go

Lines changed: 25 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,15 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
4444
checker, deferable := repo.CheckAttributeReader(commitID)
4545
defer deferable()
4646

47+
// sizes contains the current calculated size of all files by language
4748
sizes := make(map[string]int64)
49+
// by default we will only count the sizes of programming languages or markup languages
50+
// unless they are explicitly set using linguist-language
51+
includedLanguage := map[string]bool{}
52+
// or if there's only one language in the repository
53+
firstExcludedLanguage := ""
54+
firstExcludedLanguageSize := int64(0)
55+
4856
err = tree.Files().ForEach(func(f *object.File) error {
4957
if f.Size == 0 {
5058
return nil
@@ -75,8 +83,8 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
7583
language = group
7684
}
7785

86+
// this language will always be added to the size
7887
sizes[language] += f.Size
79-
8088
return nil
8189
} else if language, has := attrs["gitlab-language"]; has && language != "unspecified" && language != "" {
8290
// strip off a ? if present
@@ -90,6 +98,7 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
9098
language = group
9199
}
92100

101+
// this language will always be added to the size
93102
sizes[language] += f.Size
94103
return nil
95104
}
@@ -124,22 +133,28 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
124133
language = group
125134
}
126135

127-
sizes[language] += f.Size
136+
included, checked := includedLanguage[language]
137+
if !checked {
138+
langtype := enry.GetLanguageType(language)
139+
included = langtype == enry.Programming || langtype == enry.Markup
140+
includedLanguage[language] = included
141+
}
142+
if included {
143+
sizes[language] += f.Size
144+
} else if len(sizes) == 0 && (firstExcludedLanguage == "" || firstExcludedLanguage == language) {
145+
firstExcludedLanguage = language
146+
firstExcludedLanguageSize += f.Size
147+
}
128148

129149
return nil
130150
})
131151
if err != nil {
132152
return nil, err
133153
}
134154

135-
// filter special languages unless they are the only language
136-
if len(sizes) > 1 {
137-
for language := range sizes {
138-
langtype := enry.GetLanguageType(language)
139-
if langtype != enry.Programming && langtype != enry.Markup {
140-
delete(sizes, language)
141-
}
142-
}
155+
// If there are no included languages add the first excluded language
156+
if len(sizes) == 0 && firstExcludedLanguage != "" {
157+
sizes[firstExcludedLanguage] = firstExcludedLanguageSize
143158
}
144159

145160
return sizes, nil

modules/git/repo_language_stats_nogogit.go

Lines changed: 26 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -67,7 +67,16 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
6767

6868
contentBuf := bytes.Buffer{}
6969
var content []byte
70+
71+
// sizes contains the current calculated size of all files by language
7072
sizes := make(map[string]int64)
73+
// by default we will only count the sizes of programming languages or markup languages
74+
// unless they are explicitly set using linguist-language
75+
includedLanguage := map[string]bool{}
76+
// or if there's only one language in the repository
77+
firstExcludedLanguage := ""
78+
firstExcludedLanguageSize := int64(0)
79+
7180
for _, f := range entries {
7281
select {
7382
case <-repo.Ctx.Done():
@@ -107,6 +116,7 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
107116
language = group
108117
}
109118

119+
// this language will always be added to the size
110120
sizes[language] += f.Size()
111121
continue
112122
} 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
121131
language = group
122132
}
123133

134+
// this language will always be added to the size
124135
sizes[language] += f.Size()
125136
continue
126137
}
@@ -180,18 +191,24 @@ func (repo *Repository) GetLanguageStats(commitID string) (map[string]int64, err
180191
language = group
181192
}
182193

183-
sizes[language] += f.Size()
194+
included, checked := includedLanguage[language]
195+
if !checked {
196+
langtype := enry.GetLanguageType(language)
197+
included = langtype == enry.Programming || langtype == enry.Markup
198+
includedLanguage[language] = included
199+
}
200+
if included {
201+
sizes[language] += f.Size()
202+
} else if len(sizes) == 0 && (firstExcludedLanguage == "" || firstExcludedLanguage == language) {
203+
firstExcludedLanguage = language
204+
firstExcludedLanguageSize += f.Size()
205+
}
184206
continue
185207
}
186208

187-
// filter special languages unless they are the only language
188-
if len(sizes) > 1 {
189-
for language := range sizes {
190-
langtype := enry.GetLanguageType(language)
191-
if langtype != enry.Programming && langtype != enry.Markup {
192-
delete(sizes, language)
193-
}
194-
}
209+
// If there are no included languages add the first excluded language
210+
if len(sizes) == 0 && firstExcludedLanguage != "" {
211+
sizes[firstExcludedLanguage] = firstExcludedLanguageSize
195212
}
196213

197214
return sizes, nil

modules/setting/setting.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -452,6 +452,7 @@ var (
452452
RunUser string
453453
IsWindows bool
454454
HasRobotsTxt bool
455+
EnableSitemap bool
455456
InternalToken string // internal access token
456457
)
457458

@@ -1100,6 +1101,7 @@ func loadFromConf(allowEmpty bool, extraConfig string) {
11001101
ShowFooterBranding = Cfg.Section("other").Key("SHOW_FOOTER_BRANDING").MustBool(false)
11011102
ShowFooterVersion = Cfg.Section("other").Key("SHOW_FOOTER_VERSION").MustBool(true)
11021103
ShowFooterTemplateLoadTime = Cfg.Section("other").Key("SHOW_FOOTER_TEMPLATE_LOAD_TIME").MustBool(true)
1104+
EnableSitemap = Cfg.Section("other").Key("ENABLE_SITEMAP").MustBool(true)
11031105

11041106
UI.ShowUserEmail = Cfg.Section("ui").Key("SHOW_USER_EMAIL").MustBool(true)
11051107
UI.DefaultShowFullName = Cfg.Section("ui").Key("DEFAULT_SHOW_FULL_NAME").MustBool(false)

modules/system/item_runtime.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ package system
66

77
// RuntimeState contains app state for runtime, and we can save remote version for update checker here in future
88
type RuntimeState struct {
9-
LastAppPath string `json:"last_app_path"`
9+
LastAppPath string `json:"last_app_path"`
10+
LastCustomConf string `json:"last_custom_conf"`
1011
}
1112

1213
// Name returns the item name

options/license/FSFULLRWD

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
Copyright (C) 1994, 1995, 1996, 1997, 1998, 1999, 2000, 2001, 2002,
2+
2003, 2004, 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
3+
4+
This Makefile.in is free software; the Free Software Foundation
5+
gives unlimited permission to copy and/or distribute it,
6+
with or without modifications, as long as this notice is preserved.
7+
8+
This program is distributed in the hope that it will be useful,
9+
but WITHOUT ANY WARRANTY, to the extent permitted by law; without
10+
even the implied warranty of MERCHANTABILITY or FITNESS FOR A
11+
PARTICULAR PURPOSE.
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
In addition, as a special exception, Karl J. Runge
2+
gives permission to link the code of its release of x11vnc with the
3+
OpenSSL project's "OpenSSL" library (or with modified versions of it
4+
that use the same license as the "OpenSSL" library), and distribute
5+
the linked executables. You must obey the GNU General Public License
6+
in all respects for all of the code used other than "OpenSSL". If you
7+
modify this file, you may extend this exception to your version of the
8+
file, but you are not obligated to do so. If you do not wish to do
9+
so, delete this exception statement from your version.

options/locale/locale_zh-CN.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,7 @@ create_oauth2_application_button=创建应用
749749
create_oauth2_application_success=您已成功创建了一个新的 OAuth2 应用。
750750
update_oauth2_application_success=您已成功更新了此 OAuth2 应用。
751751
oauth2_application_name=应用名称
752+
oauth2_confidential_client=机密客户端。是否是能够维持凭据机密性的应用,比如网页应用程序。如果是本地应用程序请不要勾选,包括桌面和移动端应用。
752753
oauth2_redirect_uri=重定向 URI
753754
save_application=保存
754755
oauth2_client_id=客户端ID

routers/init.go

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -76,21 +76,31 @@ func InitGitServices() {
7676
mustInit(repo_service.Init)
7777
}
7878

79-
func syncAppPathForGit(ctx context.Context) error {
79+
func syncAppConfForGit(ctx context.Context) error {
8080
runtimeState := new(system.RuntimeState)
8181
if err := system.AppState.Get(runtimeState); err != nil {
8282
return err
8383
}
84+
85+
updated := false
8486
if runtimeState.LastAppPath != setting.AppPath {
8587
log.Info("AppPath changed from '%s' to '%s'", runtimeState.LastAppPath, setting.AppPath)
88+
runtimeState.LastAppPath = setting.AppPath
89+
updated = true
90+
}
91+
if runtimeState.LastCustomConf != setting.CustomConf {
92+
log.Info("CustomConf changed from '%s' to '%s'", runtimeState.LastCustomConf, setting.CustomConf)
93+
runtimeState.LastCustomConf = setting.CustomConf
94+
updated = true
95+
}
8696

97+
if updated {
8798
log.Info("re-sync repository hooks ...")
8899
mustInitCtx(ctx, repo_service.SyncRepositoryHooks)
89100

90101
log.Info("re-write ssh public keys ...")
91102
mustInit(asymkey_model.RewriteAllPublicKeys)
92103

93-
runtimeState.LastAppPath = setting.AppPath
94104
return system.AppState.Set(runtimeState)
95105
}
96106
return nil
@@ -153,7 +163,7 @@ func GlobalInitInstalled(ctx context.Context) {
153163
mustInit(repo_migrations.Init)
154164
eventsource.GetManager().Init()
155165

156-
mustInitCtx(ctx, syncAppPathForGit)
166+
mustInitCtx(ctx, syncAppConfForGit)
157167

158168
mustInit(ssh.Init)
159169

routers/web/web.go

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -296,12 +296,19 @@ func RegisterRoutes(m *web.Route) {
296296
}
297297
}
298298

299+
sitemapEnabled := func(ctx *context.Context) {
300+
if !setting.EnableSitemap {
301+
ctx.Error(http.StatusNotFound)
302+
return
303+
}
304+
}
305+
299306
// FIXME: not all routes need go through same middleware.
300307
// Especially some AJAX requests, we can reduce middleware number to improve performance.
301308
// Routers.
302309
// for health check
303310
m.Get("/", Home)
304-
m.Get("/sitemap.xml", ignExploreSignIn, HomeSitemap)
311+
m.Get("/sitemap.xml", sitemapEnabled, ignExploreSignIn, HomeSitemap)
305312
m.Group("/.well-known", func() {
306313
m.Get("/openid-configuration", auth.OIDCWellKnown)
307314
m.Group("", func() {
@@ -318,9 +325,9 @@ func RegisterRoutes(m *web.Route) {
318325
ctx.Redirect(setting.AppSubURL + "/explore/repos")
319326
})
320327
m.Get("/repos", explore.Repos)
321-
m.Get("/repos/sitemap-{idx}.xml", explore.Repos)
328+
m.Get("/repos/sitemap-{idx}.xml", sitemapEnabled, explore.Repos)
322329
m.Get("/users", explore.Users)
323-
m.Get("/users/sitemap-{idx}.xml", explore.Users)
330+
m.Get("/users/sitemap-{idx}.xml", sitemapEnabled, explore.Users)
324331
m.Get("/organizations", explore.Organizations)
325332
m.Get("/code", explore.Code)
326333
m.Get("/topics/search", explore.TopicSearch)

0 commit comments

Comments
 (0)