Skip to content

Bindata is optional and over-writable on restart #354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 13 commits into from
Dec 22, 2016
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -28,6 +28,7 @@ _testmain.go

coverage.out

/modules/options/bindata.go
/modules/public/bindata.go
/modules/templates/bindata.go

22 changes: 3 additions & 19 deletions Makefile
Original file line number Diff line number Diff line change
@@ -2,10 +2,7 @@ DIST := dist
EXECUTABLE := gitea
IMPORT := code.gitea.io/gitea

SHA := $(shell git rev-parse --short HEAD)
DATE := $(shell date -u '+%Y-%m-%d %I:%M:%S %Z')

BINDATA := $(shell find conf | sed 's/ /\\ /g')
BINDATA := modules/{options,public,templates}/bindata.go
STYLESHEETS := $(wildcard public/less/index.less public/less/_*.less)
JAVASCRIPTS :=

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

.PHONY: fmt
fmt:
@@ -119,19 +116,6 @@ release-copy:
release-check:
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 [email protected]

.PHONY: javascripts
javascripts: public/js/index.js

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

.PHONY: assets
assets: bindata javascripts stylesheets
assets: javascripts stylesheets
27 changes: 17 additions & 10 deletions cmd/web.go
Original file line number Diff line number Diff line change
@@ -16,9 +16,9 @@ import (

"code.gitea.io/gitea/models"
"code.gitea.io/gitea/modules/auth"
"code.gitea.io/gitea/modules/bindata"
"code.gitea.io/gitea/modules/context"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/options"
"code.gitea.io/gitea/modules/public"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/templates"
@@ -99,22 +99,29 @@ func newMacaron() *macaron.Macaron {
m.Use(templates.Renderer())
models.InitMailRender(templates.Mailer())

localeNames, err := bindata.AssetDir("conf/locale")
localeNames, err := options.Dir("locale")

if err != nil {
log.Fatal(4, "Fail to list locale files: %v", err)
}

localFiles := make(map[string][]byte)

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{
SubURL: setting.AppSubURL,
Files: localFiles,
CustomDirectory: path.Join(setting.CustomPath, "conf/locale"),
Langs: setting.Langs,
Names: setting.Names,
DefaultLang: "en-US",
Redirect: true,
SubURL: setting.AppSubURL,
Files: localFiles,
Langs: setting.Langs,
Names: setting.Names,
DefaultLang: "en-US",
Redirect: true,
}))
m.Use(cache.Cacher(cache.Options{
Adapter: setting.CacheAdapter,
3 changes: 0 additions & 3 deletions conf/README.md

This file was deleted.

3 changes: 0 additions & 3 deletions conf/app.ini
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
# NEVER EVER MODIFY THIS FILE
# PLEASE MAKE CHANGES ON CORRESPONDING CUSTOM CONFIG FILE

; App name that shows on every page title
APP_NAME = Gitea: Git with a cup of tea
; Change it if you run locally
21 changes: 16 additions & 5 deletions models/repo.go
Original file line number Diff line number Diff line change
@@ -20,9 +20,9 @@ import (
"time"

"code.gitea.io/git"
"code.gitea.io/gitea/modules/bindata"
"code.gitea.io/gitea/modules/log"
"code.gitea.io/gitea/modules/markdown"
"code.gitea.io/gitea/modules/options"
"code.gitea.io/gitea/modules/process"
"code.gitea.io/gitea/modules/setting"
"code.gitea.io/gitea/modules/sync"
@@ -80,11 +80,11 @@ func LoadRepoConfig() {
types := []string{"gitignore", "license", "readme", "label"}
typeFiles := make([][]string, 4)
for i, t := range types {
files, err := bindata.AssetDir("conf/" + t)
files, err := options.Dir(t)
if err != nil {
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) {
customFiles, err := com.StatDir(customPath)
if err != nil {
@@ -827,14 +827,25 @@ type CreateRepoOptions struct {
}

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.
customPath := path.Join(setting.CustomPath, relPath)
if com.IsFile(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 {
2 changes: 1 addition & 1 deletion modules/base/tool_test.go
Original file line number Diff line number Diff line change
@@ -25,7 +25,7 @@ const (
func TestMain(m *testing.M) {
// setup
macaroni18n.I18n(macaroni18n.Options{
Directory: "../../conf/locale/",
Directory: "../../options/locale/",
DefaultLang: "en-US",
Langs: []string{"en-US"},
Names: []string{"english"},
Loading