@@ -10,7 +10,6 @@ import (
1010 "fmt"
1111 "os"
1212 "path"
13- "sort"
1413 "strconv"
1514 "strings"
1615 "unicode/utf8"
@@ -28,7 +27,6 @@ import (
2827 "code.gitea.io/gitea/models/webhook"
2928 "code.gitea.io/gitea/modules/lfs"
3029 "code.gitea.io/gitea/modules/log"
31- "code.gitea.io/gitea/modules/options"
3230 "code.gitea.io/gitea/modules/setting"
3331 "code.gitea.io/gitea/modules/storage"
3432 api "code.gitea.io/gitea/modules/structs"
@@ -37,90 +35,11 @@ import (
3735 "xorm.io/builder"
3836)
3937
40- var (
41- // Gitignores contains the gitiginore files
42- Gitignores []string
43-
44- // Licenses contains the license files
45- Licenses []string
46-
47- // Readmes contains the readme files
48- Readmes []string
49-
50- // LabelTemplates contains the label template files and the list of labels for each file
51- LabelTemplates map [string ]string
52-
53- // ItemsPerPage maximum items per page in forks, watchers and stars of a repo
54- ItemsPerPage = 40
55- )
56-
57- // loadRepoConfig loads the repository config
58- func loadRepoConfig () {
59- // Load .gitignore and license files and readme templates.
60- types := []string {"gitignore" , "license" , "readme" , "label" }
61- typeFiles := make ([][]string , 4 )
62- for i , t := range types {
63- files , err := options .Dir (t )
64- if err != nil {
65- log .Fatal ("Failed to get %s files: %v" , t , err )
66- }
67- customPath := path .Join (setting .CustomPath , "options" , t )
68- isDir , err := util .IsDir (customPath )
69- if err != nil {
70- log .Fatal ("Failed to get custom %s files: %v" , t , err )
71- }
72- if isDir {
73- customFiles , err := util .StatDir (customPath )
74- if err != nil {
75- log .Fatal ("Failed to get custom %s files: %v" , t , err )
76- }
77-
78- for _ , f := range customFiles {
79- if ! util .IsStringInSlice (f , files , true ) {
80- files = append (files , f )
81- }
82- }
83- }
84- typeFiles [i ] = files
85- }
86-
87- Gitignores = typeFiles [0 ]
88- Licenses = typeFiles [1 ]
89- Readmes = typeFiles [2 ]
90- LabelTemplatesFiles := typeFiles [3 ]
91- sort .Strings (Gitignores )
92- sort .Strings (Licenses )
93- sort .Strings (Readmes )
94- sort .Strings (LabelTemplatesFiles )
95-
96- // Load label templates
97- LabelTemplates = make (map [string ]string )
98- for _ , templateFile := range LabelTemplatesFiles {
99- labels , err := LoadLabelsFormatted (templateFile )
100- if err != nil {
101- log .Error ("Failed to load labels: %v" , err )
102- }
103- LabelTemplates [templateFile ] = labels
104- }
105-
106- // Filter out invalid names and promote preferred licenses.
107- sortedLicenses := make ([]string , 0 , len (Licenses ))
108- for _ , name := range setting .Repository .PreferredLicenses {
109- if util .IsStringInSlice (name , Licenses , true ) {
110- sortedLicenses = append (sortedLicenses , name )
111- }
112- }
113- for _ , name := range Licenses {
114- if ! util .IsStringInSlice (name , setting .Repository .PreferredLicenses , true ) {
115- sortedLicenses = append (sortedLicenses , name )
116- }
117- }
118- Licenses = sortedLicenses
119- }
38+ // ItemsPerPage maximum items per page in forks, watchers and stars of a repo
39+ var ItemsPerPage = 40
12040
12141// NewRepoContext creates a new repository context
12242func NewRepoContext () {
123- loadRepoConfig ()
12443 unit .LoadUnitConfig ()
12544
12645 admin_model .RemoveAllWithNotice (db .DefaultContext , "Clean up temporary repository uploads" , setting .Repository .Upload .TempPath )
@@ -441,35 +360,6 @@ type CreateRepoOptions struct {
441360 MirrorInterval string
442361}
443362
444- // GetRepoInitFile returns repository init files
445- func GetRepoInitFile (tp , name string ) ([]byte , error ) {
446- cleanedName := strings .TrimLeft (path .Clean ("/" + name ), "/" )
447- relPath := path .Join ("options" , tp , cleanedName )
448-
449- // Use custom file when available.
450- customPath := path .Join (setting .CustomPath , relPath )
451- isFile , err := util .IsFile (customPath )
452- if err != nil {
453- log .Error ("Unable to check if %s is a file. Error: %v" , customPath , err )
454- }
455- if isFile {
456- return os .ReadFile (customPath )
457- }
458-
459- switch tp {
460- case "readme" :
461- return options .Readme (cleanedName )
462- case "gitignore" :
463- return options .Gitignore (cleanedName )
464- case "license" :
465- return options .License (cleanedName )
466- case "label" :
467- return options .Labels (cleanedName )
468- default :
469- return []byte {}, fmt .Errorf ("Invalid init file type" )
470- }
471- }
472-
473363// CreateRepository creates a repository for the user/organization.
474364func CreateRepository (ctx context.Context , doer , u * user_model.User , repo * repo_model.Repository , overwriteOrAdopt bool ) (err error ) {
475365 if err = repo_model .IsUsableRepoName (repo .Name ); err != nil {
0 commit comments