Skip to content

Commit b33078f

Browse files
authored
Bindata is optional and over-writable on restart (#354)
* Moved conf assets into options folder * Dropped old bindata * Started to integrate options bindata and accessors * Do not enforce a builtin app.ini * Replaced bindata calls with options * Dropped bindata task from makefile, it's the generate task now * Always embedd app.ini to provide sane config defaults * Use sane defaults for the configuration * Defined default value for SSH_KEYGEN_PATH * Dropped "NEVER EVER MODIFY THIS FILE" header from app.ini * Fixed new paths in latest test additions * Drop bindata with make clean task * Set more proper default values
1 parent c21e2c4 commit b33078f

File tree

234 files changed

+292
-5404
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

234 files changed

+292
-5404
lines changed

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@ _testmain.go
2828

2929
coverage.out
3030

31+
/modules/options/bindata.go
3132
/modules/public/bindata.go
3233
/modules/templates/bindata.go
3334

Makefile

+3-19
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,7 @@ DIST := dist
22
EXECUTABLE := gitea
33
IMPORT := code.gitea.io/gitea
44

5-
SHA := $(shell git rev-parse --short HEAD)
6-
DATE := $(shell date -u '+%Y-%m-%d %I:%M:%S %Z')
7-
8-
BINDATA := $(shell find conf | sed 's/ /\\ /g')
5+
BINDATA := modules/{options,public,templates}/bindata.go
96
STYLESHEETS := $(wildcard public/less/index.less public/less/_*.less)
107
JAVASCRIPTS :=
118

@@ -33,7 +30,7 @@ all: build
3330
.PHONY: clean
3431
clean:
3532
go clean -i ./...
36-
rm -rf $(EXECUTABLE) $(DIST)
33+
rm -rf $(EXECUTABLE) $(DIST) $(BINDATA)
3734

3835
.PHONY: fmt
3936
fmt:
@@ -119,19 +116,6 @@ release-copy:
119116
release-check:
120117
cd $(DIST)/release; $(foreach file,$(wildcard $(DIST)/release/$(EXECUTABLE)-*),sha256sum $(notdir $(file)) > $(notdir $(file)).sha256;)
121118

122-
.PHONY: bindata
123-
bindata: modules/bindata/bindata.go
124-
125-
.IGNORE: modules/bindata/bindata.go
126-
modules/bindata/bindata.go: $(BINDATA)
127-
@which go-bindata > /dev/null; if [ $$? -ne 0 ]; then \
128-
go get -u github.com/jteeuwen/go-bindata/...; \
129-
fi
130-
go-bindata -o=$@ -ignore="\\.go|README.md|TRANSLATORS" -pkg=bindata conf/...
131-
go fmt $@
132-
sed -i.bak 's/confLocaleLocale_/confLocaleLocale/' $@
133-
rm $@.bak
134-
135119
.PHONY: javascripts
136120
javascripts: public/js/index.js
137121

@@ -147,4 +131,4 @@ public/css/index.css: $(STYLESHEETS)
147131
lessc $< $@
148132

149133
.PHONY: assets
150-
assets: bindata javascripts stylesheets
134+
assets: javascripts stylesheets

cmd/web.go

+17-10
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ import (
1616

1717
"code.gitea.io/gitea/models"
1818
"code.gitea.io/gitea/modules/auth"
19-
"code.gitea.io/gitea/modules/bindata"
2019
"code.gitea.io/gitea/modules/context"
2120
"code.gitea.io/gitea/modules/log"
21+
"code.gitea.io/gitea/modules/options"
2222
"code.gitea.io/gitea/modules/public"
2323
"code.gitea.io/gitea/modules/setting"
2424
"code.gitea.io/gitea/modules/templates"
@@ -99,22 +99,29 @@ func newMacaron() *macaron.Macaron {
9999
m.Use(templates.Renderer())
100100
models.InitMailRender(templates.Mailer())
101101

102-
localeNames, err := bindata.AssetDir("conf/locale")
102+
localeNames, err := options.Dir("locale")
103+
103104
if err != nil {
104105
log.Fatal(4, "Fail to list locale files: %v", err)
105106
}
107+
106108
localFiles := make(map[string][]byte)
109+
107110
for _, name := range localeNames {
108-
localFiles[name] = bindata.MustAsset("conf/locale/" + name)
111+
localFiles[name], err = options.Locale(name)
112+
113+
if err != nil {
114+
log.Fatal(4, "Failed to load %s locale file. %v", name, err)
115+
}
109116
}
117+
110118
m.Use(i18n.I18n(i18n.Options{
111-
SubURL: setting.AppSubURL,
112-
Files: localFiles,
113-
CustomDirectory: path.Join(setting.CustomPath, "conf/locale"),
114-
Langs: setting.Langs,
115-
Names: setting.Names,
116-
DefaultLang: "en-US",
117-
Redirect: true,
119+
SubURL: setting.AppSubURL,
120+
Files: localFiles,
121+
Langs: setting.Langs,
122+
Names: setting.Names,
123+
DefaultLang: "en-US",
124+
Redirect: true,
118125
}))
119126
m.Use(cache.Cacher(cache.Options{
120127
Adapter: setting.CacheAdapter,

conf/README.md

-3
This file was deleted.

conf/app.ini

-3
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,3 @@
1-
# NEVER EVER MODIFY THIS FILE
2-
# PLEASE MAKE CHANGES ON CORRESPONDING CUSTOM CONFIG FILE
3-
41
; App name that shows on every page title
52
APP_NAME = Gitea: Git with a cup of tea
63
; Change it if you run locally

models/repo.go

+16-5
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,9 @@ import (
2020
"time"
2121

2222
"code.gitea.io/git"
23-
"code.gitea.io/gitea/modules/bindata"
2423
"code.gitea.io/gitea/modules/log"
2524
"code.gitea.io/gitea/modules/markdown"
25+
"code.gitea.io/gitea/modules/options"
2626
"code.gitea.io/gitea/modules/process"
2727
"code.gitea.io/gitea/modules/setting"
2828
"code.gitea.io/gitea/modules/sync"
@@ -80,11 +80,11 @@ func LoadRepoConfig() {
8080
types := []string{"gitignore", "license", "readme", "label"}
8181
typeFiles := make([][]string, 4)
8282
for i, t := range types {
83-
files, err := bindata.AssetDir("conf/" + t)
83+
files, err := options.Dir(t)
8484
if err != nil {
8585
log.Fatal(4, "Fail to get %s files: %v", t, err)
8686
}
87-
customPath := path.Join(setting.CustomPath, "conf", t)
87+
customPath := path.Join(setting.CustomPath, "options", t)
8888
if com.IsDir(customPath) {
8989
customFiles, err := com.StatDir(customPath)
9090
if err != nil {
@@ -827,14 +827,25 @@ type CreateRepoOptions struct {
827827
}
828828

829829
func getRepoInitFile(tp, name string) ([]byte, error) {
830-
relPath := path.Join("conf", tp, strings.TrimLeft(name, "./"))
830+
cleanedName := strings.TrimLeft(name, "./")
831+
relPath := path.Join("options", tp, cleanedName)
831832

832833
// Use custom file when available.
833834
customPath := path.Join(setting.CustomPath, relPath)
834835
if com.IsFile(customPath) {
835836
return ioutil.ReadFile(customPath)
836837
}
837-
return bindata.Asset(relPath)
838+
839+
switch tp {
840+
case "readme":
841+
return options.Readme(cleanedName)
842+
case "gitignore":
843+
return options.Gitignore(cleanedName)
844+
case "license":
845+
return options.License(cleanedName)
846+
default:
847+
return []byte{}, fmt.Errorf("Invalid init file type")
848+
}
838849
}
839850

840851
func prepareRepoCommit(repo *Repository, tmpDir, repoPath string, opts CreateRepoOptions) error {

modules/base/tool_test.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ const (
2525
func TestMain(m *testing.M) {
2626
// setup
2727
macaroni18n.I18n(macaroni18n.Options{
28-
Directory: "../../conf/locale/",
28+
Directory: "../../options/locale/",
2929
DefaultLang: "en-US",
3030
Langs: []string{"en-US"},
3131
Names: []string{"english"},

0 commit comments

Comments
 (0)