summaryrefslogtreecommitdiffstats
path: root/models
diff options
context:
space:
mode:
authorUnknown <joe2010xtmf@163.com>2014-05-25 20:11:25 -0400
committerUnknown <joe2010xtmf@163.com>2014-05-25 20:11:25 -0400
commit688ec6ecbdf0e1c450aa93fdc4d760c4ae63a73f (patch)
tree8adb59c369d1fe1bd41ae7be38785dc613a29a91 /models
parent87854c95a90cf1bebe1bffb833389471fb35f234 (diff)
downloadgitea-688ec6ecbdf0e1c450aa93fdc4d760c4ae63a73f.tar.gz
gitea-688ec6ecbdf0e1c450aa93fdc4d760c4ae63a73f.zip
Fixed #209
Diffstat (limited to 'models')
-rw-r--r--models/action.go3
-rw-r--r--models/models.go20
-rw-r--r--models/repo.go36
-rw-r--r--models/user.go9
4 files changed, 37 insertions, 31 deletions
diff --git a/models/action.go b/models/action.go
index 62cff86277..9fc9d89b9f 100644
--- a/models/action.go
+++ b/models/action.go
@@ -17,6 +17,7 @@ import (
"github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/hooks"
"github.com/gogits/gogs/modules/log"
+ "github.com/gogits/gogs/modules/setting"
)
// Operation types of user action.
@@ -129,7 +130,7 @@ func CommitRepoAction(userId, repoUserId int64, userName, actEmail string,
return nil
}
- repoLink := fmt.Sprintf("%s%s/%s", base.AppUrl, repoUserName, repoName)
+ repoLink := fmt.Sprintf("%s%s/%s", setting.AppUrl, repoUserName, repoName)
commits := make([]*hooks.PayloadCommit, len(commit.Commits))
for i, cmt := range commit.Commits {
commits[i] = &hooks.PayloadCommit{
diff --git a/models/models.go b/models/models.go
index 841b10639d..c9fb0a4cbf 100644
--- a/models/models.go
+++ b/models/models.go
@@ -14,7 +14,7 @@ import (
"github.com/go-xorm/xorm"
_ "github.com/lib/pq"
- "github.com/gogits/gogs/modules/base"
+ "github.com/gogits/gogs/modules/setting"
)
var (
@@ -39,16 +39,16 @@ func init() {
}
func LoadModelsConfig() {
- DbCfg.Type = base.Cfg.MustValue("database", "DB_TYPE")
+ DbCfg.Type = setting.Cfg.MustValue("database", "DB_TYPE")
if DbCfg.Type == "sqlite3" {
UseSQLite3 = true
}
- DbCfg.Host = base.Cfg.MustValue("database", "HOST")
- DbCfg.Name = base.Cfg.MustValue("database", "NAME")
- DbCfg.User = base.Cfg.MustValue("database", "USER")
- DbCfg.Pwd = base.Cfg.MustValue("database", "PASSWD")
- DbCfg.SslMode = base.Cfg.MustValue("database", "SSL_MODE")
- DbCfg.Path = base.Cfg.MustValue("database", "PATH", "data/gogs.db")
+ DbCfg.Host = setting.Cfg.MustValue("database", "HOST")
+ DbCfg.Name = setting.Cfg.MustValue("database", "NAME")
+ DbCfg.User = setting.Cfg.MustValue("database", "USER")
+ DbCfg.Pwd = setting.Cfg.MustValue("database", "PASSWD")
+ DbCfg.SslMode = setting.Cfg.MustValue("database", "SSL_MODE")
+ DbCfg.Path = setting.Cfg.MustValue("database", "PATH", "data/gogs.db")
}
func NewTestEngine(x *xorm.Engine) (err error) {
@@ -112,8 +112,8 @@ func SetEngine() (err error) {
// WARNNING: for serv command, MUST remove the output to os.stdout,
// so use log file to instead print to stdout.
- execDir, _ := base.ExecDir()
- logPath := execDir + "/log/xorm.log"
+ workDir, _ := setting.WorkDir()
+ logPath := workDir + "/log/xorm.log"
os.MkdirAll(path.Dir(logPath), os.ModePerm)
f, err := os.Create(logPath)
diff --git a/models/repo.go b/models/repo.go
index fe4b39c244..5ab7d76a87 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -23,7 +23,9 @@ import (
"github.com/gogits/git"
"github.com/gogits/gogs/modules/base"
+ "github.com/gogits/gogs/modules/bin"
"github.com/gogits/gogs/modules/log"
+ "github.com/gogits/gogs/modules/setting"
)
var (
@@ -39,26 +41,28 @@ var (
LanguageIgns, Licenses []string
)
-func LoadRepoConfig() {
- workDir, err := base.ExecDir()
- if err != nil {
- qlog.Fatalf("Fail to get work directory: %s\n", err)
+// getAssetList returns corresponding asset list in 'conf'.
+func getAssetList(prefix string) []string {
+ assets := make([]string, 0, 15)
+ for _, name := range bin.AssetNames() {
+ if strings.HasPrefix(name, prefix) {
+ assets = append(assets, name)
+ }
}
+ return assets
+}
+func LoadRepoConfig() {
// Load .gitignore and license files.
types := []string{"gitignore", "license"}
typeFiles := make([][]string, 2)
for i, t := range types {
- cfgPath := filepath.Join(workDir, "conf", t)
- files, err := com.StatDir(cfgPath)
- if err != nil {
- qlog.Fatalf("Fail to get default %s files: %v\n", t, err)
- }
- cfgPath = filepath.Join(workDir, "custom/conf/gitignore")
- if com.IsDir(cfgPath) {
- customFiles, err := com.StatDir(cfgPath)
+ files := getAssetList(path.Join("conf", t))
+ customPath := path.Join(setting.CustomPath, "conf", t)
+ if com.IsDir(customPath) {
+ customFiles, err := com.StatDir(customPath)
if err != nil {
- qlog.Fatalf("Fail to get custom %s files: %v\n", t, err)
+ log.Fatal("Fail to get custom %s files: %v", t, err)
}
for _, f := range customFiles {
@@ -192,7 +196,7 @@ func MirrorUpdate() {
return nil
}
- repoPath := filepath.Join(base.RepoRootPath, m.RepoName+".git")
+ repoPath := filepath.Join(setting.RepoRootPath, m.RepoName+".git")
_, stderr, err := com.ExecCmdDir(repoPath, "git", "remote", "update")
if err != nil {
return errors.New("git remote update: " + stderr)
@@ -434,7 +438,7 @@ func initRepository(f string, user *User, repo *Repository, initReadme bool, rep
rp := strings.NewReplacer("\\", "/", " ", "\\ ")
// hook/post-update
if err := createHookUpdate(filepath.Join(repoPath, "hooks", "update"),
- fmt.Sprintf("#!/usr/bin/env %s\n%s update $1 $2 $3\n", base.ScriptType,
+ fmt.Sprintf("#!/usr/bin/env %s\n%s update $1 $2 $3\n", setting.ScriptType,
rp.Replace(appPath))); err != nil {
return err
}
@@ -452,7 +456,7 @@ func initRepository(f string, user *User, repo *Repository, initReadme bool, rep
}
// Clone to temprory path and do the init commit.
- tmpDir := filepath.Join(os.TempDir(), fmt.Sprintf("%d", time.Now().Nanosecond()))
+ tmpDir := filepath.Join(os.TempDir(), base.ToStr(time.Now().Nanosecond()))
os.MkdirAll(tmpDir, os.ModePerm)
_, stderr, err := com.ExecCmd("git", "clone", repoPath, tmpDir)
diff --git a/models/user.go b/models/user.go
index 1a2f3a5eb3..dd70a35f0b 100644
--- a/models/user.go
+++ b/models/user.go
@@ -18,6 +18,7 @@ import (
"github.com/gogits/gogs/modules/base"
"github.com/gogits/gogs/modules/log"
+ "github.com/gogits/gogs/modules/setting"
)
// User types.
@@ -73,9 +74,9 @@ func (user *User) HomeLink() string {
// AvatarLink returns the user gravatar link.
func (user *User) AvatarLink() string {
- if base.DisableGravatar {
+ if setting.DisableGravatar {
return "/img/avatar_default.jpg"
- } else if base.Service.EnableCacheAvatar {
+ } else if setting.Service.EnableCacheAvatar {
return "/avatar/" + user.Avatar
}
return "//1.gravatar.com/avatar/" + user.Avatar
@@ -197,7 +198,7 @@ func getVerifyUser(code string) (user *User) {
// verify active code when active account
func VerifyUserActiveCode(code string) (user *User) {
- minutes := base.Service.ActiveCodeLives
+ minutes := setting.Service.ActiveCodeLives
if user = getVerifyUser(code); user != nil {
// time limit code
@@ -340,7 +341,7 @@ func DeleteUser(user *User) error {
// UserPath returns the path absolute path of user repositories.
func UserPath(userName string) string {
- return filepath.Join(base.RepoRootPath, strings.ToLower(userName))
+ return filepath.Join(setting.RepoRootPath, strings.ToLower(userName))
}
func GetUserByKeyId(keyId int64) (*User, error) {