From 3da325591b5d8578f575f5fad59595f3c5efe4d6 Mon Sep 17 00:00:00 2001 From: Lunny Xiao Date: Wed, 19 Mar 2014 14:39:07 +0800 Subject: [PATCH] bug fixed for commits list --- models/repo.go | 3 ++- modules/base/template.go | 19 +++++++++++++++++++ templates/repo/commits.tmpl | 5 +++-- web.go | 4 ++++ 4 files changed, 28 insertions(+), 3 deletions(-) diff --git a/models/repo.go b/models/repo.go index c37fb4de2..1331bbf45 100644 --- a/models/repo.go +++ b/models/repo.go @@ -5,6 +5,7 @@ package models import ( + "container/list" "errors" "fmt" "io/ioutil" @@ -601,7 +602,7 @@ func GetLastestCommit(userName, repoName string) (*Commit, error) { }*/ // GetCommits returns all commits of given branch of repository. -func GetCommits(userName, reposName, branchname string) ([]*git.Commit, error) { +func GetCommits(userName, reposName, branchname string) (*list.List, error) { repo, err := git.OpenRepository(RepoPath(userName, reposName)) if err != nil { return nil, err diff --git a/modules/base/template.go b/modules/base/template.go index 4517cd47a..db79340e7 100644 --- a/modules/base/template.go +++ b/modules/base/template.go @@ -5,6 +5,7 @@ package base import ( + "container/list" "html/template" ) @@ -12,6 +13,23 @@ func Str2html(raw string) template.HTML { return template.HTML(raw) } +func Range(l int) []int { + return make([]int, l) +} + +func List(l *list.List) chan interface{} { + e := l.Front() + c := make(chan interface{}) + go func() { + for e != nil { + c <- e.Value + e = e.Next() + } + close(c) + }() + return c +} + var TemplateFuncs template.FuncMap = map[string]interface{}{ "AppName": func() string { return AppName @@ -30,4 +48,5 @@ var TemplateFuncs template.FuncMap = map[string]interface{}{ "ActionIcon": ActionIcon, "ActionDesc": ActionDesc, "DateFormat": DateFormat, + "List": List, } diff --git a/templates/repo/commits.tmpl b/templates/repo/commits.tmpl index 9190a030a..4bffb9daf 100644 --- a/templates/repo/commits.tmpl +++ b/templates/repo/commits.tmpl @@ -5,8 +5,9 @@
    - {{range .Commits}} -
  • {{.Committer.Name}} - {{.Id}} - {{.Message}} - {{.Committer.When}}
  • + {{$r := List .Commits}} + {{range $r}} +
  • {{.Committer.Name}} - {{.Id}} - {{.Message}} - {{.Committer.When}}
  • {{end}}
diff --git a/web.go b/web.go index ca504ea56..3ca93f307 100644 --- a/web.go +++ b/web.go @@ -34,6 +34,10 @@ gogs web`, Flags: []cli.Flag{}, } +func Range(l int) []int { + return make([]int, l) +} + func runWeb(*cli.Context) { log.Info("%s %s", base.AppName, base.AppVer)