summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--routers/repo/commit.go34
-rw-r--r--templates/repo/diff.tmpl7
2 files changed, 36 insertions, 5 deletions
diff --git a/routers/repo/commit.go b/routers/repo/commit.go
index 4a126d236b..afc1ffda29 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 809a4873c3..e58f2d664e 100644
--- a/templates/repo/diff.tmpl
+++ b/templates/repo/diff.tmpl
@@ -60,7 +60,13 @@
<a class="btn btn-default btn-sm pull-right" href="{{$.SourcePath}}/{{.Name}}">View File</a>
<span class="file">{{.Name}}</span>
</div>
+ {{$isImage := (call $.IsImageFile .Name)}}
<div class="panel-body file-body file-code code-view code-diff">
+ {{if $isImage}}
+ <div class="text-center">
+ <img src="{{$.RawPath}}/{{.Name}}">
+ </div>
+ {{else}}
<table>
<tbody>
{{range .Sections}}
@@ -201,6 +207,7 @@
</tr> -->
</tbody>
</table>
+ {{end}}
</div>
</div>
{{end}}