From 25d6ae69d1cb392922b9d9dc0da1c17aef9a9db2 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Sun, 7 Sep 2014 19:58:01 -0400 Subject: Remove hg dep --- routers/repo/view.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) (limited to 'routers/repo/view.go') diff --git a/routers/repo/view.go b/routers/repo/view.go index 108e892b..f98eee03 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -11,13 +11,13 @@ import ( "path/filepath" "strings" + "github.com/saintfish/chardet" + "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/git" "github.com/gogits/gogs/modules/log" + "github.com/gogits/gogs/modules/mahonia" "github.com/gogits/gogs/modules/middleware" - - "code.google.com/p/mahonia" - "github.com/saintfish/chardet" ) const ( -- cgit v1.2.3 From ed84adb679f3de70b2bffaead20a87711c38ee3a Mon Sep 17 00:00:00 2001 From: lunnyxiao Date: Wed, 17 Sep 2014 12:03:03 +0800 Subject: toutf8 improved & add max git diff lines --- conf/app.ini | 3 +++ models/git_diff.go | 34 ++++++++++++++++++++++------------ modules/base/template.go | 27 +++++++++++++++++++++++++++ modules/setting/setting.go | 3 +++ routers/repo/commit.go | 7 +++++-- routers/repo/view.go | 20 +------------------- templates/repo/diff.tmpl | 2 +- 7 files changed, 62 insertions(+), 34 deletions(-) (limited to 'routers/repo/view.go') diff --git a/conf/app.ini b/conf/app.ini index be49e064..cb907b22 100644 --- a/conf/app.ini +++ b/conf/app.ini @@ -255,3 +255,6 @@ CONN = [i18n] LANGS = en-US,zh-CN,de-DE NAMES = English,简体中文,Deutsch + +[git] +MAX_GITDIFF_LINES = 10000 \ No newline at end of file diff --git a/models/git_diff.go b/models/git_diff.go index bf7a9cd5..e093e7ab 100644 --- a/models/git_diff.go +++ b/models/git_diff.go @@ -70,7 +70,7 @@ func (diff *Diff) NumFiles() int { const DIFF_HEAD = "diff --git " -func ParsePatch(pid int64, cmd *exec.Cmd, reader io.Reader) (*Diff, error) { +func ParsePatch(pid int64, maxlines int, cmd *exec.Cmd, reader io.Reader) (*Diff, error) { scanner := bufio.NewScanner(reader) var ( curFile *DiffFile @@ -79,6 +79,7 @@ func ParsePatch(pid int64, cmd *exec.Cmd, reader io.Reader) (*Diff, error) { } leftLine, rightLine int + isTooLong bool ) diff := &Diff{Files: make([]*DiffFile, 0)} @@ -90,16 +91,17 @@ func ParsePatch(pid int64, cmd *exec.Cmd, reader io.Reader) (*Diff, error) { continue } + if line == "" { + continue + } + i = i + 1 - // Diff data too large. - if i == 5000 { + // Diff data too large, we only show the first about maxlines lines + if i == maxlines { + isTooLong = true log.Warn("Diff data too large") - return &Diff{}, nil - } - - if line == "" { - continue + //return &Diff{}, nil } switch { @@ -110,6 +112,10 @@ func ParsePatch(pid int64, cmd *exec.Cmd, reader io.Reader) (*Diff, error) { curSection.Lines = append(curSection.Lines, diffLine) continue case line[0] == '@': + if isTooLong { + return diff, nil + } + curSection = &DiffSection{} curFile.Sections = append(curFile.Sections, curSection) ss := strings.Split(line, "@@") @@ -143,6 +149,10 @@ func ParsePatch(pid int64, cmd *exec.Cmd, reader io.Reader) (*Diff, error) { // Get new file. if strings.HasPrefix(line, DIFF_HEAD) { + if isTooLong { + return diff, nil + } + fs := strings.Split(line[len(DIFF_HEAD):], " ") a := fs[0] @@ -174,7 +184,7 @@ func ParsePatch(pid int64, cmd *exec.Cmd, reader io.Reader) (*Diff, error) { return diff, nil } -func GetDiffRange(repoPath, beforeCommitId string, afterCommitId string) (*Diff, error) { +func GetDiffRange(repoPath, beforeCommitId string, afterCommitId string, maxlines int) (*Diff, error) { repo, err := git.OpenRepository(repoPath) if err != nil { return nil, err @@ -228,9 +238,9 @@ func GetDiffRange(repoPath, beforeCommitId string, afterCommitId string) (*Diff, } }() - return ParsePatch(pid, cmd, rd) + return ParsePatch(pid, maxlines, cmd, rd) } -func GetDiffCommit(repoPath, commitId string) (*Diff, error) { - return GetDiffRange(repoPath, "", commitId) +func GetDiffCommit(repoPath, commitId string, maxlines int) (*Diff, error) { + return GetDiffRange(repoPath, "", commitId, maxlines) } diff --git a/modules/base/template.go b/modules/base/template.go index f2ae00b9..64195729 100644 --- a/modules/base/template.go +++ b/modules/base/template.go @@ -8,13 +8,16 @@ import ( "bytes" "container/list" "encoding/json" + "errors" "fmt" "html/template" "runtime" "strings" "time" + "code.google.com/p/mahonia" "github.com/gogits/gogs/modules/setting" + "github.com/saintfish/chardet" ) func Str2html(raw string) template.HTML { @@ -45,6 +48,29 @@ func ShortSha(sha1 string) string { return sha1 } +func ToUtf8WithErr(content []byte) (error, string) { + detector := chardet.NewTextDetector() + result, err := detector.DetectBest(content) + if err != nil { + return err, "" + } + + if result.Charset == "utf8" { + return nil, string(content) + } + + decoder := mahonia.NewDecoder(result.Charset) + if decoder != nil { + return nil, decoder.ConvertString(string(content)) + } + return errors.New("unknow char decoder"), string(content) +} + +func ToUtf8(content string) string { + _, res := ToUtf8WithErr([]byte(content)) + return res +} + var mailDomains = map[string]string{ "gmail.com": "gmail.com", } @@ -103,6 +129,7 @@ var TemplateFuncs template.FuncMap = map[string]interface{}{ "ActionContent2Commits": ActionContent2Commits, "Oauth2Icon": Oauth2Icon, "Oauth2Name": Oauth2Name, + "ToUtf8": ToUtf8, } type Actioner interface { diff --git a/modules/setting/setting.go b/modules/setting/setting.go index 199b4f2c..011c00c0 100644 --- a/modules/setting/setting.go +++ b/modules/setting/setting.go @@ -64,6 +64,7 @@ var ( // Picture settings. PictureService string DisableGravatar bool + MaxGitDiffLines int // Log settings. LogRootPath string @@ -241,6 +242,8 @@ func NewConfigContext() { []string{"server"}) DisableGravatar = Cfg.MustBool("picture", "DISABLE_GRAVATAR") + MaxGitDiffLines = Cfg.MustInt("git", "MAX_GITDIFF_LINES", 5000) + Langs = Cfg.MustValueArray("i18n", "LANGS", ",") Names = Cfg.MustValueArray("i18n", "NAMES", ",") } diff --git a/routers/repo/commit.go b/routers/repo/commit.go index 54acc85b..f7feb4d9 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -12,6 +12,7 @@ import ( "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/middleware" + "github.com/gogits/gogs/modules/setting" ) const ( @@ -114,7 +115,8 @@ func Diff(ctx *middleware.Context) { commit := ctx.Repo.Commit - diff, err := models.GetDiffCommit(models.RepoPath(userName, repoName), commitId) + diff, err := models.GetDiffCommit(models.RepoPath(userName, repoName), + commitId, setting.MaxGitDiffLines) if err != nil { ctx.Handle(404, "GetDiffCommit", err) return @@ -176,7 +178,8 @@ func CompareDiff(ctx *middleware.Context) { return } - diff, err := models.GetDiffRange(models.RepoPath(userName, repoName), beforeCommitId, afterCommitId) + diff, err := models.GetDiffRange(models.RepoPath(userName, repoName), beforeCommitId, + afterCommitId, setting.MaxGitDiffLines) if err != nil { ctx.Handle(404, "GetDiffRange", err) return diff --git a/routers/repo/view.go b/routers/repo/view.go index f98eee03..e42894ae 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -11,12 +11,9 @@ import ( "path/filepath" "strings" - "github.com/saintfish/chardet" - "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/git" "github.com/gogits/gogs/modules/log" - "github.com/gogits/gogs/modules/mahonia" "github.com/gogits/gogs/modules/middleware" ) @@ -24,21 +21,6 @@ const ( HOME base.TplName = "repo/home" ) -func toUtf8(content []byte) (error, string) { - detector := chardet.NewTextDetector() - result, err := detector.DetectBest(content) - if err != nil { - return err, "" - } - - if result.Charset == "utf8" { - return nil, string(content) - } - - decoder := mahonia.NewDecoder(result.Charset) - return nil, decoder.ConvertString(string(content)) -} - func Home(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Repo.Repository.Name @@ -117,7 +99,7 @@ func Home(ctx *middleware.Context) { if readmeExist { ctx.Data["FileContent"] = string(base.RenderMarkdown(buf, "")) } else { - if err, content := toUtf8(buf); err != nil { + if err, content := base.ToUtf8WithErr(buf); err != nil { if err != nil { log.Error(4, "Convert content encoding: %s", err) } diff --git a/templates/repo/diff.tmpl b/templates/repo/diff.tmpl index 78733450..a2150f28 100644 --- a/templates/repo/diff.tmpl +++ b/templates/repo/diff.tmpl @@ -105,7 +105,7 @@ {{if .RightIdx}}{{.RightIdx}}{{end}} -
{{.Content}}
+
{{ToUtf8 .Content}}
{{end}} -- cgit v1.2.3 From 150eef93b2340f665c070158ade1863339829e05 Mon Sep 17 00:00:00 2001 From: lunnyxiao Date: Mon, 22 Sep 2014 10:43:16 +0800 Subject: add submodule basic support & buf fixed #478 --- modules/git/commit.go | 50 ++++++++++++++++++++++++++++++++++++++++++- modules/git/submodule.go | 6 ++++++ modules/git/tree.go | 2 ++ modules/git/tree_entry.go | 4 ++++ routers/repo/http.go | 5 +++++ routers/repo/view.go | 40 ++++++++++++++++++++++++++++------ templates/repo/view_list.tmpl | 17 +++++++++++++-- 7 files changed, 115 insertions(+), 9 deletions(-) create mode 100644 modules/git/submodule.go (limited to 'routers/repo/view.go') diff --git a/modules/git/commit.go b/modules/git/commit.go index 52348fef..d2d373da 100644 --- a/modules/git/commit.go +++ b/modules/git/commit.go @@ -5,6 +5,7 @@ package git import ( + "bufio" "container/list" "strings" ) @@ -17,7 +18,8 @@ type Commit struct { Committer *Signature CommitMessage string - parents []sha1 // sha1 strings + parents []sha1 // sha1 strings + submodules map[string]*SubModule } // Return the commit message. Same as retrieving CommitMessage directly. @@ -84,3 +86,49 @@ func (c *Commit) CommitsByRange(page int) (*list.List, error) { func (c *Commit) GetCommitOfRelPath(relPath string) (*Commit, error) { return c.repo.getCommitOfRelPath(c.Id, relPath) } + +func (c *Commit) GetSubModule(entryname string) (*SubModule, error) { + moduels, err := c.GetSubModules() + if err != nil { + return nil, err + } + return moduels[entryname], nil +} + +func (c *Commit) GetSubModules() (map[string]*SubModule, error) { + if c.submodules != nil { + return c.submodules, nil + } + + entry, err := c.GetTreeEntryByPath(".gitmodules") + if err != nil { + return nil, err + } + rd, err := entry.Blob().Data() + if err != nil { + return nil, err + } + + scanner := bufio.NewScanner(rd) + c.submodules = make(map[string]*SubModule) + var ismodule bool + var path string + for scanner.Scan() { + if strings.HasPrefix(scanner.Text(), "[submodule") { + ismodule = true + continue + } + if ismodule { + fields := strings.Split(scanner.Text(), "=") + k := strings.TrimSpace(fields[0]) + if k == "path" { + path = strings.TrimSpace(fields[1]) + } else if k == "url" { + c.submodules[path] = &SubModule{path, strings.TrimSpace(fields[1])} + ismodule = false + } + } + } + + return c.submodules, nil +} diff --git a/modules/git/submodule.go b/modules/git/submodule.go new file mode 100644 index 00000000..28b5b9f3 --- /dev/null +++ b/modules/git/submodule.go @@ -0,0 +1,6 @@ +package git + +type SubModule struct { + Name string + Url string +} diff --git a/modules/git/tree.go b/modules/git/tree.go index 03152c34..a3012443 100644 --- a/modules/git/tree.go +++ b/modules/git/tree.go @@ -51,6 +51,8 @@ func parseTreeData(tree *Tree, data []byte) ([]*TreeEntry, error) { case "160000": entry.mode = ModeCommit entry.Type = COMMIT + + step = 8 case "040000": entry.mode = ModeTree entry.Type = TREE diff --git a/modules/git/tree_entry.go b/modules/git/tree_entry.go index e842f233..f65f3326 100644 --- a/modules/git/tree_entry.go +++ b/modules/git/tree_entry.go @@ -61,6 +61,10 @@ func (te *TreeEntry) Size() int64 { return te.size } +func (te *TreeEntry) IsSubModule() bool { + return te.mode == ModeCommit +} + func (te *TreeEntry) IsDir() bool { return te.mode == ModeTree } diff --git a/routers/repo/http.go b/routers/repo/http.go index 56c85bf5..a98478c9 100644 --- a/routers/repo/http.go +++ b/routers/repo/http.go @@ -103,6 +103,7 @@ func Http(ctx *middleware.Context) { // check access if askAuth { baHead := ctx.Req.Header.Get("Authorization") + fmt.Println("auth:", baHead) if baHead == "" { authRequired(ctx) return @@ -121,6 +122,8 @@ func Http(ctx *middleware.Context) { return } + fmt.Println("auth2:", authUsername, passwd) + authUser, err = models.GetUserByName(authUsername) if err != nil { ctx.Handle(401, "no basic auth and digit auth", nil) @@ -134,6 +137,8 @@ func Http(ctx *middleware.Context) { return } + fmt.Println("passwd is right") + if !isPublicPull { var tp = models.WRITABLE if isPull { diff --git a/routers/repo/view.go b/routers/repo/view.go index e42894ae..41fdaba0 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -10,6 +10,7 @@ import ( "path" "path/filepath" "strings" + "time" "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/git" @@ -21,6 +22,15 @@ const ( HOME base.TplName = "repo/home" ) +type fakeCommit struct { + Id string + Summary string + Url string + Committer struct { + When time.Time + } +} + func Home(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Repo.Repository.Name @@ -127,13 +137,31 @@ func Home(ctx *middleware.Context) { files := make([][]interface{}, 0, len(entries)) for _, te := range entries { - c, err := ctx.Repo.Commit.GetCommitOfRelPath(filepath.Join(treePath, te.Name())) - if err != nil { - ctx.Handle(404, "GetCommitOfRelPath", err) - return - } + if te.Type != git.COMMIT { + c, err := ctx.Repo.Commit.GetCommitOfRelPath(filepath.Join(treePath, te.Name())) + if err != nil { + ctx.Handle(404, "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) + return + } - files = append(files, []interface{}{te, c}) + commit := git.Commit{ + Tree: *tree, + Id: te.Id, + Committer: &git.Signature{ + When: time.Now(), + }, + CommitMessage: sm.Url, + } + + files = append(files, []interface{}{te, &commit}) + } } ctx.Data["Files"] = files diff --git a/templates/repo/view_list.tmpl b/templates/repo/view_list.tmpl index ce46cfb2..e8628306 100644 --- a/templates/repo/view_list.tmpl +++ b/templates/repo/view_list.tmpl @@ -27,8 +27,20 @@ {{$entry := index $item 0}} {{$commit := index $item 1}} - - + {{if $entry.IsSubModule}} + + + + + {{$entry.Name}} @ {{ShortSha $commit.Id.String}} + + + {{$commit.Summary}} + + {{TimeSince $commit.Committer.When $.i18n.Lang}} + {{else}} + + {{$entry.Name}} @@ -37,6 +49,7 @@ {{$commit.Summary}} {{TimeSince $commit.Committer.When $.i18n.Lang}} + {{end}} {{end}} -- cgit v1.2.3 From 7df60af60ed6d9606c5894c6512522dc91d0c247 Mon Sep 17 00:00:00 2001 From: lunnyxiao Date: Mon, 22 Sep 2014 14:23:36 +0800 Subject: submodule support and closed #478 --- modules/git/tree_entry.go | 2 +- routers/repo/view.go | 28 ++++++++++++++-------------- templates/repo/view_list.tmpl | 8 ++------ 3 files changed, 17 insertions(+), 21 deletions(-) (limited to 'routers/repo/view.go') diff --git a/modules/git/tree_entry.go b/modules/git/tree_entry.go index f65f3326..e403e93e 100644 --- a/modules/git/tree_entry.go +++ b/modules/git/tree_entry.go @@ -84,7 +84,7 @@ type Entries []*TreeEntry var sorter = []func(t1, t2 *TreeEntry) bool{ func(t1, t2 *TreeEntry) bool { - return t1.IsDir() && !t2.IsDir() + return (t1.IsDir() || t1.IsSubModule()) && !t2.IsDir() && !t2.IsSubModule() }, func(t1, t2 *TreeEntry) bool { return t1.name < t2.name diff --git a/routers/repo/view.go b/routers/repo/view.go index 41fdaba0..77f17e7a 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -10,7 +10,6 @@ import ( "path" "path/filepath" "strings" - "time" "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/git" @@ -23,12 +22,10 @@ const ( ) type fakeCommit struct { - Id string - Summary string - Url string - Committer struct { - When time.Time - } + *git.Commit + + RefUrl string + RefId string } func Home(ctx *middleware.Context) { @@ -151,13 +148,16 @@ func Home(ctx *middleware.Context) { return } - commit := git.Commit{ - Tree: *tree, - Id: te.Id, - Committer: &git.Signature{ - When: time.Now(), - }, - CommitMessage: sm.Url, + c, err := ctx.Repo.Commit.GetCommitOfRelPath(filepath.Join(treePath, te.Name())) + if err != nil { + ctx.Handle(404, "GetCommitOfRelPath", err) + return + } + + commit := fakeCommit{ + Commit: c, + RefUrl: strings.TrimRight(sm.Url, ".git"), + RefId: te.Id.String(), } files = append(files, []interface{}{te, &commit}) diff --git a/templates/repo/view_list.tmpl b/templates/repo/view_list.tmpl index e8628306..41f7daf2 100644 --- a/templates/repo/view_list.tmpl +++ b/templates/repo/view_list.tmpl @@ -32,12 +32,8 @@ - {{$entry.Name}} @ {{ShortSha $commit.Id.String}} + {{$entry.Name}} @ {{ShortSha $commit.RefId}} - - {{$commit.Summary}} - - {{TimeSince $commit.Committer.When $.i18n.Lang}} {{else}} @@ -45,11 +41,11 @@ {{$entry.Name}} + {{end}} {{$commit.Summary}} {{TimeSince $commit.Committer.When $.i18n.Lang}} - {{end}} {{end}} -- cgit v1.2.3 From 3f707b3f3265c4b3e64e47ee172cc878f3325248 Mon Sep 17 00:00:00 2001 From: Unknwon Date: Mon, 22 Sep 2014 17:01:19 -0400 Subject: Add basic submodule support --- README.md | 2 +- README_ZH.md | 2 +- gogs.go | 2 +- modules/git/submodule.go | 52 ++++++++++++++++++++++++++++++++++++++++++++++++ routers/repo/view.go | 16 +-------------- templates/.VERSION | 2 +- 6 files changed, 57 insertions(+), 19 deletions(-) (limited to 'routers/repo/view.go') diff --git a/README.md b/README.md index 232aa92a..a2aed3af 100644 --- a/README.md +++ b/README.md @@ -5,7 +5,7 @@ Gogs(Go Git Service) is a painless self-hosted Git Service written in Go. ![Demo](https://gowalker.org/public/gogs_demo.gif) -##### Current version: 0.5.3 Beta +##### Current version: 0.5.4 Beta ### NOTICES diff --git a/README_ZH.md b/README_ZH.md index fcc8b496..817110b3 100644 --- a/README_ZH.md +++ b/README_ZH.md @@ -5,7 +5,7 @@ Gogs(Go Git Service) 是一个基于 Go 语言的自助 Git 服务。 ![Demo](https://gowalker.org/public/gogs_demo.gif) -##### 当前版本:0.5.3 Beta +##### 当前版本:0.5.4 Beta ## 开发目的 diff --git a/gogs.go b/gogs.go index b1b9fe60..d565d7bb 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.5.3.0922 Beta" +const APP_VER = "0.5.4.0922 Beta" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/modules/git/submodule.go b/modules/git/submodule.go index 28b5b9f3..6927f8cb 100644 --- a/modules/git/submodule.go +++ b/modules/git/submodule.go @@ -1,6 +1,58 @@ +// 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 git +import ( + "strings" +) + type SubModule struct { Name string Url string } + +// SubModuleFile represents a file with submodule type. +type SubModuleFile struct { + *Commit + + refUrl string + refId string +} + +func NewSubModuleFile(c *Commit, refUrl, refId string) *SubModuleFile { + return &SubModuleFile{ + Commit: c, + refUrl: refUrl, + refId: refId, + } +} + +// RefUrl guesses and returns reference URL. +func (sf *SubModuleFile) RefUrl() string { + url := strings.TrimSuffix(sf.refUrl, ".git") + + // git://xxx/user/repo + if strings.HasPrefix(url, "git://") { + return "http://" + strings.TrimPrefix(url, "git://") + } + + // http[s]://xxx/user/repo + if strings.HasPrefix(url, "http://") || strings.HasPrefix(url, "https://") { + return url + } + + // sysuser@xxx:user/repo + i := strings.Index(url, "@") + j := strings.LastIndex(url, ":") + if i > -1 && j > -1 { + return "http://" + url[i+1:j] + "/" + url[j+1:] + } + return url +} + +// RefId returns reference ID. +func (sf *SubModuleFile) RefId() string { + return sf.refId +} diff --git a/routers/repo/view.go b/routers/repo/view.go index 77f17e7a..4e4a7b18 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -21,13 +21,6 @@ const ( HOME base.TplName = "repo/home" ) -type fakeCommit struct { - *git.Commit - - RefUrl string - RefId string -} - func Home(ctx *middleware.Context) { ctx.Data["Title"] = ctx.Repo.Repository.Name @@ -153,14 +146,7 @@ func Home(ctx *middleware.Context) { ctx.Handle(404, "GetCommitOfRelPath", err) return } - - commit := fakeCommit{ - Commit: c, - RefUrl: strings.TrimRight(sm.Url, ".git"), - RefId: te.Id.String(), - } - - files = append(files, []interface{}{te, &commit}) + files = append(files, []interface{}{te, git.NewSubModuleFile(c, sm.Url, te.Id.String())}) } } diff --git a/templates/.VERSION b/templates/.VERSION index 19d8171e..8a713df0 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.5.3.0922 Beta \ No newline at end of file +0.5.4.0922 Beta \ No newline at end of file -- cgit v1.2.3 From b8368f98ffc79a6c6c7bceed50a2989049d3eb1a Mon Sep 17 00:00:00 2001 From: Unknwon Date: Fri, 26 Sep 2014 08:55:13 -0400 Subject: 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(-) (limited to 'routers/repo/view.go') diff --git a/gogs.go b/gogs.go index 2f5b2417..28b0fecc 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 f327ed14..8aa349c8 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 512df253..9791cc55 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 4e4a7b18..82f34600 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 87b06b81..59eee24b 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 850c7616..e6c43d9e 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}} -- cgit v1.2.3 From 2a031c13658458df9f8f56ce295a8ba72bf35dff Mon Sep 17 00:00:00 2001 From: Unknwon Date: Tue, 30 Sep 2014 04:39:53 -0400 Subject: Fix #515 --- gogs.go | 2 +- modules/git/repo_commit.go | 4 ++-- modules/git/repo_tag.go | 2 +- modules/git/tree.go | 5 ++++- modules/middleware/repo.go | 5 ++--- public/ng/css/gogs.css | 1 - public/ng/less/gogs/dashboard.less | 1 - routers/repo/view.go | 1 + templates/.VERSION | 2 +- 9 files changed, 12 insertions(+), 11 deletions(-) (limited to 'routers/repo/view.go') diff --git a/gogs.go b/gogs.go index e7615c9b..0ea64d26 100644 --- a/gogs.go +++ b/gogs.go @@ -17,7 +17,7 @@ import ( "github.com/gogits/gogs/modules/setting" ) -const APP_VER = "0.5.4.0929 Beta" +const APP_VER = "0.5.4.0930 Beta" func init() { runtime.GOMAXPROCS(runtime.NumCPU()) diff --git a/modules/git/repo_commit.go b/modules/git/repo_commit.go index cd0181c4..7c47b53d 100644 --- a/modules/git/repo_commit.go +++ b/modules/git/repo_commit.go @@ -40,11 +40,11 @@ func (repo *Repository) GetCommitIdOfTag(tagName string) (string, error) { } func (repo *Repository) GetCommitOfTag(tagName string) (*Commit, error) { - commitId, err := repo.GetCommitIdOfTag(tagName) + tag, err := repo.GetTag(tagName) if err != nil { return nil, err } - return repo.GetCommit(commitId) + return tag.Commit() } // Parse commit information from the (uncompressed) raw diff --git a/modules/git/repo_tag.go b/modules/git/repo_tag.go index dd31e441..77ae3db0 100644 --- a/modules/git/repo_tag.go +++ b/modules/git/repo_tag.go @@ -52,6 +52,7 @@ func (repo *Repository) getTag(id sha1) (*Tag, error) { if err != nil { return nil, errors.New(stderr) } + tp = strings.TrimSpace(tp) // Tag is a commit. if ObjectType(tp) == COMMIT { @@ -77,7 +78,6 @@ func (repo *Repository) getTag(id sha1) (*Tag, error) { } tag.Id = id - tag.Object = id tag.repo = repo repo.tagCache[id] = tag diff --git a/modules/git/tree.go b/modules/git/tree.go index a3012443..be77bfce 100644 --- a/modules/git/tree.go +++ b/modules/git/tree.go @@ -109,9 +109,12 @@ func (t *Tree) ListEntries(relpath string) (Entries, error) { } t.entriesParsed = true - stdout, _, err := com.ExecCmdDirBytes(t.repo.Path, + stdout, stderr, err := com.ExecCmdDirBytes(t.repo.Path, "git", "ls-tree", t.Id.String()) if err != nil { + if strings.Contains(err.Error(), "exit status 128") { + return nil, errors.New(strings.TrimSpace(string(stderr))) + } return nil, err } t.entries, err = parseTreeData(t, stdout) diff --git a/modules/middleware/repo.go b/modules/middleware/repo.go index c0290b2e..c6250f6d 100644 --- a/modules/middleware/repo.go +++ b/modules/middleware/repo.go @@ -208,10 +208,9 @@ func RepoAssignment(redirect bool, args ...bool) macaron.Handler { } else if gitRepo.IsTagExist(refName) { ctx.Repo.IsTag = true ctx.Repo.BranchName = refName - - ctx.Repo.Commit, err = gitRepo.GetCommitOfTag(refName) + ctx.Repo.Commit, err = ctx.Repo.GitRepo.GetCommitOfTag(refName) if err != nil { - ctx.Handle(500, "RepoAssignment invalid tag", err) + ctx.Handle(500, "Fail to get tag commit", err) return } ctx.Repo.CommitId = ctx.Repo.Commit.Id.String() diff --git a/public/ng/css/gogs.css b/public/ng/css/gogs.css index 6d38ac9b..feb21c97 100644 --- a/public/ng/css/gogs.css +++ b/public/ng/css/gogs.css @@ -833,7 +833,6 @@ ol.linenums { } #dashboard-my-repo .repo-count { margin-left: 4px; - font-size: .8em; } #dashboard-my-org, #dashboard-my-mirror { diff --git a/public/ng/less/gogs/dashboard.less b/public/ng/less/gogs/dashboard.less index e7a1e90c..a40debe5 100644 --- a/public/ng/less/gogs/dashboard.less +++ b/public/ng/less/gogs/dashboard.less @@ -139,7 +139,6 @@ } .repo-count { margin-left: 4px; - font-size: .8em; } } #dashboard-my-org, diff --git a/routers/repo/view.go b/routers/repo/view.go index 82f34600..ba76a6ad 100644 --- a/routers/repo/view.go +++ b/routers/repo/view.go @@ -118,6 +118,7 @@ func Home(ctx *middleware.Context) { ctx.Handle(404, "SubTree", err) return } + entries, err := tree.ListEntries(treename) if err != nil { ctx.Handle(500, "ListEntries", err) diff --git a/templates/.VERSION b/templates/.VERSION index 2d0d24c2..c734a8f0 100644 --- a/templates/.VERSION +++ b/templates/.VERSION @@ -1 +1 @@ -0.5.4.0929 Beta \ No newline at end of file +0.5.4.0930 Beta \ No newline at end of file -- cgit v1.2.3