A fork of Gitea (see branch `mj`) adding Majority Judgment Polls 𐄷 over Issues and Merge Requests. https://git.mieuxvoter.fr
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.

106 lines
2.5 KiB

Use native git variants by default with go-git variants as build tag (#13673) * Move last commit cache back into modules/git Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove go-git from the interface for last commit cache Signed-off-by: Andrew Thornton <art27@cantab.net> * move cacheref to last_commit_cache Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove go-git from routers/private/hook Signed-off-by: Andrew Thornton <art27@cantab.net> * Move FindLFSFiles to pipeline Signed-off-by: Andrew Thornton <art27@cantab.net> * Make no-go-git variants Signed-off-by: Andrew Thornton <art27@cantab.net> * Submodule RefID Signed-off-by: Andrew Thornton <art27@cantab.net> * fix issue with GetCommitsInfo Signed-off-by: Andrew Thornton <art27@cantab.net> * fix GetLastCommitForPaths Signed-off-by: Andrew Thornton <art27@cantab.net> * Improve efficiency Signed-off-by: Andrew Thornton <art27@cantab.net> * More efficiency Signed-off-by: Andrew Thornton <art27@cantab.net> * even faster Signed-off-by: Andrew Thornton <art27@cantab.net> * Reduce duplication * As per @lunny Signed-off-by: Andrew Thornton <art27@cantab.net> * attempt to fix drone Signed-off-by: Andrew Thornton <art27@cantab.net> * fix test-tags Signed-off-by: Andrew Thornton <art27@cantab.net> * default to use no-go-git variants and add gogit build tag Signed-off-by: Andrew Thornton <art27@cantab.net> * placate lint Signed-off-by: Andrew Thornton <art27@cantab.net> * as per @6543 Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
2 years ago
Use native git variants by default with go-git variants as build tag (#13673) * Move last commit cache back into modules/git Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove go-git from the interface for last commit cache Signed-off-by: Andrew Thornton <art27@cantab.net> * move cacheref to last_commit_cache Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove go-git from routers/private/hook Signed-off-by: Andrew Thornton <art27@cantab.net> * Move FindLFSFiles to pipeline Signed-off-by: Andrew Thornton <art27@cantab.net> * Make no-go-git variants Signed-off-by: Andrew Thornton <art27@cantab.net> * Submodule RefID Signed-off-by: Andrew Thornton <art27@cantab.net> * fix issue with GetCommitsInfo Signed-off-by: Andrew Thornton <art27@cantab.net> * fix GetLastCommitForPaths Signed-off-by: Andrew Thornton <art27@cantab.net> * Improve efficiency Signed-off-by: Andrew Thornton <art27@cantab.net> * More efficiency Signed-off-by: Andrew Thornton <art27@cantab.net> * even faster Signed-off-by: Andrew Thornton <art27@cantab.net> * Reduce duplication * As per @lunny Signed-off-by: Andrew Thornton <art27@cantab.net> * attempt to fix drone Signed-off-by: Andrew Thornton <art27@cantab.net> * fix test-tags Signed-off-by: Andrew Thornton <art27@cantab.net> * default to use no-go-git variants and add gogit build tag Signed-off-by: Andrew Thornton <art27@cantab.net> * placate lint Signed-off-by: Andrew Thornton <art27@cantab.net> * as per @6543 Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
2 years ago
Use native git variants by default with go-git variants as build tag (#13673) * Move last commit cache back into modules/git Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove go-git from the interface for last commit cache Signed-off-by: Andrew Thornton <art27@cantab.net> * move cacheref to last_commit_cache Signed-off-by: Andrew Thornton <art27@cantab.net> * Remove go-git from routers/private/hook Signed-off-by: Andrew Thornton <art27@cantab.net> * Move FindLFSFiles to pipeline Signed-off-by: Andrew Thornton <art27@cantab.net> * Make no-go-git variants Signed-off-by: Andrew Thornton <art27@cantab.net> * Submodule RefID Signed-off-by: Andrew Thornton <art27@cantab.net> * fix issue with GetCommitsInfo Signed-off-by: Andrew Thornton <art27@cantab.net> * fix GetLastCommitForPaths Signed-off-by: Andrew Thornton <art27@cantab.net> * Improve efficiency Signed-off-by: Andrew Thornton <art27@cantab.net> * More efficiency Signed-off-by: Andrew Thornton <art27@cantab.net> * even faster Signed-off-by: Andrew Thornton <art27@cantab.net> * Reduce duplication * As per @lunny Signed-off-by: Andrew Thornton <art27@cantab.net> * attempt to fix drone Signed-off-by: Andrew Thornton <art27@cantab.net> * fix test-tags Signed-off-by: Andrew Thornton <art27@cantab.net> * default to use no-go-git variants and add gogit build tag Signed-off-by: Andrew Thornton <art27@cantab.net> * placate lint Signed-off-by: Andrew Thornton <art27@cantab.net> * as per @6543 Signed-off-by: Andrew Thornton <art27@cantab.net> Co-authored-by: 6543 <6543@obermui.de> Co-authored-by: techknowlogick <techknowlogick@gitea.io>
2 years ago
  1. // Copyright 2015 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 git
  5. import (
  6. "bytes"
  7. "sort"
  8. "strings"
  9. )
  10. const beginpgp = "\n-----BEGIN PGP SIGNATURE-----\n"
  11. const endpgp = "\n-----END PGP SIGNATURE-----"
  12. // Tag represents a Git tag.
  13. type Tag struct {
  14. Name string
  15. ID SHA1
  16. repo *Repository
  17. Object SHA1 // The id of this commit object
  18. Type string
  19. Tagger *Signature
  20. Message string
  21. Signature *CommitGPGSignature
  22. }
  23. // Commit return the commit of the tag reference
  24. func (tag *Tag) Commit() (*Commit, error) {
  25. return tag.repo.getCommit(tag.Object)
  26. }
  27. // Parse commit information from the (uncompressed) raw
  28. // data from the commit object.
  29. // \n\n separate headers from message
  30. func parseTagData(data []byte) (*Tag, error) {
  31. tag := new(Tag)
  32. tag.Tagger = &Signature{}
  33. // we now have the contents of the commit object. Let's investigate...
  34. nextline := 0
  35. l:
  36. for {
  37. eol := bytes.IndexByte(data[nextline:], '\n')
  38. switch {
  39. case eol > 0:
  40. line := data[nextline : nextline+eol]
  41. spacepos := bytes.IndexByte(line, ' ')
  42. reftype := line[:spacepos]
  43. switch string(reftype) {
  44. case "object":
  45. id, err := NewIDFromString(string(line[spacepos+1:]))
  46. if err != nil {
  47. return nil, err
  48. }
  49. tag.Object = id
  50. case "type":
  51. // A commit can have one or more parents
  52. tag.Type = string(line[spacepos+1:])
  53. case "tagger":
  54. sig, err := newSignatureFromCommitline(line[spacepos+1:])
  55. if err != nil {
  56. return nil, err
  57. }
  58. tag.Tagger = sig
  59. }
  60. nextline += eol + 1
  61. case eol == 0:
  62. tag.Message = string(data[nextline+1:])
  63. break l
  64. default:
  65. break l
  66. }
  67. }
  68. idx := strings.LastIndex(tag.Message, beginpgp)
  69. if idx > 0 {
  70. endSigIdx := strings.Index(tag.Message[idx:], endpgp)
  71. if endSigIdx > 0 {
  72. tag.Signature = &CommitGPGSignature{
  73. Signature: tag.Message[idx+1 : idx+endSigIdx+len(endpgp)],
  74. Payload: string(data[:bytes.LastIndex(data, []byte(beginpgp))+1]),
  75. }
  76. tag.Message = tag.Message[:idx+1]
  77. }
  78. }
  79. return tag, nil
  80. }
  81. type tagSorter []*Tag
  82. func (ts tagSorter) Len() int {
  83. return len([]*Tag(ts))
  84. }
  85. func (ts tagSorter) Less(i, j int) bool {
  86. return []*Tag(ts)[i].Tagger.When.After([]*Tag(ts)[j].Tagger.When)
  87. }
  88. func (ts tagSorter) Swap(i, j int) {
  89. []*Tag(ts)[i], []*Tag(ts)[j] = []*Tag(ts)[j], []*Tag(ts)[i]
  90. }
  91. // sortTagsByTime
  92. func sortTagsByTime(tags []*Tag) {
  93. sorter := tagSorter(tags)
  94. sort.Sort(sorter)
  95. }