diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md
index 17a3ebe68f..cfc6c14f21 100644
--- a/CONTRIBUTING.md
+++ b/CONTRIBUTING.md
@@ -2,7 +2,7 @@
> Thanks [drone](https://github.com/drone/drone) because this guidelines sheet is forked from its [CONTRIBUTING.md](https://github.com/drone/drone/blob/master/CONTRIBUTING.md).
-**This document is pre^3 release, we're not ready for receiving contribution until v0.5.0 release.**
+**This document is pre^2 release, we're not ready for receiving contribution until v0.5.0 release.**
Want to hack on Gogs? Awesome! Here are instructions to get you started. They are probably not perfect, please let us know if anything feels wrong or incomplete.
diff --git a/README.md b/README.md
index d30e81356a..dfc2fff5e6 100644
--- a/README.md
+++ b/README.md
@@ -5,7 +5,7 @@ Gogs(Go Git Service) is a Self Hosted Git Service in the Go Programming Language

-##### Current version: 0.2.5 Alpha
+##### Current version: 0.2.6 Alpha
#### 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.
@@ -43,7 +43,7 @@ More importantly, Gogs only needs one binary to setup your own project hosting o
Make sure you install [Prerequirements](https://github.com/gogits/gogs/wiki/Prerequirements) first.
-There are two ways to install Gogs:
+There are 3 ways to install Gogs:
- [Install from binary](https://github.com/gogits/gogs/wiki/Install-from-binary): **STRONGLY RECOMMENDED**
- [Install from source](https://github.com/gogits/gogs/wiki/Install-from-source)
diff --git a/README_ZH.md b/README_ZH.md
index 43303cdf5c..e9aa74adb6 100644
--- a/README_ZH.md
+++ b/README_ZH.md
@@ -5,7 +5,7 @@ Gogs(Go Git Service) 是一个由 Go 语言编写的自助 Git 托管服务。

-##### 当前版本:0.2.5 Alpha
+##### 当前版本:0.2.6 Alpha
## 开发目的
@@ -37,7 +37,7 @@ Gogs 完全使用 Go 语言来实现对 Git 数据的操作,实现 **零** 依
在安装 Gogs 之前,您需要先安装 [基本环境](https://github.com/gogits/gogs/wiki/Prerequirements)。
-然后,您可以通过以下两种方式来安装 Gogs:
+然后,您可以通过以下 3 种方式来安装 Gogs:
- [二进制安装](https://github.com/gogits/gogs/wiki/Install-from-binary): **强烈推荐**
- [源码安装](https://github.com/gogits/gogs/wiki/Install-from-source)
diff --git a/gogs.go b/gogs.go
index d0b0c6ca04..8c96ec90fd 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.5.0410 Alpha"
+const APP_VER = "0.2.6.0411 Alpha"
func init() {
base.AppVer = APP_VER
diff --git a/models/git.go b/models/git.go
index 68e139056a..f20e663b1b 100644
--- a/models/git.go
+++ b/models/git.go
@@ -6,7 +6,9 @@ package models
import (
"bufio"
+ "bytes"
"container/list"
+ "errors"
"fmt"
"io"
"os"
@@ -409,3 +411,85 @@ func GetDiff(repoPath, commitid string) (*Diff, error) {
defer rd.Close()
return ParsePatch(rd)
}
+
+const prettyLogFormat = `--pretty=format:%H%n%an <%ae> %at%n%s`
+
+func parsePrettyFormatLog(logByts []byte) (*list.List, error) {
+ l := list.New()
+ buf := bytes.NewBuffer(logByts)
+ if buf.Len() == 0 {
+ return l, nil
+ }
+
+ idx := 0
+ var commit *git.Commit
+
+ for {
+ line, err := buf.ReadString('\n')
+ if err != nil && err != io.EOF {
+ return nil, err
+ }
+ line = strings.TrimSpace(line)
+ // fmt.Println(line)
+
+ var parseErr error
+ switch idx {
+ case 0: // SHA1.
+ commit = &git.Commit{}
+ commit.Oid, parseErr = git.NewOidFromString(line)
+ case 1: // Signature.
+ commit.Author, parseErr = git.NewSignatureFromCommitline([]byte(line + " "))
+ case 2: // Commit message.
+ commit.CommitMessage = line
+ l.PushBack(commit)
+ idx = -1
+ }
+
+ if parseErr != nil {
+ return nil, parseErr
+ }
+
+ idx++
+
+ if err == io.EOF {
+ break
+ }
+ }
+
+ return l, nil
+}
+
+// SearchCommits searches commits in given branch and keyword of repository.
+func SearchCommits(repoPath, branch, keyword string) (*list.List, error) {
+ stdout, stderr, err := com.ExecCmdDirBytes(repoPath, "git", "log", branch, "-100",
+ "-i", "--grep="+keyword, prettyLogFormat)
+ if err != nil {
+ return nil, err
+ } else if len(stderr) > 0 {
+ return nil, errors.New(string(stderr))
+ }
+ return parsePrettyFormatLog(stdout)
+}
+
+// GetCommitsByRange returns certain number of commits with given page of repository.
+func GetCommitsByRange(repoPath, branch string, page int) (*list.List, error) {
+ stdout, stderr, err := com.ExecCmdDirBytes(repoPath, "git", "log", branch,
+ "--skip="+base.ToStr((page-1)*50), "--max-count=50", prettyLogFormat)
+ if err != nil {
+ return nil, err
+ } else if len(stderr) > 0 {
+ return nil, errors.New(string(stderr))
+ }
+ return parsePrettyFormatLog(stdout)
+}
+
+// GetCommitsCount returns the commits count of given branch of repository.
+func GetCommitsCount(repoPath, branch string) (int, error) {
+ stdout, stderr, err := com.ExecCmdDir(repoPath, "git", "rev-list", "--count", branch)
+ if err != nil {
+ return 0, err
+ } else if len(stderr) > 0 {
+ return 0, errors.New(stderr)
+ }
+ return base.StrTo(strings.TrimSpace(stdout)).Int()
+}
diff --git a/models/models.go b/models/models.go
index ee96207d10..b380d0e0f2 100644
--- a/models/models.go
+++ b/models/models.go
@@ -32,7 +32,7 @@ var (
func init() {
tables = append(tables, new(User), new(PublicKey), new(Repository), new(Watch),
- new(Action), new(Access), new(Issue), new(Comment), new(Oauth2))
+ new(Action), new(Access), new(Issue), new(Comment), new(Oauth2), new(Follow))
}
func LoadModelsConfig() {
diff --git a/models/repo.go b/models/repo.go
index 91dc710281..ce8665cc63 100644
--- a/models/repo.go
+++ b/models/repo.go
@@ -192,12 +192,6 @@ func CreateRepository(user *User, repoName, desc, repoLang, license string, priv
return nil, err
}
- c := exec.Command("git", "update-server-info")
- c.Dir = repoPath
- if err = c.Run(); err != nil {
- log.Error("repo.CreateRepository(exec update-server-info): %v", err)
- }
-
if err = NewRepoAction(user, repo); err != nil {
log.Error("repo.CreateRepository(NewRepoAction): %v", err)
}
@@ -210,6 +204,12 @@ func CreateRepository(user *User, repoName, desc, repoLang, license string, priv
return nil, err
}
+ c := exec.Command("git", "update-server-info")
+ c.Dir = repoPath
+ if err = c.Run(); err != nil {
+ log.Error("repo.CreateRepository(exec update-server-info): %v", err)
+ }
+
return repo, nil
}
diff --git a/models/user.go b/models/user.go
index b2fddd0a1d..5274970fa0 100644
--- a/models/user.go
+++ b/models/user.go
@@ -294,6 +294,8 @@ func DeleteUser(user *User) error {
return err
}
+ // Delete oauth2.
+
// Delete all feeds.
if _, err = orm.Delete(&Action{UserId: user.Id}); err != nil {
return err
diff --git a/routers/api/v1/repositories.go b/routers/api/v1/repositories.go
new file mode 100644
index 0000000000..4d05c1a77a
--- /dev/null
+++ b/routers/api/v1/repositories.go
@@ -0,0 +1,32 @@
+// Copyright 2014 The Gogs Authors. All rights reserved.
+// Use of this source code is governed by a MIT-style
+// license that can be found in the LICENSE file.
+
+package v1
+
+import (
+ "github.com/gogits/gogs/models"
+ "github.com/gogits/gogs/modules/middleware"
+)
+
+func SearchCommits(ctx *middleware.Context) {
+ userName := ctx.Query("username")
+ repoName := ctx.Query("reponame")
+ branch := ctx.Query("branch")
+ keyword := ctx.Query("q")
+ if len(keyword) == 0 {
+ ctx.Render.JSON(404, nil)
+ return
+ }
+
+ commits, err := models.SearchCommits(models.RepoPath(userName, repoName), branch, keyword)
+ if err != nil {
+ ctx.Render.JSON(200, map[string]interface{}{"ok": false})
+ return
+ }
+
+ ctx.Render.JSON(200, map[string]interface{}{
+ "ok": true,
+ "commits": commits,
+ })
+}
diff --git a/routers/repo/commit.go b/routers/repo/commit.go
index d29c40e67e..e6f6d7ed89 100644
--- a/routers/repo/commit.go
+++ b/routers/repo/commit.go
@@ -22,29 +22,53 @@ func Commits(ctx *middleware.Context, params martini.Params) {
brs, err := models.GetBranches(userName, repoName)
if err != nil {
- ctx.Handle(200, "repo.Commits", err)
+ ctx.Handle(500, "repo.Commits", err)
return
} else if len(brs) == 0 {
ctx.Handle(404, "repo.Commits", nil)
return
}
+ repoPath := models.RepoPath(userName, repoName)
+ commitsCount, err := models.GetCommitsCount(repoPath, branchName)
+ if err != nil {
+ ctx.Handle(500, "repo.Commits(GetCommitsCount)", err)
+ return
+ }
+
+ // Calculate and validate page number.
+ page, _ := base.StrTo(ctx.Query("p")).Int()
+ if page < 1 {
+ page = 1
+ }
+ lastPage := page - 1
+ if lastPage < 0 {
+ lastPage = 0
+ }
+ nextPage := page + 1
+ if nextPage*50 > commitsCount {
+ nextPage = 0
+ }
+
var commits *list.List
if models.IsBranchExist(userName, repoName, branchName) {
- commits, err = models.GetCommitsByBranch(userName, repoName, branchName)
+ // commits, err = models.GetCommitsByBranch(userName, repoName, branchName)
+ commits, err = models.GetCommitsByRange(repoPath, branchName, page)
} else {
commits, err = models.GetCommitsByCommitId(userName, repoName, branchName)
}
if err != nil {
- ctx.Handle(404, "repo.Commits", err)
+ ctx.Handle(404, "repo.Commits(get commits)", err)
return
}
ctx.Data["Username"] = userName
ctx.Data["Reponame"] = repoName
- ctx.Data["CommitCount"] = commits.Len()
+ ctx.Data["CommitCount"] = commitsCount
ctx.Data["Commits"] = commits
+ ctx.Data["LastPageNum"] = lastPage
+ ctx.Data["NextPageNum"] = nextPage
ctx.Data["IsRepoToolbarCommits"] = true
ctx.HTML(200, "repo/commits")
}
@@ -90,3 +114,42 @@ func Diff(ctx *middleware.Context, params martini.Params) {
ctx.Data["RawPath"] = "/" + path.Join(userName, repoName, "raw", commitId)
ctx.HTML(200, "repo/diff")
}
+
+func SearchCommits(ctx *middleware.Context, params martini.Params) {
+ keyword := ctx.Query("q")
+ if len(keyword) == 0 {
+ ctx.Redirect(ctx.Repo.RepoLink + "/commits/" + ctx.Repo.BranchName)
+ return
+ }
+
+ userName := params["username"]
+ repoName := params["reponame"]
+ branchName := params["branchname"]
+
+ brs, err := models.GetBranches(userName, repoName)
+ if err != nil {
+ ctx.Handle(500, "repo.SearchCommits(GetBranches)", err)
+ return
+ } else if len(brs) == 0 {
+ ctx.Handle(404, "repo.SearchCommits(GetBranches)", nil)
+ return
+ }
+
+ var commits *list.List
+ if !models.IsBranchExist(userName, repoName, branchName) {
+ ctx.Handle(404, "repo.SearchCommits(IsBranchExist)", err)
+ return
+ } else if commits, err = models.SearchCommits(models.RepoPath(userName, repoName), branchName, keyword); err != nil {
+ ctx.Handle(500, "repo.SearchCommits(SearchCommits)", err)
+ return
+ }
+
+ ctx.Data["Keyword"] = keyword
+ ctx.Data["Username"] = userName
+ ctx.Data["Reponame"] = repoName
+ ctx.Data["CommitCount"] = commits.Len()
+ ctx.Data["Commits"] = commits
+ ctx.Data["IsSearchPage"] = true
+ ctx.Data["IsRepoToolbarCommits"] = true
+ ctx.HTML(200, "repo/commits")
+}
diff --git a/routers/repo/repo.go b/routers/repo/repo.go
index 1ae4a3740a..3859b43e87 100644
--- a/routers/repo/repo.go
+++ b/routers/repo/repo.go
@@ -425,3 +425,7 @@ func Action(ctx *middleware.Context, params martini.Params) {
"ok": true,
})
}
+
+func Import(ctx *middleware.Context, params martini.Params) {
+ ctx.ResponseWriter.Write([]byte("not done yet"))
+}
diff --git a/templates/base/navbar.tmpl b/templates/base/navbar.tmpl
index 8d6ca47e9c..e74fd3160c 100644
--- a/templates/base/navbar.tmpl
+++ b/templates/base/navbar.tmpl
@@ -4,19 +4,19 @@
Dashboard
Help{{if .IsSigned}}
- {{if .Repository}}