summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorskyblue <ssx205@gmail.com>2014-04-12 09:42:15 +0800
committerskyblue <ssx205@gmail.com>2014-04-12 09:42:15 +0800
commitf8e97b75fbe7201830413fabead33967fb690827 (patch)
tree5a1234fdbc527799913c4eaf691f97769dc2fe8b
parent5c1312f38e8968e068125a1b1dd59060f3f29bfe (diff)
parentd6dac160dfcac068b31bda9316ddc3d4919e3288 (diff)
downloadgitea-f8e97b75fbe7201830413fabead33967fb690827.tar.gz
gitea-f8e97b75fbe7201830413fabead33967fb690827.zip
Merge branch 'dev' of github.com:gogits/gogs into dev
-rw-r--r--CONTRIBUTING.md2
-rw-r--r--README.md4
-rw-r--r--README_ZH.md4
-rw-r--r--gogs.go2
-rw-r--r--models/git.go84
-rw-r--r--models/models.go2
-rw-r--r--models/repo.go12
-rw-r--r--models/user.go2
-rw-r--r--routers/api/v1/repositories.go32
-rw-r--r--routers/repo/commit.go71
-rw-r--r--routers/repo/repo.go4
-rw-r--r--templates/base/navbar.tmpl12
-rw-r--r--templates/repo/commits.tmpl25
-rw-r--r--templates/repo/single_bare.tmpl2
-rw-r--r--templates/user/dashboard.tmpl2
-rw-r--r--web.go2
16 files changed, 222 insertions, 40 deletions
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
![Demo](http://gowalker.org/public/gogs_demo.gif)
-##### 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 托管服务。
![Demo](http://gowalker.org/public/gogs_demo.gif)
-##### 当前版本: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 @@
<a id="nav-logo" class="nav-item pull-left{{if .PageIsHome}} active{{end}}" href="/"><img src="/img/favicon.png" alt="Gogs Logo" id="logo"></a>
<a class="nav-item pull-left{{if .PageIsUserDashboard}} active{{end}}" href="/">Dashboard</a>
<a class="nav-item pull-left{{if .PageIsHelp}} active{{end}}" href="https://github.com/gogits/gogs/wiki">Help</a>{{if .IsSigned}}
- {{if .Repository}}<form class="nav-item pull-left{{if .PageIsNewRepo}} active{{end}}" id="nav-search-form">
+ <form class="nav-item pull-left{{if .PageIsNewRepo}} active{{end}}" id="nav-search-form">
<div class="input-group">
<div class="input-group-btn">
- <button type="button" class="btn btn-sm btn-default dropdown-toggle" data-toggle="dropdown">All Repositories <span class="caret"></span></button>
+ <button type="button" class="btn btn-sm btn-default dropdown-toggle" data-toggle="dropdown">{{if .Repository}}This Repository{{else}}All Repositories{{end}} <span class="caret"></span></button>
<ul class="dropdown-menu">
+ {{if .Repository}}<li><a href="#">This Repository</a></li>
+ <li class="divider"></li>{{end}}
<li><a href="#">All Repositories</a></li>
- <li class="divider"></li>
- <li><a href="#">This Repository</a></li>
</ul>
</div>
<input type="search" class="form-control input-sm" name="q" placeholder="search code, commits and issues"/>
</div>
- </form>{{end}}
+ </form>
<a id="nav-out" class="nav-item navbar-right navbar-btn btn btn-danger" href="/user/logout/"><i class="fa fa-power-off fa-lg"></i></a>
<a id="nav-avatar" class="nav-item navbar-right{{if .PageIsUserProfile}} active{{end}}" href="{{.SignedUser.HomeLink}}" data-toggle="tooltip" data-placement="bottom" title="{{.SignedUserName}}">
<img src="{{.SignedUser.AvatarLink}}?s=28" alt="user-avatar" title="username"/>
@@ -29,7 +29,7 @@
<ul class="list-unstyled">
<li><a href="/repo/create"><i class="fa fa-book"></i>Repository</a></li>
<li><a href="/repo/mirror"><i class="fa fa-clipboard"></i>Mirror</a></li>
- <li><a href="#"><i class="fa fa-users"></i>Organization</a></li>
+ <!-- <li><a href="#"><i class="fa fa-users"></i>Organization</a></li> -->
</ul>
</div>
</div>
diff --git a/templates/repo/commits.tmpl b/templates/repo/commits.tmpl
index 842a2a6d8f..68b1403589 100644
--- a/templates/repo/commits.tmpl
+++ b/templates/repo/commits.tmpl
@@ -6,11 +6,11 @@
<div id="commits">
<div class="panel panel-default commit-box info-box">
<div class="panel-heading info-head">
- <form class="search pull-right col-md-3" action="" method="post" id="commits-search-form">
+ <form class="search pull-right col-md-3" action="{{.RepoLink}}/commits/{{.BranchName}}/search" method="get" id="commits-search-form">
<div class="input-group">
- <input class="form-control search" type="search" placeholder="search commit" name="q"/>
+ <input class="form-control search" type="search" placeholder="search commit" name="q" value="{{.Keyword}}" />
<div class="input-group-btn">
- <button type="button" class="btn btn-default">Find</button>
+ <button type="submit" class="btn btn-default">Find</button>
</div>
</div>
</form>
@@ -20,7 +20,7 @@
<thead>
<tr>
<th class="author">Author</th>
- <th class="sha">Commit</th>
+ <th class="sha">SHA1</th>
<th class="message">Message</th>
<th class="date">Date</th>
</tr>
@@ -31,24 +31,19 @@
{{$r := List .Commits}}
{{range $r}}
<tr>
- <td class="author"><img class="avatar" src="{{AvatarLink .Committer.Email}}" alt=""/><a href="/user/{{.Committer.Name}}">{{.Committer.Name}}</a></td>
+ <td class="author"><img class="avatar" src="{{AvatarLink .Author.Email}}" alt=""/><a href="/user/{{.Author.Name}}">{{.Author.Name}}</a></td>
<td class="sha"><a class="label label-success" href="/{{$username}}/{{$reponame}}/commit/{{.Id}} ">{{SubStr .Id.String 0 10}} </a></td>
<td class="message">{{.Message}} </td>
- <td class="date">{{TimeSince .Committer.When}}</td>
+ <td class="date">{{TimeSince .Author.When}}</td>
</tr>
{{end}}
</tbody>
</table>
</div>
- <ul class="pagination" id="commits-pager">
- <li><a href="#">&laquo;</a></li>
- <li><a href="#">1</a></li>
- <li><a href="#">2</a></li>
- <li><a href="#">3</a></li>
- <li><a href="#">4</a></li>
- <li><a href="#">5</a></li>
- <li><a href="#">&raquo;</a></li>
- </ul>
+ {{if not .IsSearchPage}}<ul class="pagination" id="commits-pager">
+ {{if .LastPageNum}}<li><a href="{{.RepoLink}}/commits/{{.BranchName}}?p={{.LastPageNum}}">&laquo; Newer</a></li>{{end}}
+ {{if .NextPageNum}}<li><a href="{{.RepoLink}}/commits/{{.BranchName}}?p={{.NextPageNum}}">&raquo; Older</a></li>{{end}}
+ </ul>{{end}}
</div>
</div>
{{template "base/footer" .}}
diff --git a/templates/repo/single_bare.tmpl b/templates/repo/single_bare.tmpl
index 3f63915352..7d7016e5c5 100644
--- a/templates/repo/single_bare.tmpl
+++ b/templates/repo/single_bare.tmpl
@@ -16,7 +16,7 @@
<span class="input-group-btn">
<button class="btn btn-default" type="button">URL</button>
</span>
- <input name="passwd" type="password" class="form-control" placeholder="Type existing repository address" required="required">
+ <input name="import_url" class="form-control" placeholder="Type existing repository address" required="required">
<span class="input-group-btn">
<button type="submit" class="btn btn-default" type="button">Clone</button>
</span>
diff --git a/templates/user/dashboard.tmpl b/templates/user/dashboard.tmpl
index e2d7a5093f..efa78d8807 100644
--- a/templates/user/dashboard.tmpl
+++ b/templates/user/dashboard.tmpl
@@ -35,7 +35,7 @@
<ul class="list-unstyled">
<li><a href="/repo/create"><i class="fa fa-book"></i>Repository</a></li>
<li><a href="/repo/mirror"><i class="fa fa-clipboard"></i>Mirror</a></li>
- <li><a href="#"><i class="fa fa-users"></i>Organization</a></li>
+ <!-- <li><a href="#"><i class="fa fa-users"></i>Organization</a></li> -->
</ul>
</div>
</div>
diff --git a/web.go b/web.go
index e7b048bcd3..4a49a44843 100644
--- a/web.go
+++ b/web.go
@@ -152,6 +152,7 @@ func runWeb(*cli.Context) {
r.Post("/issues/new", bindIgnErr(auth.CreateIssueForm{}), repo.CreateIssuePost)
r.Post("/issues/:index", bindIgnErr(auth.CreateIssueForm{}), repo.UpdateIssue)
r.Post("/comment/:action", repo.Comment)
+ r.Post("/import", repo.Import)
}, reqSignIn, middleware.RepoAssignment(true))
m.Group("/:username/:reponame", func(r martini.Router) {
@@ -168,6 +169,7 @@ func runWeb(*cli.Context) {
r.Get("/src/:branchname/**", repo.Single)
r.Get("/raw/:branchname/**", repo.SingleDownload)
r.Get("/commits/:branchname", repo.Commits)
+ r.Get("/commits/:branchname/search", repo.SearchCommits)
r.Get("/commit/:branchname", repo.Diff)
r.Get("/commit/:branchname/**", repo.Diff)
}, ignSignIn, middleware.RepoAssignment(true, true))