This commit is contained in:
Unknown 2014-05-25 20:11:25 -04:00
parent 87854c95a9
commit 688ec6ecbd
37 changed files with 693 additions and 482 deletions

View file

@ -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{

View file

@ -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)

View file

@ -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)

View file

@ -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) {