From 6437d0180b97a26319b50c2e22927dac7c94fcdd Mon Sep 17 00:00:00 2001 From: ᴜɴᴋɴᴡᴏɴ Date: Sun, 8 Mar 2020 19:09:31 +0800 Subject: git: migrate to github.com/gogs/git-module@v1.0.0 (#5958) * WIP * Finish `internal/db/git_diff.go` * FInish internal/db/mirror.go * Finish internal/db/pull.go * Finish internal/db/release.go * Finish internal/db/repo.go * Finish internal/db/repo_branch.go * Finish internal/db/repo_editor.go * Finish internal/db/update.go * Save my work * Add license header * Compile! * Merge master * Finish internal/cmd/hook.go * Finish internal/conf/static.go * Finish internal/context/repo.go * Finish internal/db/action.go * Finish internal/db/git_diff.go * Fix submodule URL inferring * Finish internal/db/mirror.go * Updat to beta.4 * css: update fonts * Finish internal/db/pull.go * Finish internal/db/release.go * Finish internal/db/repo_branch.go * Finish internal/db/wiki.go * gitutil: enhance infer submodule UR * Finish internal/route/api/v1/repo/commits.go * mirror: only collect branch commits after sync * mirror: fix tag support * Finish internal/db/repo.go * Finish internal/db/repo_editor.go * Finish internal/db/update.go * Finish internal/gitutil/pull_request.go * Make it compile * Finish internal/route/repo/setting.go * Finish internal/route/repo/branch.go * Finish internal/route/api/v1/repo/file.go * Finish internal/route/repo/download.go * Finish internal/route/repo/editor.go * Use helper * Finish internal/route/repo/issue.go * Finish internal/route/repo/pull.go * Finish internal/route/repo/release.go * Finish internal/route/repo/repo.go * Finish internal/route/repo/wiki.go * Finish internal/route/repo/commit.go * Finish internal/route/repo/view.go * Finish internal/gitutil/tag.go * go.sum --- internal/template/template.go | 47 ++++++++++++++++++------------------------- 1 file changed, 20 insertions(+), 27 deletions(-) (limited to 'internal/template') diff --git a/internal/template/template.go b/internal/template/template.go index 5d254e50..d34e44f6 100644 --- a/internal/template/template.go +++ b/internal/template/template.go @@ -5,7 +5,6 @@ package template import ( - "container/list" "fmt" "html/template" "mime" @@ -21,8 +20,11 @@ import ( "golang.org/x/text/transform" log "unknwon.dev/clog/v2" + "github.com/gogs/git-module" + "gogs.io/gogs/internal/conf" "gogs.io/gogs/internal/db" + "gogs.io/gogs/internal/gitutil" "gogs.io/gogs/internal/markup" "gogs.io/gogs/internal/tool" ) @@ -36,6 +38,9 @@ var ( func FuncMap() []template.FuncMap { funcMapOnce.Do(func() { funcMap = []template.FuncMap{map[string]interface{}{ + "BuildCommit": func() string { + return conf.BuildCommit + }, "Year": func() int { return time.Now().Year() }, @@ -86,7 +91,6 @@ func FuncMap() []template.FuncMap { "DateFmtShort": func(t time.Time) string { return t.Format("Jan 02, 2006") }, - "List": List, "SubStr": func(str string, start, length int) string { if len(str) == 0 { return "" @@ -102,11 +106,10 @@ func FuncMap() []template.FuncMap { }, "Join": strings.Join, "EllipsisString": tool.EllipsisString, - "DiffTypeToStr": DiffTypeToStr, + "DiffFileTypeToStr": DiffFileTypeToStr, "DiffLineTypeToStr": DiffLineTypeToStr, "Sha1": Sha1, "ShortSHA1": tool.ShortSHA1, - "MD5": tool.MD5, "ActionContent2Commits": ActionContent2Commits, "EscapePound": EscapePound, "RenderCommitMessage": RenderCommitMessage, @@ -126,6 +129,7 @@ func FuncMap() []template.FuncMap { } return "tab-size-8" }, + "InferSubmoduleURL": gitutil.InferSubmoduleURL, }} }) return funcMap @@ -144,19 +148,6 @@ func NewLine2br(raw string) string { return strings.Replace(raw, "\n", "
", -1) } -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 -} - func Sha1(str string) string { return tool.SHA1(str) } @@ -269,20 +260,22 @@ func EscapePound(str string) string { return strings.NewReplacer("%", "%25", "#", "%23", " ", "%20", "?", "%3F").Replace(str) } -func DiffTypeToStr(diffType int) string { - diffTypes := map[int]string{ - 1: "add", 2: "modify", 3: "del", 4: "rename", - } - return diffTypes[diffType] +func DiffFileTypeToStr(typ git.DiffFileType) string { + return map[git.DiffFileType]string{ + git.DiffFileAdd: "add", + git.DiffFileChange: "modify", + git.DiffFileDelete: "del", + git.DiffFileRename: "rename", + }[typ] } -func DiffLineTypeToStr(diffType int) string { - switch diffType { - case 2: +func DiffLineTypeToStr(typ git.DiffLineType) string { + switch typ { + case git.DiffLineAdd: return "add" - case 3: + case git.DiffLineDelete: return "del" - case 4: + case git.DiffLineSection: return "tag" } return "same" -- cgit v1.2.3