From 677643b812cdc3bce3b7ef7839239b3059376684 Mon Sep 17 00:00:00 2001 From: slene Date: Fri, 28 Mar 2014 00:07:22 +0800 Subject: fix read commit source --- routers/repo/commit.go | 31 ++++++++++++++++++++++++------- 1 file changed, 24 insertions(+), 7 deletions(-) (limited to 'routers/repo/commit.go') diff --git a/routers/repo/commit.go b/routers/repo/commit.go index 3d00f8d7..11aab67c 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -5,13 +5,22 @@ package repo import ( + "container/list" + "fmt" + "path" + "github.com/codegangsta/martini" + "github.com/gogits/gogs/models" "github.com/gogits/gogs/modules/middleware" ) func Commits(ctx *middleware.Context, params martini.Params) { - brs, err := models.GetBranches(params["username"], params["reponame"]) + userName := params["username"] + repoName := params["reponame"] + branchName := params["branchname"] + + brs, err := models.GetBranches(userName, repoName) if err != nil { ctx.Handle(200, "repo.Commits", err) return @@ -20,21 +29,28 @@ func Commits(ctx *middleware.Context, params martini.Params) { return } - ctx.Data["IsRepoToolbarCommits"] = true - commits, err := models.GetCommits(params["username"], - params["reponame"], params["branchname"]) + var commits *list.List + if models.IsBranchExist(userName, repoName, branchName) { + commits, err = models.GetCommitsByBranch(userName, repoName, branchName) + } else { + commits, err = models.GetCommitsByCommitId(userName, repoName, branchName) + } + if err != nil { ctx.Handle(404, "repo.Commits", nil) return } - ctx.Data["Username"] = params["username"] - ctx.Data["Reponame"] = params["reponame"] + + ctx.Data["Username"] = userName + ctx.Data["Reponame"] = repoName ctx.Data["CommitCount"] = commits.Len() ctx.Data["Commits"] = commits + ctx.Data["IsRepoToolbarCommits"] = true ctx.HTML(200, "repo/commits") } func Diff(ctx *middleware.Context, params martini.Params) { + fmt.Println(params["branchname"]) commit, err := models.GetCommit(params["username"], params["reponame"], params["branchname"], params["commitid"]) if err != nil { ctx.Handle(404, "repo.Diff", err) @@ -47,11 +63,12 @@ func Diff(ctx *middleware.Context, params martini.Params) { return } - shortSha := params["commitid"][:7] + shortSha := params["commitid"][:10] ctx.Data["Title"] = commit.Message() + " · " + shortSha ctx.Data["Commit"] = commit ctx.Data["ShortSha"] = shortSha ctx.Data["Diff"] = diff ctx.Data["IsRepoToolbarCommits"] = true + ctx.Data["SourcePath"] = "/" + path.Join(params["username"], params["reponame"], "src", params["commitid"]) ctx.HTML(200, "repo/diff") } -- cgit v1.2.3 From 16cb1e974ca2e34384cd7882886f46f860ea5640 Mon Sep 17 00:00:00 2001 From: slene Date: Fri, 28 Mar 2014 00:13:05 +0800 Subject: print err --- models/git.go | 1 - routers/repo/commit.go | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) (limited to 'routers/repo/commit.go') diff --git a/models/git.go b/models/git.go index 6bae7248..e2ee5208 100644 --- a/models/git.go +++ b/models/git.go @@ -244,7 +244,6 @@ func GetCommitsByCommitId(userName, repoName, commitId string) (*list.List, erro if err != nil { return nil, err } - fmt.Println(userName, repoName, commitId) r, err := repo.LookupReference(commitId) if err != nil { return nil, err diff --git a/routers/repo/commit.go b/routers/repo/commit.go index 11aab67c..4a126d23 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -37,7 +37,7 @@ func Commits(ctx *middleware.Context, params martini.Params) { } if err != nil { - ctx.Handle(404, "repo.Commits", nil) + ctx.Handle(404, "repo.Commits", err) return } -- cgit v1.2.3 From 6b43067e1be051e8cd353d332d61613e18ad11f4 Mon Sep 17 00:00:00 2001 From: slene Date: Fri, 28 Mar 2014 01:17:09 +0800 Subject: image display in diff page --- routers/repo/commit.go | 34 +++++++++++++++++++++++++++++----- templates/repo/diff.tmpl | 7 +++++++ 2 files changed, 36 insertions(+), 5 deletions(-) (limited to 'routers/repo/commit.go') diff --git a/routers/repo/commit.go b/routers/repo/commit.go index 4a126d23..afc1ffda 100644 --- a/routers/repo/commit.go +++ b/routers/repo/commit.go @@ -6,12 +6,12 @@ package repo import ( "container/list" - "fmt" "path" "github.com/codegangsta/martini" "github.com/gogits/gogs/models" + "github.com/gogits/gogs/modules/base" "github.com/gogits/gogs/modules/middleware" ) @@ -50,25 +50,49 @@ func Commits(ctx *middleware.Context, params martini.Params) { } func Diff(ctx *middleware.Context, params martini.Params) { - fmt.Println(params["branchname"]) - commit, err := models.GetCommit(params["username"], params["reponame"], params["branchname"], params["commitid"]) + userName := params["username"] + repoName := params["reponame"] + branchName := params["branchname"] + commitId := params["commitid"] + + commit, err := models.GetCommit(userName, repoName, branchName, commitId) if err != nil { ctx.Handle(404, "repo.Diff", err) return } - diff, err := models.GetDiff(models.RepoPath(params["username"], params["reponame"]), params["commitid"]) + diff, err := models.GetDiff(models.RepoPath(userName, repoName), commitId) if err != nil { ctx.Handle(404, "repo.Diff", err) return } + isImageFile := func(name string) bool { + repoFile, err := models.GetTargetFile(userName, repoName, + branchName, commitId, name) + + if err != nil { + return false + } + + blob, err := repoFile.LookupBlob() + if err != nil { + return false + } + + data := blob.Contents() + _, isImage := base.IsImageFile(data) + return isImage + } + shortSha := params["commitid"][:10] + ctx.Data["IsImageFile"] = isImageFile ctx.Data["Title"] = commit.Message() + " · " + shortSha ctx.Data["Commit"] = commit ctx.Data["ShortSha"] = shortSha ctx.Data["Diff"] = diff ctx.Data["IsRepoToolbarCommits"] = true - ctx.Data["SourcePath"] = "/" + path.Join(params["username"], params["reponame"], "src", params["commitid"]) + ctx.Data["SourcePath"] = "/" + path.Join(userName, repoName, "src", commitId) + ctx.Data["RawPath"] = "/" + path.Join(userName, repoName, "raw", commitId) ctx.HTML(200, "repo/diff") } diff --git a/templates/repo/diff.tmpl b/templates/repo/diff.tmpl index 809a4873..e58f2d66 100644 --- a/templates/repo/diff.tmpl +++ b/templates/repo/diff.tmpl @@ -60,7 +60,13 @@ View File {{.Name}} + {{$isImage := (call $.IsImageFile .Name)}}
+ {{if $isImage}} +
+ +
+ {{else}} {{range .Sections}} @@ -201,6 +207,7 @@ -->
+ {{end}}
{{end}} -- cgit v1.2.3