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 9.1 kB

11 years ago
11 years ago
Compare branches, commits and tags with each other (#6991) * Supports tags when comparing commits or branches Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Hide headline when only comparing and don't load unused data Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Merges compare logics to allow comparing branches, commits and tags with eachother Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Display branch or tag instead of commit when used for comparing Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show pull request form after click on button Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Transfers relevant pull.go changes from master to compare.go Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes error when comparing forks against a commit or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes console.log from JavaScript file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show icon next to commit reference when comparing branch or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Updates css file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes import order * Renames template variable * Update routers/repo/compare.go Co-Authored-By: zeripath <art27@cantab.net> * Update from master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Allow short-shas in compare * Renames prInfo to compareInfo Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Check PR permissions only if compare is pull request Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjusts comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use compareInfo instead of prInfo
6 years ago
API add/generalize pagination (#9452) * paginate results * fixed deadlock * prevented breaking change * updated swagger * go fmt * fixed find topic * go mod tidy * go mod vendor with go1.13.5 * fixed repo find topics * fixed unit test * added Limit method to Engine struct; use engine variable when provided; fixed gitignore * use ItemsPerPage for default pagesize; fix GetWatchers, getOrgUsersByOrgID and GetStargazers; fix GetAllCommits headers; reverted some changed behaviors * set Page value on Home route * improved memory allocations * fixed response headers * removed logfiles * fixed import order * import order * improved swagger * added function to get models.ListOptions from context * removed pagesize diff on unit test * fixed imports * removed unnecessary struct field * fixed go fmt * scoped PR * code improvements * code improvements * go mod tidy * fixed import order * fixed commit statuses session * fixed files headers * fixed headers; added pagination for notifications * go mod tidy * go fmt * removed Private from user search options; added setting.UI.IssuePagingNum as default valeu on repo's issues list * Apply suggestions from code review Co-Authored-By: 6543 <6543@obermui.de> Co-Authored-By: zeripath <art27@cantab.net> * fixed build error * CI.restart() * fixed merge conflicts resolve * fixed conflicts resolve * improved FindTrackedTimesOptions.ToOptions() method * added backwards compatibility on ListReleases request; fixed issue tracked time ToSession * fixed build error; fixed swagger template * fixed swagger template * fixed ListReleases backwards compatibility * added page to user search route Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: zeripath <art27@cantab.net>
5 years ago
API add/generalize pagination (#9452) * paginate results * fixed deadlock * prevented breaking change * updated swagger * go fmt * fixed find topic * go mod tidy * go mod vendor with go1.13.5 * fixed repo find topics * fixed unit test * added Limit method to Engine struct; use engine variable when provided; fixed gitignore * use ItemsPerPage for default pagesize; fix GetWatchers, getOrgUsersByOrgID and GetStargazers; fix GetAllCommits headers; reverted some changed behaviors * set Page value on Home route * improved memory allocations * fixed response headers * removed logfiles * fixed import order * import order * improved swagger * added function to get models.ListOptions from context * removed pagesize diff on unit test * fixed imports * removed unnecessary struct field * fixed go fmt * scoped PR * code improvements * code improvements * go mod tidy * fixed import order * fixed commit statuses session * fixed files headers * fixed headers; added pagination for notifications * go mod tidy * go fmt * removed Private from user search options; added setting.UI.IssuePagingNum as default valeu on repo's issues list * Apply suggestions from code review Co-Authored-By: 6543 <6543@obermui.de> Co-Authored-By: zeripath <art27@cantab.net> * fixed build error * CI.restart() * fixed merge conflicts resolve * fixed conflicts resolve * improved FindTrackedTimesOptions.ToOptions() method * added backwards compatibility on ListReleases request; fixed issue tracked time ToSession * fixed build error; fixed swagger template * fixed swagger template * fixed ListReleases backwards compatibility * added page to user search route Co-authored-by: techknowlogick <matti@mdranta.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: zeripath <art27@cantab.net>
5 years ago
Better logging (#6038) (#6095) * Panic don't fatal on create new logger Fixes #5854 Signed-off-by: Andrew Thornton <art27@cantab.net> * partial broken * Update the logging infrastrcture Signed-off-by: Andrew Thornton <art27@cantab.net> * Reset the skip levels for Fatal and Error Signed-off-by: Andrew Thornton <art27@cantab.net> * broken ncsa * More log.Error fixes Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove nal * set log-levels to lowercase * Make console_test test all levels * switch to lowercased levels * OK now working * Fix vetting issues * Fix lint * Fix tests * change default logging to match current gitea * Improve log testing Signed-off-by: Andrew Thornton <art27@cantab.net> * reset error skip levels to 0 * Update documentation and access logger configuration * Redirect the router log back to gitea if redirect macaron log but also allow setting the log level - i.e. TRACE * Fix broken level caching * Refactor the router log * Add Router logger * Add colorizing options * Adjust router colors * Only create logger if they will be used * update app.ini.sample * rename Attribute ColorAttribute * Change from white to green for function * Set fatal/error levels * Restore initial trace logger * Fix Trace arguments in modules/auth/auth.go * Properly handle XORMLogger * Improve admin/config page * fix fmt * Add auto-compression of old logs * Update error log levels * Remove the unnecessary skip argument from Error, Fatal and Critical * Add stacktrace support * Fix tests * Remove x/sync from vendors? * Add stderr option to console logger * Use filepath.ToSlash to protect against Windows in tests * Remove prefixed underscores from names in colors.go * Remove not implemented database logger This was removed from Gogs on 4 Mar 2016 but left in the configuration since then. * Ensure that log paths are relative to ROOT_PATH * use path.Join * rename jsonConfig to logConfig * Rename "config" to "jsonConfig" to make it clearer * Requested changes * Requested changes: XormLogger * Try to color the windows terminal If successful default to colorizing the console logs * fixup * Colorize initially too * update vendor * Colorize logs on default and remove if this is not a colorizing logger * Fix documentation * fix test * Use go-isatty to detect if on windows we are on msys or cygwin * Fix spelling mistake * Add missing vendors * More changes * Rationalise the ANSI writer protection * Adjust colors on advice from @0x5c * Make Flags a comma separated list * Move to use the windows constant for ENABLE_VIRTUAL_TERMINAL_PROCESSING * Ensure matching is done on the non-colored message - to simpify EXPRESSION
6 years ago
Adds side-by-side diff for images (#6784) * Adds side-by-side diff for images Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Explain blank imports Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use complete word for width and height labels on image compare Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update index.css from master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Moves ImageInfo to git commit file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Assign ImageInfo function for template and sets correct target for BeforeSourcePath Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adds missing comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return error if ImageInfo failed Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Avoid template panic when ImageInfo failed for some reason Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show file size on image diff Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes unused helper function Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Reverts copyright year change Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Close file reader Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update commit.go Sets correct data key * Moves reader.Close() up a few lines * Updates index.css * Updates CSS file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Transfers adjustments for image compare to compare.go file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjusts variable name Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Apply lesshint recommendations Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Do not show old image on image compare if it is not in index of base commit Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Change file size text Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
5 years ago
Adds side-by-side diff for images (#6784) * Adds side-by-side diff for images Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Explain blank imports Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use complete word for width and height labels on image compare Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update index.css from master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Moves ImageInfo to git commit file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Assign ImageInfo function for template and sets correct target for BeforeSourcePath Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adds missing comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Return error if ImageInfo failed Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Avoid template panic when ImageInfo failed for some reason Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show file size on image diff Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes unused helper function Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Reverts copyright year change Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Close file reader Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Update commit.go Sets correct data key * Moves reader.Close() up a few lines * Updates index.css * Updates CSS file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Transfers adjustments for image compare to compare.go file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjusts variable name Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Apply lesshint recommendations Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Do not show old image on image compare if it is not in index of base commit Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Change file size text Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com>
5 years ago
9 years ago
Improve listing performance by using go-git (#6478) * Use go-git for tree reading and commit info lookup. Signed-off-by: Filip Navara <navara@emclient.com> * Use TreeEntry.IsRegular() instead of ObjectType that was removed. Signed-off-by: Filip Navara <navara@emclient.com> * Use the treePath to optimize commit info search. Signed-off-by: Filip Navara <navara@emclient.com> * Extract the latest commit at treePath along with the other commits. Signed-off-by: Filip Navara <navara@emclient.com> * Fix listing commit info for a directory that was created in one commit and never modified after. Signed-off-by: Filip Navara <navara@emclient.com> * Avoid nearly all external 'git' invocations when doing directory listing (.editorconfig code path is still hit). Signed-off-by: Filip Navara <navara@emclient.com> * Use go-git for reading blobs. Signed-off-by: Filip Navara <navara@emclient.com> * Make SHA1 type alias for plumbing.Hash in go-git. Signed-off-by: Filip Navara <navara@emclient.com> * Make Signature type alias for object.Signature in go-git. Signed-off-by: Filip Navara <navara@emclient.com> * Fix GetCommitsInfo for repository with only one commit. Signed-off-by: Filip Navara <navara@emclient.com> * Fix PGP signature verification. Signed-off-by: Filip Navara <navara@emclient.com> * Fix issues with walking commit graph across merges. Signed-off-by: Filip Navara <navara@emclient.com> * Fix typo in condition. Signed-off-by: Filip Navara <navara@emclient.com> * Speed up loading branch list by keeping the repository reference (and thus all the loaded packfile indexes). Signed-off-by: Filip Navara <navara@emclient.com> * Fix lising submodules. Signed-off-by: Filip Navara <navara@emclient.com> * Fix build Signed-off-by: Filip Navara <navara@emclient.com> * Add back commit cache because of name-rev Signed-off-by: Filip Navara <navara@emclient.com> * Fix tests Signed-off-by: Filip Navara <navara@emclient.com> * Fix code style * Fix spelling * Address PR feedback Signed-off-by: Filip Navara <navara@emclient.com> * Update vendor module list Signed-off-by: Filip Navara <navara@emclient.com> * Fix getting trees by commit id Signed-off-by: Filip Navara <navara@emclient.com> * Fix remaining unit test failures * Fix GetTreeBySHA * Avoid running `git name-rev` if not necessary Signed-off-by: Filip Navara <navara@emclient.com> * Move Branch code to git module * Clean up GPG signature verification and fix it for tagged commits * Address PR feedback (import formatting, copyright headers) * Make blob lookup by SHA working * Update tests to use public API * Allow getting content from any type of object through the blob interface * Change test to actually expect the object content that is in the GIT repository * Change one more test to actually expect the object content that is in the GIT repository * Add comments
6 years ago
Compare branches, commits and tags with each other (#6991) * Supports tags when comparing commits or branches Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Hide headline when only comparing and don't load unused data Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Merges compare logics to allow comparing branches, commits and tags with eachother Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Display branch or tag instead of commit when used for comparing Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show pull request form after click on button Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Transfers relevant pull.go changes from master to compare.go Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes error when comparing forks against a commit or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Removes console.log from JavaScript file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Show icon next to commit reference when comparing branch or tag Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Updates css file Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Fixes import order * Renames template variable * Update routers/repo/compare.go Co-Authored-By: zeripath <art27@cantab.net> * Update from master Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Allow short-shas in compare * Renames prInfo to compareInfo Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Check PR permissions only if compare is pull request Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Adjusts comment Signed-off-by: Mario Lubenka <mario.lubenka@googlemail.com> * Use compareInfo instead of prInfo
6 years ago
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333
  1. // Copyright 2014 The Gogs Authors. All rights reserved.
  2. // Copyright 2019 The Gitea Authors. All rights reserved.
  3. // Use of this source code is governed by a MIT-style
  4. // license that can be found in the LICENSE file.
  5. package repo
  6. import (
  7. "path"
  8. "strings"
  9. "code.gitea.io/gitea/models"
  10. "code.gitea.io/gitea/modules/base"
  11. "code.gitea.io/gitea/modules/charset"
  12. "code.gitea.io/gitea/modules/context"
  13. "code.gitea.io/gitea/modules/git"
  14. "code.gitea.io/gitea/modules/gitgraph"
  15. "code.gitea.io/gitea/modules/log"
  16. "code.gitea.io/gitea/modules/setting"
  17. "code.gitea.io/gitea/services/gitdiff"
  18. )
  19. const (
  20. tplCommits base.TplName = "repo/commits"
  21. tplGraph base.TplName = "repo/graph"
  22. tplCommitPage base.TplName = "repo/commit_page"
  23. )
  24. // RefCommits render commits page
  25. func RefCommits(ctx *context.Context) {
  26. switch {
  27. case len(ctx.Repo.TreePath) == 0:
  28. Commits(ctx)
  29. case ctx.Repo.TreePath == "search":
  30. SearchCommits(ctx)
  31. default:
  32. FileHistory(ctx)
  33. }
  34. }
  35. // Commits render branch's commits
  36. func Commits(ctx *context.Context) {
  37. ctx.Data["PageIsCommits"] = true
  38. if ctx.Repo.Commit == nil {
  39. ctx.NotFound("Commit not found", nil)
  40. return
  41. }
  42. ctx.Data["PageIsViewCode"] = true
  43. commitsCount, err := ctx.Repo.GetCommitsCount()
  44. if err != nil {
  45. ctx.ServerError("GetCommitsCount", err)
  46. return
  47. }
  48. page := ctx.QueryInt("page")
  49. if page <= 1 {
  50. page = 1
  51. }
  52. pageSize := ctx.QueryInt("limit")
  53. if pageSize <= 0 {
  54. pageSize = git.CommitsRangeSize
  55. }
  56. // Both `git log branchName` and `git log commitId` work.
  57. commits, err := ctx.Repo.Commit.CommitsByRange(page, pageSize)
  58. if err != nil {
  59. ctx.ServerError("CommitsByRange", err)
  60. return
  61. }
  62. commits = models.ValidateCommitsWithEmails(commits)
  63. commits = models.ParseCommitsWithSignature(commits, ctx.Repo.Repository)
  64. commits = models.ParseCommitsWithStatus(commits, ctx.Repo.Repository)
  65. ctx.Data["Commits"] = commits
  66. ctx.Data["Username"] = ctx.Repo.Owner.Name
  67. ctx.Data["Reponame"] = ctx.Repo.Repository.Name
  68. ctx.Data["CommitCount"] = commitsCount
  69. ctx.Data["Branch"] = ctx.Repo.BranchName
  70. pager := context.NewPagination(int(commitsCount), git.CommitsRangeSize, page, 5)
  71. pager.SetDefaultParams(ctx)
  72. ctx.Data["Page"] = pager
  73. ctx.HTML(200, tplCommits)
  74. }
  75. // Graph render commit graph - show commits from all branches.
  76. func Graph(ctx *context.Context) {
  77. ctx.Data["PageIsCommits"] = true
  78. ctx.Data["PageIsViewCode"] = true
  79. commitsCount, err := ctx.Repo.GetCommitsCount()
  80. if err != nil {
  81. ctx.ServerError("GetCommitsCount", err)
  82. return
  83. }
  84. allCommitsCount, err := ctx.Repo.GitRepo.GetAllCommitsCount()
  85. if err != nil {
  86. ctx.ServerError("GetAllCommitsCount", err)
  87. return
  88. }
  89. page := ctx.QueryInt("page")
  90. graph, err := gitgraph.GetCommitGraph(ctx.Repo.GitRepo, page)
  91. if err != nil {
  92. ctx.ServerError("GetCommitGraph", err)
  93. return
  94. }
  95. ctx.Data["Graph"] = graph
  96. ctx.Data["Username"] = ctx.Repo.Owner.Name
  97. ctx.Data["Reponame"] = ctx.Repo.Repository.Name
  98. ctx.Data["CommitCount"] = commitsCount
  99. ctx.Data["Branch"] = ctx.Repo.BranchName
  100. ctx.Data["Page"] = context.NewPagination(int(allCommitsCount), setting.UI.GraphMaxCommitNum, page, 5)
  101. ctx.HTML(200, tplGraph)
  102. }
  103. // SearchCommits render commits filtered by keyword
  104. func SearchCommits(ctx *context.Context) {
  105. ctx.Data["PageIsCommits"] = true
  106. ctx.Data["PageIsViewCode"] = true
  107. query := strings.Trim(ctx.Query("q"), " ")
  108. if len(query) == 0 {
  109. ctx.Redirect(ctx.Repo.RepoLink + "/commits/" + ctx.Repo.BranchNameSubURL())
  110. return
  111. }
  112. all := ctx.QueryBool("all")
  113. opts := git.NewSearchCommitsOptions(query, all)
  114. commits, err := ctx.Repo.Commit.SearchCommits(opts)
  115. if err != nil {
  116. ctx.ServerError("SearchCommits", err)
  117. return
  118. }
  119. commits = models.ValidateCommitsWithEmails(commits)
  120. commits = models.ParseCommitsWithSignature(commits, ctx.Repo.Repository)
  121. commits = models.ParseCommitsWithStatus(commits, ctx.Repo.Repository)
  122. ctx.Data["Commits"] = commits
  123. ctx.Data["Keyword"] = query
  124. if all {
  125. ctx.Data["All"] = "checked"
  126. }
  127. ctx.Data["Username"] = ctx.Repo.Owner.Name
  128. ctx.Data["Reponame"] = ctx.Repo.Repository.Name
  129. ctx.Data["CommitCount"] = commits.Len()
  130. ctx.Data["Branch"] = ctx.Repo.BranchName
  131. ctx.HTML(200, tplCommits)
  132. }
  133. // FileHistory show a file's reversions
  134. func FileHistory(ctx *context.Context) {
  135. ctx.Data["IsRepoToolbarCommits"] = true
  136. fileName := ctx.Repo.TreePath
  137. if len(fileName) == 0 {
  138. Commits(ctx)
  139. return
  140. }
  141. branchName := ctx.Repo.BranchName
  142. commitsCount, err := ctx.Repo.GitRepo.FileCommitsCount(branchName, fileName)
  143. if err != nil {
  144. ctx.ServerError("FileCommitsCount", err)
  145. return
  146. } else if commitsCount == 0 {
  147. ctx.NotFound("FileCommitsCount", nil)
  148. return
  149. }
  150. page := ctx.QueryInt("page")
  151. if page <= 1 {
  152. page = 1
  153. }
  154. commits, err := ctx.Repo.GitRepo.CommitsByFileAndRange(branchName, fileName, page)
  155. if err != nil {
  156. ctx.ServerError("CommitsByFileAndRange", err)
  157. return
  158. }
  159. commits = models.ValidateCommitsWithEmails(commits)
  160. commits = models.ParseCommitsWithSignature(commits, ctx.Repo.Repository)
  161. commits = models.ParseCommitsWithStatus(commits, ctx.Repo.Repository)
  162. ctx.Data["Commits"] = commits
  163. ctx.Data["Username"] = ctx.Repo.Owner.Name
  164. ctx.Data["Reponame"] = ctx.Repo.Repository.Name
  165. ctx.Data["FileName"] = fileName
  166. ctx.Data["CommitCount"] = commitsCount
  167. ctx.Data["Branch"] = branchName
  168. pager := context.NewPagination(int(commitsCount), git.CommitsRangeSize, page, 5)
  169. pager.SetDefaultParams(ctx)
  170. ctx.Data["Page"] = pager
  171. ctx.HTML(200, tplCommits)
  172. }
  173. // Diff show different from current commit to previous commit
  174. func Diff(ctx *context.Context) {
  175. ctx.Data["PageIsDiff"] = true
  176. ctx.Data["RequireHighlightJS"] = true
  177. ctx.Data["RequireSimpleMDE"] = true
  178. ctx.Data["RequireTribute"] = true
  179. userName := ctx.Repo.Owner.Name
  180. repoName := ctx.Repo.Repository.Name
  181. commitID := ctx.Params(":sha")
  182. var (
  183. gitRepo *git.Repository
  184. err error
  185. repoPath string
  186. )
  187. if ctx.Data["PageIsWiki"] != nil {
  188. gitRepo, err = git.OpenRepository(ctx.Repo.Repository.WikiPath())
  189. if err != nil {
  190. ctx.ServerError("Repo.GitRepo.GetCommit", err)
  191. return
  192. }
  193. repoPath = ctx.Repo.Repository.WikiPath()
  194. } else {
  195. gitRepo = ctx.Repo.GitRepo
  196. repoPath = models.RepoPath(userName, repoName)
  197. }
  198. commit, err := gitRepo.GetCommit(commitID)
  199. if err != nil {
  200. if git.IsErrNotExist(err) {
  201. ctx.NotFound("Repo.GitRepo.GetCommit", err)
  202. } else {
  203. ctx.ServerError("Repo.GitRepo.GetCommit", err)
  204. }
  205. return
  206. }
  207. if len(commitID) != 40 {
  208. commitID = commit.ID.String()
  209. }
  210. statuses, err := models.GetLatestCommitStatus(ctx.Repo.Repository, commitID, 0)
  211. if err != nil {
  212. log.Error("GetLatestCommitStatus: %v", err)
  213. }
  214. ctx.Data["CommitStatus"] = models.CalcCommitStatus(statuses)
  215. diff, err := gitdiff.GetDiffCommit(repoPath,
  216. commitID, setting.Git.MaxGitDiffLines,
  217. setting.Git.MaxGitDiffLineCharacters, setting.Git.MaxGitDiffFiles)
  218. if err != nil {
  219. ctx.NotFound("GetDiffCommit", err)
  220. return
  221. }
  222. parents := make([]string, commit.ParentCount())
  223. for i := 0; i < commit.ParentCount(); i++ {
  224. sha, err := commit.ParentID(i)
  225. if err != nil {
  226. ctx.NotFound("repo.Diff", err)
  227. return
  228. }
  229. parents[i] = sha.String()
  230. }
  231. ctx.Data["CommitID"] = commitID
  232. ctx.Data["AfterCommitID"] = commitID
  233. ctx.Data["Username"] = userName
  234. ctx.Data["Reponame"] = repoName
  235. var parentCommit *git.Commit
  236. if commit.ParentCount() > 0 {
  237. parentCommit, err = gitRepo.GetCommit(parents[0])
  238. if err != nil {
  239. ctx.NotFound("GetParentCommit", err)
  240. return
  241. }
  242. }
  243. setImageCompareContext(ctx, parentCommit, commit)
  244. headTarget := path.Join(userName, repoName)
  245. setPathsCompareContext(ctx, parentCommit, commit, headTarget)
  246. ctx.Data["Title"] = commit.Summary() + " · " + base.ShortSha(commitID)
  247. ctx.Data["Commit"] = commit
  248. verification := models.ParseCommitWithSignature(commit)
  249. ctx.Data["Verification"] = verification
  250. ctx.Data["Author"] = models.ValidateCommitWithEmail(commit)
  251. ctx.Data["Diff"] = diff
  252. ctx.Data["Parents"] = parents
  253. ctx.Data["DiffNotAvailable"] = diff.NumFiles() == 0
  254. if err := models.CalculateTrustStatus(verification, ctx.Repo.Repository, nil); err != nil {
  255. ctx.ServerError("CalculateTrustStatus", err)
  256. return
  257. }
  258. note := &git.Note{}
  259. err = git.GetNote(ctx.Repo.GitRepo, commitID, note)
  260. if err == nil {
  261. ctx.Data["Note"] = string(charset.ToUTF8WithFallback(note.Message))
  262. ctx.Data["NoteCommit"] = note.Commit
  263. ctx.Data["NoteAuthor"] = models.ValidateCommitWithEmail(note.Commit)
  264. }
  265. ctx.Data["BranchName"], err = commit.GetBranchName()
  266. if err != nil {
  267. ctx.ServerError("commit.GetBranchName", err)
  268. }
  269. ctx.HTML(200, tplCommitPage)
  270. }
  271. // RawDiff dumps diff results of repository in given commit ID to io.Writer
  272. func RawDiff(ctx *context.Context) {
  273. var repoPath string
  274. if ctx.Data["PageIsWiki"] != nil {
  275. repoPath = ctx.Repo.Repository.WikiPath()
  276. } else {
  277. repoPath = models.RepoPath(ctx.Repo.Owner.Name, ctx.Repo.Repository.Name)
  278. }
  279. if err := git.GetRawDiff(
  280. repoPath,
  281. ctx.Params(":sha"),
  282. git.RawDiffType(ctx.Params(":ext")),
  283. ctx.Resp,
  284. ); err != nil {
  285. ctx.ServerError("GetRawDiff", err)
  286. return
  287. }
  288. }