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.

92 lines
2.3 KiB

10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
10 years ago
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. "container/list"
  7. "path"
  8. "github.com/go-martini/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 := ctx.Repo.Owner.Name
  44. repoName := ctx.Repo.Repository.Name
  45. branchName := ctx.Repo.BranchName
  46. commitId := ctx.Repo.CommitId
  47. commit := ctx.Repo.Commit
  48. diff, err := models.GetDiff(models.RepoPath(userName, repoName), commitId)
  49. if err != nil {
  50. ctx.Handle(404, "repo.Diff", err)
  51. return
  52. }
  53. isImageFile := func(name string) bool {
  54. repoFile, err := models.GetTargetFile(userName, repoName,
  55. branchName, commitId, name)
  56. if err != nil {
  57. return false
  58. }
  59. blob, err := repoFile.LookupBlob()
  60. if err != nil {
  61. return false
  62. }
  63. data := blob.Contents()
  64. _, isImage := base.IsImageFile(data)
  65. return isImage
  66. }
  67. ctx.Data["IsImageFile"] = isImageFile
  68. ctx.Data["Title"] = commit.Message() + " · " + base.ShortSha(commitId)
  69. ctx.Data["Commit"] = commit
  70. ctx.Data["Diff"] = diff
  71. ctx.Data["IsRepoToolbarCommits"] = true
  72. ctx.Data["SourcePath"] = "/" + path.Join(userName, repoName, "src", commitId)
  73. ctx.Data["RawPath"] = "/" + path.Join(userName, repoName, "raw", commitId)
  74. ctx.HTML(200, "repo/diff")
  75. }