forked from p85947160/gitea
Compare commits
6 Commits
main
...
options-bi
Author | SHA1 | Date |
---|---|---|
![]() |
2a46834168 | |
![]() |
8596ea5519 | |
![]() |
608b1ce642 | |
![]() |
d97b9cf0c2 | |
![]() |
dd5464e1f2 | |
![]() |
c06db22b24 |
|
@ -28,6 +28,7 @@ _testmain.go
|
||||||
|
|
||||||
coverage.out
|
coverage.out
|
||||||
|
|
||||||
|
/modules/options/bindata.go
|
||||||
/modules/public/bindata.go
|
/modules/public/bindata.go
|
||||||
|
|
||||||
*.db
|
*.db
|
||||||
|
|
16
Makefile
16
Makefile
|
@ -5,7 +5,6 @@ IMPORT := code.gitea.io/gitea
|
||||||
SHA := $(shell git rev-parse --short HEAD)
|
SHA := $(shell git rev-parse --short HEAD)
|
||||||
DATE := $(shell date -u '+%Y-%m-%d %I:%M:%S %Z')
|
DATE := $(shell date -u '+%Y-%m-%d %I:%M:%S %Z')
|
||||||
|
|
||||||
BINDATA := $(shell find conf | sed 's/ /\\ /g')
|
|
||||||
STYLESHEETS := $(wildcard public/less/index.less public/less/_*.less)
|
STYLESHEETS := $(wildcard public/less/index.less public/less/_*.less)
|
||||||
JAVASCRIPTS :=
|
JAVASCRIPTS :=
|
||||||
|
|
||||||
|
@ -115,19 +114,6 @@ release-copy:
|
||||||
release-check:
|
release-check:
|
||||||
cd $(DIST)/release; $(foreach file,$(wildcard $(DIST)/release/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
|
cd $(DIST)/release; $(foreach file,$(wildcard $(DIST)/release/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
|
||||||
|
|
||||||
.PHONY: bindata
|
|
||||||
bindata: modules/bindata/bindata.go
|
|
||||||
|
|
||||||
.IGNORE: modules/bindata/bindata.go
|
|
||||||
modules/bindata/bindata.go: $(BINDATA)
|
|
||||||
@which go-bindata > /dev/null; if [ $$? -ne 0 ]; then \
|
|
||||||
go get -u github.com/jteeuwen/go-bindata/...; \
|
|
||||||
fi
|
|
||||||
go-bindata -o=$@ -ignore="\\.go|README.md|TRANSLATORS" -pkg=bindata conf/...
|
|
||||||
go fmt $@
|
|
||||||
sed -i.bak 's/confLocaleLocale_/confLocaleLocale/' $@
|
|
||||||
rm $@.bak
|
|
||||||
|
|
||||||
.PHONY: javascripts
|
.PHONY: javascripts
|
||||||
javascripts: public/js/index.js
|
javascripts: public/js/index.js
|
||||||
|
|
||||||
|
@ -143,4 +129,4 @@ public/css/index.css: $(STYLESHEETS)
|
||||||
lessc $< $@
|
lessc $< $@
|
||||||
|
|
||||||
.PHONY: assets
|
.PHONY: assets
|
||||||
assets: bindata javascripts stylesheets
|
assets: javascripts stylesheets
|
||||||
|
|
27
cmd/web.go
27
cmd/web.go
|
@ -18,9 +18,9 @@ import (
|
||||||
"code.gitea.io/git"
|
"code.gitea.io/git"
|
||||||
"code.gitea.io/gitea/models"
|
"code.gitea.io/gitea/models"
|
||||||
"code.gitea.io/gitea/modules/auth"
|
"code.gitea.io/gitea/modules/auth"
|
||||||
"code.gitea.io/gitea/modules/bindata"
|
|
||||||
"code.gitea.io/gitea/modules/context"
|
"code.gitea.io/gitea/modules/context"
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
|
"code.gitea.io/gitea/modules/options"
|
||||||
"code.gitea.io/gitea/modules/public"
|
"code.gitea.io/gitea/modules/public"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
"code.gitea.io/gitea/modules/template"
|
"code.gitea.io/gitea/modules/template"
|
||||||
|
@ -150,22 +150,29 @@ func newMacaron() *macaron.Macaron {
|
||||||
models.InitMailRender(path.Join(setting.StaticRootPath, "templates/mail"),
|
models.InitMailRender(path.Join(setting.StaticRootPath, "templates/mail"),
|
||||||
path.Join(setting.CustomPath, "templates/mail"), funcMap)
|
path.Join(setting.CustomPath, "templates/mail"), funcMap)
|
||||||
|
|
||||||
localeNames, err := bindata.AssetDir("conf/locale")
|
localeNames, err := options.Dir("locale")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(4, "Fail to list locale files: %v", err)
|
log.Fatal(4, "Fail to list locale files: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
localFiles := make(map[string][]byte)
|
localFiles := make(map[string][]byte)
|
||||||
|
|
||||||
for _, name := range localeNames {
|
for _, name := range localeNames {
|
||||||
localFiles[name] = bindata.MustAsset("conf/locale/" + name)
|
localFiles[name], err = options.Locale(name)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
log.Fatal(4, "Failed to load %s locale file. %v", name, err)
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
m.Use(i18n.I18n(i18n.Options{
|
m.Use(i18n.I18n(i18n.Options{
|
||||||
SubURL: setting.AppSubURL,
|
SubURL: setting.AppSubURL,
|
||||||
Files: localFiles,
|
Files: localFiles,
|
||||||
CustomDirectory: path.Join(setting.CustomPath, "conf/locale"),
|
Langs: setting.Langs,
|
||||||
Langs: setting.Langs,
|
Names: setting.Names,
|
||||||
Names: setting.Names,
|
DefaultLang: "en-US",
|
||||||
DefaultLang: "en-US",
|
Redirect: true,
|
||||||
Redirect: true,
|
|
||||||
}))
|
}))
|
||||||
m.Use(cache.Cacher(cache.Options{
|
m.Use(cache.Cacher(cache.Options{
|
||||||
Adapter: setting.CacheAdapter,
|
Adapter: setting.CacheAdapter,
|
||||||
|
|
|
@ -1,3 +0,0 @@
|
||||||
Execute following command in ROOT directory when anything is changed:
|
|
||||||
|
|
||||||
$ make bindata
|
|
|
@ -20,9 +20,9 @@ import (
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
"code.gitea.io/git"
|
"code.gitea.io/git"
|
||||||
"code.gitea.io/gitea/modules/bindata"
|
|
||||||
"code.gitea.io/gitea/modules/log"
|
"code.gitea.io/gitea/modules/log"
|
||||||
"code.gitea.io/gitea/modules/markdown"
|
"code.gitea.io/gitea/modules/markdown"
|
||||||
|
"code.gitea.io/gitea/modules/options"
|
||||||
"code.gitea.io/gitea/modules/process"
|
"code.gitea.io/gitea/modules/process"
|
||||||
"code.gitea.io/gitea/modules/setting"
|
"code.gitea.io/gitea/modules/setting"
|
||||||
"code.gitea.io/gitea/modules/sync"
|
"code.gitea.io/gitea/modules/sync"
|
||||||
|
@ -80,11 +80,11 @@ func LoadRepoConfig() {
|
||||||
types := []string{"gitignore", "license", "readme", "label"}
|
types := []string{"gitignore", "license", "readme", "label"}
|
||||||
typeFiles := make([][]string, 4)
|
typeFiles := make([][]string, 4)
|
||||||
for i, t := range types {
|
for i, t := range types {
|
||||||
files, err := bindata.AssetDir("conf/" + t)
|
files, err := options.Dir(t)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatal(4, "Fail to get %s files: %v", t, err)
|
log.Fatal(4, "Fail to get %s files: %v", t, err)
|
||||||
}
|
}
|
||||||
customPath := path.Join(setting.CustomPath, "conf", t)
|
customPath := path.Join(setting.CustomPath, "options", t)
|
||||||
if com.IsDir(customPath) {
|
if com.IsDir(customPath) {
|
||||||
customFiles, err := com.StatDir(customPath)
|
customFiles, err := com.StatDir(customPath)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -823,14 +823,25 @@ type CreateRepoOptions struct {
|
||||||
}
|
}
|
||||||
|
|
||||||
func getRepoInitFile(tp, name string) ([]byte, error) {
|
func getRepoInitFile(tp, name string) ([]byte, error) {
|
||||||
relPath := path.Join("conf", tp, strings.TrimLeft(name, "./"))
|
cleanedName := strings.TrimLeft(name, "./")
|
||||||
|
relPath := path.Join("options", tp, cleanedName)
|
||||||
|
|
||||||
// Use custom file when available.
|
// Use custom file when available.
|
||||||
customPath := path.Join(setting.CustomPath, relPath)
|
customPath := path.Join(setting.CustomPath, relPath)
|
||||||
if com.IsFile(customPath) {
|
if com.IsFile(customPath) {
|
||||||
return ioutil.ReadFile(customPath)
|
return ioutil.ReadFile(customPath)
|
||||||
}
|
}
|
||||||
return bindata.Asset(relPath)
|
|
||||||
|
switch tp {
|
||||||
|
case "readme":
|
||||||
|
return options.Readme(cleanedName)
|
||||||
|
case "gitignore":
|
||||||
|
return options.Gitignore(cleanedName)
|
||||||
|
case "license":
|
||||||
|
return options.License(cleanedName)
|
||||||
|
default:
|
||||||
|
return []byte{}, fmt.Errorf("Invalid init file type")
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
func prepareRepoCommit(repo *Repository, tmpDir, repoPath string, opts CreateRepoOptions) error {
|
func prepareRepoCommit(repo *Repository, tmpDir, repoPath string, opts CreateRepoOptions) error {
|
||||||
|
|
File diff suppressed because one or more lines are too long
|
@ -0,0 +1,94 @@
|
||||||
|
// +build !bindata
|
||||||
|
|
||||||
|
// Copyright 2016 The Gitea Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package options
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"path"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
"github.com/Unknwon/com"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
directories = make(directorySet)
|
||||||
|
)
|
||||||
|
|
||||||
|
// Dir returns all files from static or custom directory.
|
||||||
|
func Dir(name string) ([]string, error) {
|
||||||
|
if directories.Filled(name) {
|
||||||
|
return directories.Get(name), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
result []string
|
||||||
|
)
|
||||||
|
|
||||||
|
customDir := path.Join(setting.CustomPath, "options", name)
|
||||||
|
|
||||||
|
if com.IsDir(customDir) {
|
||||||
|
files, err := com.StatDir(customDir, true)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return []string{}, fmt.Errorf("Failed to read custom directory. %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
result = append(result, files...)
|
||||||
|
}
|
||||||
|
|
||||||
|
staticDir := path.Join(setting.StaticRootPath, "options", name)
|
||||||
|
|
||||||
|
if com.IsDir(staticDir) {
|
||||||
|
files, err := com.StatDir(staticDir, true)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return []string{}, fmt.Errorf("Failed to read static directory. %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
result = append(result, files...)
|
||||||
|
}
|
||||||
|
|
||||||
|
return directories.AddAndGet(name, result), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Locale reads the content of a specific locale from static or custom path.
|
||||||
|
func Locale(name string) ([]byte, error) {
|
||||||
|
return fileFromDir(path.Join("locale", name))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Readme reads the content of a specific readme from static or custom path.
|
||||||
|
func Readme(name string) ([]byte, error) {
|
||||||
|
return fileFromDir(path.Join("readme", name))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gitignore reads the content of a specific gitignore from static or custom path.
|
||||||
|
func Gitignore(name string) ([]byte, error) {
|
||||||
|
return fileFromDir(path.Join("gitignore", name))
|
||||||
|
}
|
||||||
|
|
||||||
|
// License reads the content of a specific license from static or custom path.
|
||||||
|
func License(name string) ([]byte, error) {
|
||||||
|
return fileFromDir(path.Join("license", name))
|
||||||
|
}
|
||||||
|
|
||||||
|
// fileFromDir is a helper to read files from static or custom path.
|
||||||
|
func fileFromDir(name string) ([]byte, error) {
|
||||||
|
customPath := path.Join(setting.CustomPath, "options", name)
|
||||||
|
|
||||||
|
if com.IsFile(customPath) {
|
||||||
|
return ioutil.ReadFile(customPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
staticPath := path.Join(setting.StaticRootPath, "options", name)
|
||||||
|
|
||||||
|
if com.IsFile(staticPath) {
|
||||||
|
return ioutil.ReadFile(staticPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
return []byte{}, fmt.Errorf("Asset file does not exist: %s", name)
|
||||||
|
}
|
|
@ -0,0 +1,51 @@
|
||||||
|
// Copyright 2016 The Gitea Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package options
|
||||||
|
|
||||||
|
//go:generate go-bindata -tags "bindata" -ignore "TRANSLATORS" -pkg "options" -o "bindata.go" ../../options/...
|
||||||
|
//go:generate go fmt bindata.go
|
||||||
|
//go:generate sed -i.bak s/..\/..\/options\/// bindata.go
|
||||||
|
//go:generate rm -f bindata.go.bak
|
||||||
|
|
||||||
|
type directorySet map[string][]string
|
||||||
|
|
||||||
|
func (s directorySet) Add(key string, value []string) {
|
||||||
|
_, ok := s[key]
|
||||||
|
|
||||||
|
if !ok {
|
||||||
|
s[key] = make([]string, 0, len(value))
|
||||||
|
}
|
||||||
|
|
||||||
|
s[key] = append(s[key], value...)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s directorySet) Get(key string) []string {
|
||||||
|
_, ok := s[key]
|
||||||
|
|
||||||
|
if ok {
|
||||||
|
result := []string{}
|
||||||
|
seen := map[string]string{}
|
||||||
|
|
||||||
|
for _, val := range s[key] {
|
||||||
|
if _, ok := seen[val]; !ok {
|
||||||
|
result = append(result, val)
|
||||||
|
seen[val] = val
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
return result
|
||||||
|
}
|
||||||
|
|
||||||
|
return []string{}
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s directorySet) AddAndGet(key string, value []string) []string {
|
||||||
|
s.Add(key, value)
|
||||||
|
return s.Get(key)
|
||||||
|
}
|
||||||
|
|
||||||
|
func (s directorySet) Filled(key string) bool {
|
||||||
|
return len(s[key]) > 0
|
||||||
|
}
|
|
@ -0,0 +1,84 @@
|
||||||
|
// +build bindata
|
||||||
|
|
||||||
|
// Copyright 2016 The Gitea Authors. All rights reserved.
|
||||||
|
// Use of this source code is governed by a MIT-style
|
||||||
|
// license that can be found in the LICENSE file.
|
||||||
|
|
||||||
|
package options
|
||||||
|
|
||||||
|
import (
|
||||||
|
"fmt"
|
||||||
|
"io/ioutil"
|
||||||
|
"path"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/modules/setting"
|
||||||
|
"github.com/Unknwon/com"
|
||||||
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
directories = make(directorySet)
|
||||||
|
)
|
||||||
|
|
||||||
|
// Dir returns all files from bindata or custom directory.
|
||||||
|
func Dir(name string) ([]string, error) {
|
||||||
|
if directories.Filled(name) {
|
||||||
|
return directories.Get(name), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
var (
|
||||||
|
result []string
|
||||||
|
)
|
||||||
|
|
||||||
|
customDir := path.Join(setting.CustomPath, "options", name)
|
||||||
|
|
||||||
|
if com.IsDir(customDir) {
|
||||||
|
files, err := com.StatDir(customDir, true)
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return []string{}, fmt.Errorf("Failed to read custom directory. %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
result = append(result, files...)
|
||||||
|
}
|
||||||
|
|
||||||
|
files, err := AssetDir(path.Join("..", "..", "options", name))
|
||||||
|
|
||||||
|
if err != nil {
|
||||||
|
return []string{}, fmt.Errorf("Failed to read embedded directory. %v", err)
|
||||||
|
}
|
||||||
|
|
||||||
|
result = append(result, files...)
|
||||||
|
|
||||||
|
return directories.AddAndGet(name, result), nil
|
||||||
|
}
|
||||||
|
|
||||||
|
// Locale reads the content of a specific locale from bindata or custom path.
|
||||||
|
func Locale(name string) ([]byte, error) {
|
||||||
|
return fileFromDir(path.Join("locale", name))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Readme reads the content of a specific readme from bindata or custom path.
|
||||||
|
func Readme(name string) ([]byte, error) {
|
||||||
|
return fileFromDir(path.Join("readme", name))
|
||||||
|
}
|
||||||
|
|
||||||
|
// Gitignore reads the content of a gitignore locale from bindata or custom path.
|
||||||
|
func Gitignore(name string) ([]byte, error) {
|
||||||
|
return fileFromDir(path.Join("gitignore", name))
|
||||||
|
}
|
||||||
|
|
||||||
|
// License reads the content of a specific license from bindata or custom path.
|
||||||
|
func License(name string) ([]byte, error) {
|
||||||
|
return fileFromDir(path.Join("license", name))
|
||||||
|
}
|
||||||
|
|
||||||
|
// fileFromDir is a helper to read files from bindata or custom path.
|
||||||
|
func fileFromDir(name string) ([]byte, error) {
|
||||||
|
customPath := path.Join(setting.CustomPath, "options", name)
|
||||||
|
|
||||||
|
if com.IsFile(customPath) {
|
||||||
|
return ioutil.ReadFile(customPath)
|
||||||
|
}
|
||||||
|
|
||||||
|
return Asset(name)
|
||||||
|
}
|
|
@ -17,6 +17,8 @@ import (
|
||||||
"strings"
|
"strings"
|
||||||
"time"
|
"time"
|
||||||
|
|
||||||
|
"code.gitea.io/gitea/modules/log"
|
||||||
|
"code.gitea.io/gitea/modules/user"
|
||||||
"github.com/Unknwon/com"
|
"github.com/Unknwon/com"
|
||||||
_ "github.com/go-macaron/cache/memcache" // memcache plugin for cache
|
_ "github.com/go-macaron/cache/memcache" // memcache plugin for cache
|
||||||
_ "github.com/go-macaron/cache/redis"
|
_ "github.com/go-macaron/cache/redis"
|
||||||
|
@ -25,10 +27,6 @@ import (
|
||||||
_ "github.com/kardianos/minwinsvc" // import minwinsvc for windows services
|
_ "github.com/kardianos/minwinsvc" // import minwinsvc for windows services
|
||||||
"gopkg.in/ini.v1"
|
"gopkg.in/ini.v1"
|
||||||
"strk.kbt.io/projects/go/libravatar"
|
"strk.kbt.io/projects/go/libravatar"
|
||||||
|
|
||||||
"code.gitea.io/gitea/modules/bindata"
|
|
||||||
"code.gitea.io/gitea/modules/log"
|
|
||||||
"code.gitea.io/gitea/modules/user"
|
|
||||||
)
|
)
|
||||||
|
|
||||||
// Scheme describes protocol types
|
// Scheme describes protocol types
|
||||||
|
@ -352,10 +350,7 @@ func NewContext() {
|
||||||
log.Fatal(4, "Fail to get work directory: %v", err)
|
log.Fatal(4, "Fail to get work directory: %v", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
Cfg, err = ini.Load(bindata.MustAsset("conf/app.ini"))
|
Cfg = ini.Empty()
|
||||||
if err != nil {
|
|
||||||
log.Fatal(4, "Fail to parse 'conf/app.ini': %v", err)
|
|
||||||
}
|
|
||||||
|
|
||||||
CustomPath = os.Getenv("GITEA_CUSTOM")
|
CustomPath = os.Getenv("GITEA_CUSTOM")
|
||||||
if len(CustomPath) == 0 {
|
if len(CustomPath) == 0 {
|
||||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue