You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

commit.go 2.5 kB

11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
11 years ago
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  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. "container/list"
  7. "path"
  8. "github.com/codegangsta/martini"
  9. "github.com/gogits/gogs/models"
  10. "github.com/gogits/gogs/modules/base"
  11. "github.com/gogits/gogs/modules/middleware"
  12. )
  13. func Commits(ctx *middleware.Context, params martini.Params) {
  14. userName := params["username"]
  15. repoName := params["reponame"]
  16. branchName := params["branchname"]
  17. brs, err := models.GetBranches(userName, repoName)
  18. if err != nil {
  19. ctx.Handle(200, "repo.Commits", err)
  20. return
  21. } else if len(brs) == 0 {
  22. ctx.Handle(404, "repo.Commits", nil)
  23. return
  24. }
  25. var commits *list.List
  26. if models.IsBranchExist(userName, repoName, branchName) {
  27. commits, err = models.GetCommitsByBranch(userName, repoName, branchName)
  28. } else {
  29. commits, err = models.GetCommitsByCommitId(userName, repoName, branchName)
  30. }
  31. if err != nil {
  32. ctx.Handle(404, "repo.Commits", err)
  33. return
  34. }
  35. ctx.Data["Username"] = userName
  36. ctx.Data["Reponame"] = repoName
  37. ctx.Data["CommitCount"] = commits.Len()
  38. ctx.Data["Commits"] = commits
  39. ctx.Data["IsRepoToolbarCommits"] = true
  40. ctx.HTML(200, "repo/commits")
  41. }
  42. func Diff(ctx *middleware.Context, params martini.Params) {
  43. userName := params["username"]
  44. repoName := params["reponame"]
  45. branchName := params["branchname"]
  46. commitId := params["commitid"]
  47. commit, err := models.GetCommit(userName, repoName, branchName, commitId)
  48. if err != nil {
  49. ctx.Handle(404, "repo.Diff", err)
  50. return
  51. }
  52. diff, err := models.GetDiff(models.RepoPath(userName, repoName), commitId)
  53. if err != nil {
  54. ctx.Handle(404, "repo.Diff", err)
  55. return
  56. }
  57. isImageFile := func(name string) bool {
  58. repoFile, err := models.GetTargetFile(userName, repoName,
  59. branchName, commitId, name)
  60. if err != nil {
  61. return false
  62. }
  63. blob, err := repoFile.LookupBlob()
  64. if err != nil {
  65. return false
  66. }
  67. data := blob.Contents()
  68. _, isImage := base.IsImageFile(data)
  69. return isImage
  70. }
  71. shortSha := params["commitid"][:10]
  72. ctx.Data["IsImageFile"] = isImageFile
  73. ctx.Data["Title"] = commit.Message() + " · " + shortSha
  74. ctx.Data["Commit"] = commit
  75. ctx.Data["ShortSha"] = shortSha
  76. ctx.Data["Diff"] = diff
  77. ctx.Data["IsRepoToolbarCommits"] = true
  78. ctx.Data["SourcePath"] = "/" + path.Join(userName, repoName, "src", commitId)
  79. ctx.Data["RawPath"] = "/" + path.Join(userName, repoName, "raw", commitId)
  80. ctx.HTML(200, "repo/diff")
  81. }