Git with a cup of tea, painless self-hosted git service Mirror for internal git.with.parts use https://git.with.parts
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
gitea/routers/repo/commit.go

75 lines
2.0 KiB

11 years ago
// 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 repo
import (
"container/list"
"fmt"
"path"
11 years ago
"github.com/codegangsta/martini"
11 years ago
"github.com/gogits/gogs/models"
"github.com/gogits/gogs/modules/middleware"
)
func Commits(ctx *middleware.Context, params martini.Params) {
userName := params["username"]
repoName := params["reponame"]
branchName := params["branchname"]
brs, err := models.GetBranches(userName, repoName)
11 years ago
if err != nil {
ctx.Handle(200, "repo.Commits", err)
return
} else if len(brs) == 0 {
ctx.Handle(404, "repo.Commits", nil)
return
}
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)
}
11 years ago
if err != nil {
ctx.Handle(404, "repo.Commits", nil)
return
}
ctx.Data["Username"] = userName
ctx.Data["Reponame"] = repoName
11 years ago
ctx.Data["CommitCount"] = commits.Len()
ctx.Data["Commits"] = commits
ctx.Data["IsRepoToolbarCommits"] = true
11 years ago
ctx.HTML(200, "repo/commits")
}
11 years ago
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)
return
}
diff, err := models.GetDiff(models.RepoPath(params["username"], params["reponame"]), params["commitid"])
if err != nil {
ctx.Handle(404, "repo.Diff", err)
return
}
shortSha := params["commitid"][:10]
ctx.Data["Title"] = commit.Message() + " · " + shortSha
ctx.Data["Commit"] = commit
ctx.Data["ShortSha"] = shortSha
ctx.Data["Diff"] = diff
11 years ago
ctx.Data["IsRepoToolbarCommits"] = true
ctx.Data["SourcePath"] = "/" + path.Join(params["username"], params["reponame"], "src", params["commitid"])
ctx.HTML(200, "repo/diff")
11 years ago
}