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.

57 lines
1.6 KiB

10 years ago
10 years ago
10 years ago
10 years ago
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Use of this source code is governed by a MIT-style
  3. // license that can be found in the LICENSE file.
  4. package repo
  5. import (
  6. "github.com/codegangsta/martini"
  7. "github.com/gogits/gogs/models"
  8. "github.com/gogits/gogs/modules/middleware"
  9. )
  10. func Commits(ctx *middleware.Context, params martini.Params) {
  11. brs, err := models.GetBranches(params["username"], params["reponame"])
  12. if err != nil {
  13. ctx.Handle(200, "repo.Commits", err)
  14. return
  15. } else if len(brs) == 0 {
  16. ctx.Handle(404, "repo.Commits", nil)
  17. return
  18. }
  19. ctx.Data["IsRepoToolbarCommits"] = true
  20. commits, err := models.GetCommits(params["username"],
  21. params["reponame"], params["branchname"])
  22. if err != nil {
  23. ctx.Handle(404, "repo.Commits", nil)
  24. return
  25. }
  26. ctx.Data["Username"] = params["username"]
  27. ctx.Data["Reponame"] = params["reponame"]
  28. ctx.Data["CommitCount"] = commits.Len()
  29. ctx.Data["Commits"] = commits
  30. ctx.HTML(200, "repo/commits")
  31. }
  32. func Diff(ctx *middleware.Context, params martini.Params) {
  33. commit, err := models.GetCommit(params["username"], params["reponame"], params["branchname"], params["commitid"])
  34. if err != nil {
  35. ctx.Handle(404, "repo.Diff", err)
  36. return
  37. }
  38. diff, err := models.GetDiff(models.RepoPath(params["username"], params["reponame"]), params["commitid"])
  39. if err != nil {
  40. ctx.Handle(404, "repo.Diff", err)
  41. return
  42. }
  43. shortSha := params["commitid"][:7]
  44. ctx.Data["Title"] = commit.Message() + " · " + shortSha
  45. ctx.Data["Commit"] = commit
  46. ctx.Data["ShortSha"] = shortSha
  47. ctx.Data["Diff"] = diff
  48. ctx.Data["IsRepoToolbarCommits"] = true
  49. ctx.HTML(200, "repo/diff")
  50. }