diff --git a/.gopmfile b/.gopmfile
index d3f0b3ca3..c9fad8a03 100644
--- a/.gopmfile
+++ b/.gopmfile
@@ -7,11 +7,12 @@ github.com/go-martini/martini =
github.com/Unknwon/com =
github.com/Unknwon/cae =
github.com/Unknwon/goconfig =
-github.com/dchest/scrypt =
github.com/nfnt/resize =
github.com/lunny/xorm =
github.com/go-sql-driver/mysql =
github.com/lib/pq =
+github.com/qiniu/log =
+code.google.com/p/goauth2 =
github.com/gogits/logs =
github.com/gogits/binding =
github.com/gogits/git =
@@ -19,7 +20,6 @@ github.com/gogits/gfm =
github.com/gogits/cache =
github.com/gogits/session =
github.com/gogits/webdav =
-code.google.com/p/goauth2 =
[res]
include = templates|public|conf
diff --git a/README.md b/README.md
index ede1894ad..fe15328b1 100644
--- a/README.md
+++ b/README.md
@@ -5,9 +5,9 @@ Gogs(Go Git Service) is a Self Hosted Git Service in the Go Programming Language
![Demo](http://gowalker.org/public/gogs_demo.gif)
-##### Current version: 0.2.1 Alpha
+##### Current version: 0.2.2 Alpha
-#### Due to testing purpose, data of [try.gogits.org](http://try.gogits.org) has been reset in March 29, 2014 and will reset multiple times after. Please do NOT put your important data on the site.
+#### Due to testing purpose, data of [try.gogits.org](http://try.gogits.org) has been reset in April 6, 2014 and will reset multiple times after. Please do NOT put your important data on the site.
#### Other language version
diff --git a/README_ZH.md b/README_ZH.md
index 9b5e46413..015ee0af9 100644
--- a/README_ZH.md
+++ b/README_ZH.md
@@ -5,7 +5,7 @@ Gogs(Go Git Service) 是一个由 Go 语言编写的自助 Git 托管服务。
![Demo](http://gowalker.org/public/gogs_demo.gif)
-##### 当前版本:0.2.1 Alpha
+##### 当前版本:0.2.2 Alpha
## 开发目的
diff --git a/bee.json b/bee.json
index 4f7f7a771..ff120f0c9 100644
--- a/bee.json
+++ b/bee.json
@@ -13,6 +13,8 @@
"others": [
"modules",
"$GOPATH/src/github.com/gogits/binding",
+ "$GOPATH/src/github.com/gogits/webdav",
+ "$GOPATH/src/github.com/gogits/logs",
"$GOPATH/src/github.com/gogits/git",
"$GOPATH/src/github.com/gogits/gfm"
]
diff --git a/conf/app.ini b/conf/app.ini
index f88c750e0..43033eaa6 100644
--- a/conf/app.ini
+++ b/conf/app.ini
@@ -14,7 +14,7 @@ LICENSES = Apache v2 License|GPL v2|MIT License|Affero GPL|Artistic License 2.0|
[server]
PROTOCOL = http
DOMAIN = localhost
-ROOT_URL = %(PROTOCOL)://%(DOMAIN)s:%(HTTP_PORT)s/
+ROOT_URL = %(PROTOCOL)s://%(DOMAIN)s:%(HTTP_PORT)s/
HTTP_ADDR =
HTTP_PORT = 3000
CERT_FILE = cert.pem
diff --git a/gogs.go b/gogs.go
index 13b9d377d..e71974820 100644
--- a/gogs.go
+++ b/gogs.go
@@ -19,7 +19,7 @@ import (
// Test that go1.2 tag above is included in builds. main.go refers to this definition.
const go12tag = true
-const APP_VER = "0.2.1.0405 Alpha"
+const APP_VER = "0.2.2.0406 Alpha"
func init() {
base.AppVer = APP_VER
diff --git a/models/user.go b/models/user.go
index 2196eae84..a5a6de097 100644
--- a/models/user.go
+++ b/models/user.go
@@ -5,6 +5,7 @@
package models
import (
+ "crypto/sha256"
"encoding/hex"
"errors"
"fmt"
@@ -13,8 +14,6 @@ import (
"strings"
"time"
- "github.com/dchest/scrypt"
-
"github.com/gogits/git"
"github.com/gogits/gogs/modules/base"
@@ -62,6 +61,7 @@ type User struct {
IsActive bool
IsAdmin bool
Rands string `xorm:"VARCHAR(10)"`
+ Salt string `xorm:"VARCHAR(10)"`
Created time.Time `xorm:"created"`
Updated time.Time `xorm:"updated"`
}
@@ -89,10 +89,9 @@ func (user *User) NewGitSig() *git.Signature {
}
// EncodePasswd encodes password to safe format.
-func (user *User) EncodePasswd() error {
- newPasswd, err := scrypt.Key([]byte(user.Passwd), []byte(base.SecretKey), 16384, 8, 1, 64)
+func (user *User) EncodePasswd() {
+ newPasswd := base.PBKDF2([]byte(user.Passwd), []byte(user.Salt), 10000, 50, sha256.New)
user.Passwd = fmt.Sprintf("%x", newPasswd)
- return err
}
// Member represents user is member of organization.
@@ -148,9 +147,9 @@ func RegisterUser(user *User) (*User, error) {
user.Avatar = base.EncodeMd5(user.Email)
user.AvatarEmail = user.Email
user.Rands = GetUserSalt()
- if err = user.EncodePasswd(); err != nil {
- return nil, err
- } else if _, err = orm.Insert(user); err != nil {
+ user.Salt = GetUserSalt()
+ user.EncodePasswd()
+ if _, err = orm.Insert(user); err != nil {
return nil, err
} else if err = os.MkdirAll(UserPath(user.Name), os.ModePerm); err != nil {
if _, err := orm.Id(user.Id).Delete(&User{}); err != nil {
@@ -384,18 +383,20 @@ func GetUserByEmail(email string) (*User, error) {
// LoginUserPlain validates user by raw user name and password.
func LoginUserPlain(name, passwd string) (*User, error) {
- user := User{LowerName: strings.ToLower(name), Passwd: passwd}
- if err := user.EncodePasswd(); err != nil {
- return nil, err
- }
-
+ user := User{LowerName: strings.ToLower(name)}
has, err := orm.Get(&user)
if err != nil {
return nil, err
} else if !has {
- err = ErrUserNotExist
+ return nil, ErrUserNotExist
+ }
+
+ newUser := &User{Passwd: passwd, Salt: user.Salt}
+ newUser.EncodePasswd()
+ if user.Passwd != newUser.Passwd {
+ return nil, ErrUserNotExist
}
- return &user, err
+ return &user, nil
}
// Follow is connection request for receiving user notifycation.
diff --git a/modules/base/conf.go b/modules/base/conf.go
index 3ebc4ede1..0a618ab1d 100644
--- a/modules/base/conf.go
+++ b/modules/base/conf.go
@@ -14,6 +14,7 @@ import (
"github.com/Unknwon/com"
"github.com/Unknwon/goconfig"
+ qlog "github.com/qiniu/log"
"github.com/gogits/cache"
"github.com/gogits/session"
@@ -105,16 +106,14 @@ func newLogService() {
LogMode = Cfg.MustValue("log", "MODE", "console")
modeSec := "log." + LogMode
if _, err := Cfg.GetSection(modeSec); err != nil {
- fmt.Printf("Unknown log mode: %s\n", LogMode)
- os.Exit(2)
+ qlog.Fatalf("Unknown log mode: %s\n", LogMode)
}
// Log level.
levelName := Cfg.MustValue("log."+LogMode, "LEVEL", "Trace")
level, ok := logLevels[levelName]
if !ok {
- fmt.Printf("Unknown log level: %s\n", levelName)
- os.Exit(2)
+ qlog.Fatalf("Unknown log level: %s\n", levelName)
}
// Generate log configuration.
@@ -151,6 +150,7 @@ func newLogService() {
Cfg.MustValue(modeSec, "CONN"))
}
+ log.Info("%s %s", AppName, AppVer)
log.NewLogger(Cfg.MustInt64("log", "BUFFER_LEN", 10000), LogMode, LogConfig)
log.Info("Log Mode: %s(%s)", strings.Title(LogMode), levelName)
}
@@ -164,16 +164,14 @@ func newCacheService() {
case "redis", "memcache":
CacheConfig = fmt.Sprintf(`{"conn":"%s"}`, Cfg.MustValue("cache", "HOST"))
default:
- fmt.Printf("Unknown cache adapter: %s\n", CacheAdapter)
- os.Exit(2)
+ qlog.Fatalf("Unknown cache adapter: %s\n", CacheAdapter)
}
var err error
Cache, err = cache.NewCache(CacheAdapter, CacheConfig)
if err != nil {
- fmt.Printf("Init cache system failed, adapter: %s, config: %s, %v\n",
+ qlog.Fatalf("Init cache system failed, adapter: %s, config: %s, %v\n",
CacheAdapter, CacheConfig, err)
- os.Exit(2)
}
log.Info("Cache Service Enabled")
@@ -199,9 +197,8 @@ func newSessionService() {
var err error
SessionManager, err = session.NewManager(SessionProvider, *SessionConfig)
if err != nil {
- fmt.Printf("Init session system failed, provider: %s, %v\n",
+ qlog.Fatalf("Init session system failed, provider: %s, %v\n",
SessionProvider, err)
- os.Exit(2)
}
log.Info("Session Service Enabled")
@@ -246,23 +243,20 @@ func NewConfigContext() {
//var err error
workDir, err := ExecDir()
if err != nil {
- fmt.Printf("Fail to get work directory: %s\n", err)
- os.Exit(2)
+ qlog.Fatalf("Fail to get work directory: %s\n", err)
}
cfgPath := filepath.Join(workDir, "conf/app.ini")
Cfg, err = goconfig.LoadConfigFile(cfgPath)
if err != nil {
- fmt.Printf("Cannot load config file(%s): %v\n", cfgPath, err)
- os.Exit(2)
+ qlog.Fatalf("Cannot load config file(%s): %v\n", cfgPath, err)
}
Cfg.BlockMode = false
cfgPath = filepath.Join(workDir, "custom/conf/app.ini")
if com.IsFile(cfgPath) {
if err = Cfg.AppendFiles(cfgPath); err != nil {
- fmt.Printf("Cannot load config file(%s): %v\n", cfgPath, err)
- os.Exit(2)
+ qlog.Fatalf("Cannot load config file(%s): %v\n", cfgPath, err)
}
}
@@ -281,8 +275,7 @@ func NewConfigContext() {
}
// Does not check run user when the install lock is off.
if InstallLock && RunUser != curUser {
- fmt.Printf("Expect user(%s) but current user is: %s\n", RunUser, curUser)
- os.Exit(2)
+ qlog.Fatalf("Expect user(%s) but current user is: %s\n", RunUser, curUser)
}
LogInRememberDays = Cfg.MustInt("security", "LOGIN_REMEMBER_DAYS")
@@ -294,13 +287,11 @@ func NewConfigContext() {
// Determine and create root git reposiroty path.
homeDir, err := com.HomeDir()
if err != nil {
- fmt.Printf("Fail to get home directory): %v\n", err)
- os.Exit(2)
+ qlog.Fatalf("Fail to get home directory): %v\n", err)
}
- RepoRootPath = Cfg.MustValue("repository", "ROOT", filepath.Join(homeDir, "git/gogs-repositories"))
+ RepoRootPath = Cfg.MustValue("repository", "ROOT", filepath.Join(homeDir, "gogs-repositories"))
if err = os.MkdirAll(RepoRootPath, os.ModePerm); err != nil {
- fmt.Printf("Fail to create RepoRootPath(%s): %v\n", RepoRootPath, err)
- os.Exit(2)
+ qlog.Fatalf("Fail to create RepoRootPath(%s): %v\n", RepoRootPath, err)
}
}
diff --git a/modules/base/markdown.go b/modules/base/markdown.go
index 962e1ae1e..f0992d04d 100644
--- a/modules/base/markdown.go
+++ b/modules/base/markdown.go
@@ -6,9 +6,11 @@ package base
import (
"bytes"
+ "fmt"
"net/http"
"path"
"path/filepath"
+ "regexp"
"strings"
"github.com/gogits/gfm"
@@ -87,7 +89,53 @@ func (options *CustomRender) Link(out *bytes.Buffer, link []byte, title []byte,
options.Renderer.Link(out, link, title, content)
}
+var (
+ mentionPattern = regexp.MustCompile(`@[0-9a-zA-Z_]{1,}`)
+ commitPattern = regexp.MustCompile(`(\s|^)https?.*commit/[0-9a-zA-Z]+(#+[0-9a-zA-Z-]*)?`)
+ issueFullPattern = regexp.MustCompile(`(\s|^)https?.*issues/[0-9]+(#+[0-9a-zA-Z-]*)?`)
+ issueIndexPattern = regexp.MustCompile(`(\s|^)#[0-9]+`)
+)
+
+func RenderSpecialLink(rawBytes []byte, urlPrefix string) []byte {
+ ms := mentionPattern.FindAll(rawBytes, -1)
+ for _, m := range ms {
+ rawBytes = bytes.Replace(rawBytes, m,
+ []byte(fmt.Sprintf(`%s`, m[1:], m)), -1)
+ }
+ ms = commitPattern.FindAll(rawBytes, -1)
+ for _, m := range ms {
+ m = bytes.TrimPrefix(m, []byte(" "))
+ i := strings.Index(string(m), "commit/")
+ j := strings.Index(string(m), "#")
+ if j == -1 {
+ j = len(m)
+ }
+ rawBytes = bytes.Replace(rawBytes, m, []byte(fmt.Sprintf(
+ ` %s
`, m, ShortSha(string(m[i+7:j])))), -1)
+ }
+ ms = issueFullPattern.FindAll(rawBytes, -1)
+ for _, m := range ms {
+ m = bytes.TrimPrefix(m, []byte(" "))
+ i := strings.Index(string(m), "issues/")
+ j := strings.Index(string(m), "#")
+ if j == -1 {
+ j = len(m)
+ }
+ rawBytes = bytes.Replace(rawBytes, m, []byte(fmt.Sprintf(
+ ` #%s`, m, ShortSha(string(m[i+7:j])))), -1)
+ }
+ ms = issueIndexPattern.FindAll(rawBytes, -1)
+ for _, m := range ms {
+ m = bytes.TrimPrefix(m, []byte(" "))
+ rawBytes = bytes.Replace(rawBytes, m, []byte(fmt.Sprintf(
+ ` %s`, urlPrefix, m[1:], m)), -1)
+ }
+ return rawBytes
+}
+
func RenderMarkdown(rawBytes []byte, urlPrefix string) []byte {
+ body := RenderSpecialLink(rawBytes, urlPrefix)
+ fmt.Println(string(body))
htmlFlags := 0
// htmlFlags |= gfm.HTML_USE_XHTML
// htmlFlags |= gfm.HTML_USE_SMARTYPANTS
@@ -99,10 +147,10 @@ func RenderMarkdown(rawBytes []byte, urlPrefix string) []byte {
htmlFlags |= gfm.HTML_GITHUB_BLOCKCODE
htmlFlags |= gfm.HTML_OMIT_CONTENTS
// htmlFlags |= gfm.HTML_COMPLETE_PAGE
- renderer := &CustomRender{
- Renderer: gfm.HtmlRenderer(htmlFlags, "", ""),
- urlPrefix: urlPrefix,
- }
+ // renderer := &CustomRender{
+ // Renderer: gfm.HtmlRenderer(htmlFlags, "", ""),
+ // urlPrefix: urlPrefix,
+ // }
// set up the parser
extensions := 0
@@ -115,7 +163,7 @@ func RenderMarkdown(rawBytes []byte, urlPrefix string) []byte {
extensions |= gfm.EXTENSION_SPACE_HEADERS
extensions |= gfm.EXTENSION_NO_EMPTY_LINE_BEFORE_BLOCK
- body := gfm.Markdown(rawBytes, renderer, extensions)
-
+ // body = gfm.Markdown(body, renderer, extensions)
+ // fmt.Println(string(body))
return body
}
diff --git a/modules/base/template.go b/modules/base/template.go
index 56b77a5d6..6cd8ade61 100644
--- a/modules/base/template.go
+++ b/modules/base/template.go
@@ -5,7 +5,9 @@
package base
import (
+ "bytes"
"container/list"
+ "encoding/json"
"fmt"
"html/template"
"strings"
@@ -85,3 +87,107 @@ var TemplateFuncs template.FuncMap = map[string]interface{}{
"DiffLineTypeToStr": DiffLineTypeToStr,
"ShortSha": ShortSha,
}
+
+type Actioner interface {
+ GetOpType() int
+ GetActUserName() string
+ GetActEmail() string
+ GetRepoName() string
+ GetBranch() string
+ GetContent() string
+}
+
+// ActionIcon accepts a int that represents action operation type
+// and returns a icon class name.
+func ActionIcon(opType int) string {
+ switch opType {
+ case 1: // Create repository.
+ return "plus-circle"
+ case 5: // Commit repository.
+ return "arrow-circle-o-right"
+ case 6: // Create issue.
+ return "exclamation-circle"
+ case 8: // Transfer repository.
+ return "share"
+ default:
+ return "invalid type"
+ }
+}
+
+const (
+ TPL_CREATE_REPO = `%s created repository %s`
+ TPL_COMMIT_REPO = `%s pushed to %s at %s%s`
+ TPL_COMMIT_REPO_LI = `
%s
to %s`
+)
+
+type PushCommit struct {
+ Sha1 string
+ Message string
+ AuthorEmail string
+ AuthorName string
+}
+
+type PushCommits struct {
+ Len int
+ Commits []*PushCommit
+}
+
+// ActionDesc accepts int that represents action operation type
+// and returns the description.
+func ActionDesc(act Actioner) string {
+ actUserName := act.GetActUserName()
+ email := act.GetActEmail()
+ repoName := act.GetRepoName()
+ repoLink := actUserName + "/" + repoName
+ branch := act.GetBranch()
+ content := act.GetContent()
+ switch act.GetOpType() {
+ case 1: // Create repository.
+ return fmt.Sprintf(TPL_CREATE_REPO, actUserName, actUserName, repoLink, repoName)
+ case 5: // Commit repository.
+ var push *PushCommits
+ if err := json.Unmarshal([]byte(content), &push); err != nil {
+ return err.Error()
+ }
+ buf := bytes.NewBuffer([]byte("\n"))
+ for _, commit := range push.Commits {
+ buf.WriteString(fmt.Sprintf(TPL_COMMIT_REPO_LI, AvatarLink(commit.AuthorEmail), repoLink, commit.Sha1, commit.Sha1[:7], commit.Message) + "\n")
+ }
+ if push.Len > 3 {
+ buf.WriteString(fmt.Sprintf(``, actUserName, repoName, branch, push.Len))
+ }
+ return fmt.Sprintf(TPL_COMMIT_REPO, actUserName, actUserName, repoLink, branch, branch, repoLink, repoLink,
+ buf.String())
+ case 6: // Create issue.
+ infos := strings.SplitN(content, "|", 2)
+ return fmt.Sprintf(TPL_CREATE_ISSUE, actUserName, actUserName, repoLink, infos[0], repoLink, infos[0],
+ AvatarLink(email), infos[1])
+ case 8: // Transfer repository.
+ newRepoLink := content + "/" + repoName
+ return fmt.Sprintf(TPL_TRANSFER_REPO, actUserName, actUserName, repoLink, newRepoLink, newRepoLink)
+ default:
+ return "invalid type"
+ }
+}
+
+func DiffTypeToStr(diffType int) string {
+ diffTypes := map[int]string{
+ 1: "add", 2: "modify", 3: "del",
+ }
+ return diffTypes[diffType]
+}
+
+func DiffLineTypeToStr(diffType int) string {
+ switch diffType {
+ case 2:
+ return "add"
+ case 3:
+ return "del"
+ case 4:
+ return "tag"
+ }
+ return "same"
+}
diff --git a/modules/base/tool.go b/modules/base/tool.go
index 3946c4b56..0f06b3e0e 100644
--- a/modules/base/tool.go
+++ b/modules/base/tool.go
@@ -5,13 +5,13 @@
package base
import (
- "bytes"
+ "crypto/hmac"
"crypto/md5"
"crypto/rand"
"crypto/sha1"
"encoding/hex"
- "encoding/json"
"fmt"
+ "hash"
"math"
"strconv"
"strings"
@@ -40,6 +40,44 @@ func GetRandomString(n int, alphabets ...byte) string {
return string(bytes)
}
+// http://code.google.com/p/go/source/browse/pbkdf2/pbkdf2.go?repo=crypto
+func PBKDF2(password, salt []byte, iter, keyLen int, h func() hash.Hash) []byte {
+ prf := hmac.New(h, password)
+ hashLen := prf.Size()
+ numBlocks := (keyLen + hashLen - 1) / hashLen
+
+ var buf [4]byte
+ dk := make([]byte, 0, numBlocks*hashLen)
+ U := make([]byte, hashLen)
+ for block := 1; block <= numBlocks; block++ {
+ // N.B.: || means concatenation, ^ means XOR
+ // for each block T_i = U_1 ^ U_2 ^ ... ^ U_iter
+ // U_1 = PRF(password, salt || uint(i))
+ prf.Reset()
+ prf.Write(salt)
+ buf[0] = byte(block >> 24)
+ buf[1] = byte(block >> 16)
+ buf[2] = byte(block >> 8)
+ buf[3] = byte(block)
+ prf.Write(buf[:4])
+ dk = prf.Sum(dk)
+ T := dk[len(dk)-hashLen:]
+ copy(U, T)
+
+ // U_n = PRF(password, U_(n-1))
+ for n := 2; n <= iter; n++ {
+ prf.Reset()
+ prf.Write(U)
+ U = U[:0]
+ U = prf.Sum(U)
+ for x := range U {
+ T[x] ^= U[x]
+ }
+ }
+ }
+ return dk[:keyLen]
+}
+
// verify time limit code
func VerifyTimeLimitCode(data string, minutes int, code string) bool {
if len(code) <= 18 {
@@ -474,107 +512,3 @@ func (a argInt) Get(i int, args ...int) (r int) {
}
return
}
-
-type Actioner interface {
- GetOpType() int
- GetActUserName() string
- GetActEmail() string
- GetRepoName() string
- GetBranch() string
- GetContent() string
-}
-
-// ActionIcon accepts a int that represents action operation type
-// and returns a icon class name.
-func ActionIcon(opType int) string {
- switch opType {
- case 1: // Create repository.
- return "plus-circle"
- case 5: // Commit repository.
- return "arrow-circle-o-right"
- case 6: // Create issue.
- return "exclamation-circle"
- case 8: // Transfer repository.
- return "share"
- default:
- return "invalid type"
- }
-}
-
-const (
- TPL_CREATE_REPO = `%s created repository %s`
- TPL_COMMIT_REPO = `%s pushed to %s at %s%s`
- TPL_COMMIT_REPO_LI = `%s
to %s`
-)
-
-type PushCommit struct {
- Sha1 string
- Message string
- AuthorEmail string
- AuthorName string
-}
-
-type PushCommits struct {
- Len int
- Commits []*PushCommit
-}
-
-// ActionDesc accepts int that represents action operation type
-// and returns the description.
-func ActionDesc(act Actioner) string {
- actUserName := act.GetActUserName()
- email := act.GetActEmail()
- repoName := act.GetRepoName()
- repoLink := actUserName + "/" + repoName
- branch := act.GetBranch()
- content := act.GetContent()
- switch act.GetOpType() {
- case 1: // Create repository.
- return fmt.Sprintf(TPL_CREATE_REPO, actUserName, actUserName, repoLink, repoName)
- case 5: // Commit repository.
- var push *PushCommits
- if err := json.Unmarshal([]byte(content), &push); err != nil {
- return err.Error()
- }
- buf := bytes.NewBuffer([]byte("\n"))
- for _, commit := range push.Commits {
- buf.WriteString(fmt.Sprintf(TPL_COMMIT_REPO_LI, AvatarLink(commit.AuthorEmail), repoLink, commit.Sha1, commit.Sha1[:7], commit.Message) + "\n")
- }
- if push.Len > 3 {
- buf.WriteString(fmt.Sprintf(``, actUserName, repoName, branch, push.Len))
- }
- return fmt.Sprintf(TPL_COMMIT_REPO, actUserName, actUserName, repoLink, branch, branch, repoLink, repoLink,
- buf.String())
- case 6: // Create issue.
- infos := strings.SplitN(content, "|", 2)
- return fmt.Sprintf(TPL_CREATE_ISSUE, actUserName, actUserName, repoLink, infos[0], repoLink, infos[0],
- AvatarLink(email), infos[1])
- case 8: // Transfer repository.
- newRepoLink := content + "/" + repoName
- return fmt.Sprintf(TPL_TRANSFER_REPO, actUserName, actUserName, repoLink, newRepoLink, newRepoLink)
- default:
- return "invalid type"
- }
-}
-
-func DiffTypeToStr(diffType int) string {
- diffTypes := map[int]string{
- 1: "add", 2: "modify", 3: "del",
- }
- return diffTypes[diffType]
-}
-
-func DiffLineTypeToStr(diffType int) string {
- switch diffType {
- case 2:
- return "add"
- case 3:
- return "del"
- case 4:
- return "tag"
- }
- return "same"
-}
diff --git a/modules/log/log.go b/modules/log/log.go
index 65150237d..f21897b90 100644
--- a/modules/log/log.go
+++ b/modules/log/log.go
@@ -21,8 +21,6 @@ func init() {
func NewLogger(bufLen int64, mode, config string) {
Mode, Config = mode, config
logger = logs.NewLogger(bufLen)
- logger.EnableFuncCallDepth(true)
- logger.SetLogFuncCallDepth(4)
logger.SetLogger(mode, config)
}
diff --git a/routers/api/v1/miscellaneous.go b/routers/api/v1/miscellaneous.go
index 0ff1eb04a..babdfce9b 100644
--- a/routers/api/v1/miscellaneous.go
+++ b/routers/api/v1/miscellaneous.go
@@ -13,6 +13,6 @@ func Markdown(ctx *middleware.Context) {
content := ctx.Query("content")
ctx.Render.JSON(200, map[string]interface{}{
"ok": true,
- "content": string(base.RenderMarkdown([]byte(content), "")),
+ "content": string(base.RenderMarkdown([]byte(content), ctx.Query("repoLink"))),
})
}
diff --git a/routers/install.go b/routers/install.go
index 48c1b5e13..1c4e6181d 100644
--- a/routers/install.go
+++ b/routers/install.go
@@ -6,13 +6,13 @@ package routers
import (
"errors"
- "fmt"
"os"
"strings"
"github.com/Unknwon/goconfig"
"github.com/go-martini/martini"
"github.com/lunny/xorm"
+ qlog "github.com/qiniu/log"
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/auth"
@@ -43,8 +43,7 @@ func GlobalInit() {
if base.InstallLock {
if err := models.NewEngine(); err != nil {
- fmt.Println(err)
- os.Exit(2)
+ qlog.Fatal(err)
}
models.HasEngine = true
diff --git a/routers/repo/issue.go b/routers/repo/issue.go
index be9254264..38522e0c7 100644
--- a/routers/repo/issue.go
+++ b/routers/repo/issue.go
@@ -147,7 +147,7 @@ func ViewIssue(ctx *middleware.Context, params martini.Params) {
return
}
issue.Poster = u
- issue.RenderedContent = string(base.RenderMarkdown([]byte(issue.Content), ""))
+ issue.RenderedContent = string(base.RenderMarkdown([]byte(issue.Content), ctx.Repo.RepoLink))
// Get comments.
comments, err := models.GetIssueComments(issue.Id)
@@ -164,7 +164,7 @@ func ViewIssue(ctx *middleware.Context, params martini.Params) {
return
}
comments[i].Poster = u
- comments[i].Content = string(base.RenderMarkdown([]byte(comments[i].Content), ""))
+ comments[i].Content = string(base.RenderMarkdown([]byte(comments[i].Content), ctx.Repo.RepoLink))
}
ctx.Data["Title"] = issue.Name
@@ -193,7 +193,7 @@ func UpdateIssue(ctx *middleware.Context, params martini.Params, form auth.Creat
return
}
- if ctx.User.Id != issue.PosterId {
+ if ctx.User.Id != issue.PosterId && !ctx.Repo.IsOwner {
ctx.Handle(404, "issue.UpdateIssue", nil)
return
}
@@ -211,7 +211,7 @@ func UpdateIssue(ctx *middleware.Context, params martini.Params, form auth.Creat
ctx.JSON(200, map[string]interface{}{
"ok": true,
"title": issue.Name,
- "content": string(base.RenderMarkdown([]byte(issue.Content), "")),
+ "content": string(base.RenderMarkdown([]byte(issue.Content), ctx.Repo.RepoLink)),
})
}
diff --git a/routers/user/setting.go b/routers/user/setting.go
index 4b6d88a36..ea779e854 100644
--- a/routers/user/setting.go
+++ b/routers/user/setting.go
@@ -73,11 +73,7 @@ func SettingPassword(ctx *middleware.Context, form auth.UpdatePasswdForm) {
user := ctx.User
newUser := &models.User{Passwd: form.NewPasswd}
- if err := newUser.EncodePasswd(); err != nil {
- ctx.Handle(200, "setting.SettingPassword", err)
- return
- }
-
+ newUser.EncodePasswd()
if user.Passwd != newUser.Passwd {
ctx.Data["HasError"] = true
ctx.Data["ErrorMsg"] = "Old password is not correct"
@@ -85,6 +81,7 @@ func SettingPassword(ctx *middleware.Context, form auth.UpdatePasswdForm) {
ctx.Data["HasError"] = true
ctx.Data["ErrorMsg"] = "New password and re-type password are not same"
} else {
+ newUser.Salt = models.GetUserSalt()
user.Passwd = newUser.Passwd
if err := models.UpdateUser(user); err != nil {
ctx.Handle(200, "setting.SettingPassword", err)
diff --git a/routers/user/user.go b/routers/user/user.go
index 872ed0d60..12f2bd8c5 100644
--- a/routers/user/user.go
+++ b/routers/user/user.go
@@ -477,12 +477,9 @@ func ResetPasswd(ctx *middleware.Context) {
}
u.Passwd = passwd
- if err := u.EncodePasswd(); err != nil {
- ctx.Handle(404, "user.ResetPasswd(EncodePasswd)", err)
- return
- }
-
u.Rands = models.GetUserSalt()
+ u.Salt = models.GetUserSalt()
+ u.EncodePasswd()
if err := models.UpdateUser(u); err != nil {
ctx.Handle(404, "user.ResetPasswd(UpdateUser)", err)
return
diff --git a/serve.go b/serve.go
index afc16c281..7e00db473 100644
--- a/serve.go
+++ b/serve.go
@@ -14,7 +14,7 @@ import (
"strings"
"github.com/codegangsta/cli"
- "github.com/gogits/gogs/modules/log"
+ qlog "github.com/qiniu/log"
//"github.com/gogits/git"
"github.com/gogits/gogs/models"
@@ -44,11 +44,16 @@ gogs serv provide access auth for repositories`,
}
func newLogger(execDir string) {
- level := "0"
logPath := execDir + "/log/serv.log"
os.MkdirAll(path.Dir(logPath), os.ModePerm)
- log.NewLogger(0, "file", fmt.Sprintf(`{"level":%s,"filename":"%s"}`, level, logPath))
- log.Trace("start logging...")
+
+ f, err := os.OpenFile(logPath, os.O_WRONLY|os.O_APPEND|os.O_CREATE, os.ModePerm)
+ if err != nil {
+ qlog.Fatal(err)
+ }
+
+ qlog.SetOutput(f)
+ qlog.Info("Start logging serv...")
}
func parseCmd(cmd string) (string, string) {
@@ -87,21 +92,18 @@ func runServ(k *cli.Context) {
keys := strings.Split(os.Args[2], "-")
if len(keys) != 2 {
println("auth file format error")
- log.Error("auth file format error")
- return
+ qlog.Fatal("auth file format error")
}
keyId, err := strconv.ParseInt(keys[1], 10, 64)
if err != nil {
println("auth file format error")
- log.Error("auth file format error", err)
- return
+ qlog.Fatal("auth file format error", err)
}
user, err := models.GetUserByKeyId(keyId)
if err != nil {
println("You have no right to access")
- log.Error("SSH visit error: %v", err)
- return
+ qlog.Fatalf("SSH visit error: %v", err)
}
cmd := os.Getenv("SSH_ORIGINAL_COMMAND")
@@ -115,8 +117,7 @@ func runServ(k *cli.Context) {
rr := strings.SplitN(repoPath, "/", 2)
if len(rr) != 2 {
println("Unavilable repository", args)
- log.Error("Unavilable repository %v", args)
- return
+ qlog.Fatalf("Unavilable repository %v", args)
}
repoUserName := rr[0]
repoName := rr[1]
@@ -129,9 +130,8 @@ func runServ(k *cli.Context) {
repoUser, err := models.GetUserByName(repoUserName)
if err != nil {
- fmt.Println("You have no right to access")
- log.Error("Get user failed", err)
- return
+ println("You have no right to access")
+ qlog.Fatal("Get user failed", err)
}
// access check
@@ -140,19 +140,16 @@ func runServ(k *cli.Context) {
has, err := models.HasAccess(user.LowerName, path.Join(repoUserName, repoName), models.AU_WRITABLE)
if err != nil {
println("Inernel error:", err)
- log.Error(err.Error())
- return
+ qlog.Fatal(err)
} else if !has {
println("You have no right to write this repository")
- log.Error("User %s has no right to write repository %s", user.Name, repoPath)
- return
+ qlog.Fatalf("User %s has no right to write repository %s", user.Name, repoPath)
}
case isRead:
repo, err := models.GetRepositoryByName(repoUser.Id, repoName)
if err != nil {
println("Get repository error:", err)
- log.Error("Get repository error: " + err.Error())
- return
+ qlog.Fatal("Get repository error: " + err.Error())
}
if !repo.IsPrivate {
@@ -162,26 +159,22 @@ func runServ(k *cli.Context) {
has, err := models.HasAccess(user.Name, repoPath, models.AU_READABLE)
if err != nil {
println("Inernel error")
- log.Error(err.Error())
- return
+ qlog.Fatal(err)
}
if !has {
has, err = models.HasAccess(user.Name, repoPath, models.AU_WRITABLE)
if err != nil {
println("Inernel error")
- log.Error(err.Error())
- return
+ qlog.Fatal(err)
}
}
if !has {
println("You have no right to access this repository")
- log.Error("You have no right to access this repository")
- return
+ qlog.Fatal("You have no right to access this repository")
}
default:
println("Unknown command")
- log.Error("Unknown command")
- return
+ qlog.Fatal("Unknown command")
}
// for update use
@@ -197,7 +190,6 @@ func runServ(k *cli.Context) {
if err = gitcmd.Run(); err != nil {
println("execute command error:", err.Error())
- log.Error("execute command error: " + err.Error())
- return
+ qlog.Fatal("execute command error: " + err.Error())
}
}
diff --git a/templates/issue/view.tmpl b/templates/issue/view.tmpl
index e619451cc..16d60d358 100644
--- a/templates/issue/view.tmpl
+++ b/templates/issue/view.tmpl
@@ -72,7 +72,7 @@