From b8368f98ffc79a6c6c7bceed50a2989049d3eb1a Mon Sep 17 00:00:00 2001 From: Unknwon Date: Fri, 26 Sep 2014 08:55:13 -0400 Subject: [PATCH] Add directory level commit message --- gogs.go | 2 +- models/user.go | 13 +++++++++++-- routers/repo/commit.go | 4 ++-- routers/repo/view.go | 20 ++++++++++++++++---- templates/.VERSION | 2 +- templates/repo/view_list.tmpl | 2 +- 6 files changed, 32 insertions(+), 11 deletions(-) diff --git a/gogs.go b/gogs.go index 2f5b24176..28b0feccb 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.5.4.0925 Beta" +const APP_VER = "0.5.4.0926 Beta" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/models/user.go b/models/user.go index f327ed144..8aa349c8a 100644 --- a/models/user.go +++ b/models/user.go @@ -521,8 +521,17 @@ type UserCommit struct { *git.Commit } -// ValidCommitsWithEmails checks if authors' e-mails of commits are correcponding to users. -func ValidCommitsWithEmails(oldCommits *list.List) *list.List { +// ValidateCommitWithEmail chceck if author's e-mail of commit is corresponsind to a user. +func ValidateCommitWithEmail(c *git.Commit) (uname string) { + u, err := GetUserByEmail(c.Author.Email) + if err == nil { + uname = u.Name + } + return uname +} + +// ValidateCommitsWithEmails checks if authors' e-mails of commits are corresponding to users. +func ValidateCommitsWithEmails(oldCommits *list.List) *list.List { emails := map[string]string{} newCommits := list.New() e := oldCommits.Front() diff --git a/routers/repo/commit.go b/routers/repo/commit.go index 512df2534..9791cc551 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -61,7 +61,7 @@ func Commits(ctx *middleware.Context) { ctx.Handle(500, "CommitsByRange", err) return } - commits = models.ValidCommitsWithEmails(commits) + commits = models.ValidateCommitsWithEmails(commits) ctx.Data["Commits"] = commits ctx.Data["Username"] = userName @@ -99,7 +99,7 @@ func SearchCommits(ctx *middleware.Context) { ctx.Handle(500, "SearchCommits", err) return } - commits = models.ValidCommitsWithEmails(commits) + commits = models.ValidateCommitsWithEmails(commits) ctx.Data["Keyword"] = keyword ctx.Data["Username"] = userName diff --git a/routers/repo/view.go b/routers/repo/view.go index 4e4a7b18c..82f346002 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -11,6 +11,7 @@ import ( "path/filepath" "strings" + "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/git" "github.com/gogits/gogs/modules/log" @@ -130,20 +131,20 @@ func Home(ctx *middleware.Context) { if te.Type != git.COMMIT { c, err := ctx.Repo.Commit.GetCommitOfRelPath(filepath.Join(treePath, te.Name())) if err != nil { - ctx.Handle(404, "GetCommitOfRelPath", err) + ctx.Handle(500, "GetCommitOfRelPath", err) return } files = append(files, []interface{}{te, c}) } else { sm, err := ctx.Repo.Commit.GetSubModule(path.Join(treename, te.Name())) if err != nil { - ctx.Handle(404, "GetSubModule", err) + ctx.Handle(500, "GetSubModule", err) return } c, err := ctx.Repo.Commit.GetCommitOfRelPath(filepath.Join(treePath, te.Name())) if err != nil { - ctx.Handle(404, "GetCommitOfRelPath", err) + ctx.Handle(500, "GetCommitOfRelPath", err) return } files = append(files, []interface{}{te, git.NewSubModuleFile(c, sm.Url, te.Id.String())}) @@ -195,6 +196,18 @@ func Home(ctx *middleware.Context) { } } } + + lastCommit := ctx.Repo.Commit + if len(treePath) > 0 { + c, err := ctx.Repo.Commit.GetCommitOfRelPath(treePath) + if err != nil { + ctx.Handle(500, "GetCommitOfRelPath", err) + return + } + lastCommit = c + } + ctx.Data["LastCommit"] = lastCommit + ctx.Data["LastCommitUser"] = models.ValidateCommitWithEmail(lastCommit) } ctx.Data["Username"] = userName @@ -215,7 +228,6 @@ func Home(ctx *middleware.Context) { } } - ctx.Data["LastCommit"] = ctx.Repo.Commit ctx.Data["Paths"] = Paths ctx.Data["TreeName"] = treename ctx.Data["Treenames"] = treenames diff --git a/templates/.VERSION b/templates/.VERSION index 87b06b816..59eee24b7 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.5.4.0925 Beta \ No newline at end of file +0.5.4.0926 Beta \ No newline at end of file diff --git a/templates/repo/view_list.tmpl b/templates/repo/view_list.tmpl index 850c76164..e6c43d9e4 100644 --- a/templates/repo/view_list.tmpl +++ b/templates/repo/view_list.tmpl @@ -4,7 +4,7 @@ - {{.LastCommit.Author.Name}}: + {{if .LastCommitUser}}{{end}}{{.LastCommit.Author.Name}}:{{if .LastCommitUser}}{{end}} {{ShortSha .LastCommit.Id.String}}