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.

93 lines
1.8 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
  1. // Copyright 2020 The Gitea 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. // +build !gogit
  5. package git
  6. import (
  7. "strconv"
  8. "strings"
  9. )
  10. // TreeEntry the leaf in the git tree
  11. type TreeEntry struct {
  12. ID SHA1
  13. ptree *Tree
  14. entryMode EntryMode
  15. name string
  16. size int64
  17. sized bool
  18. fullName string
  19. }
  20. // Name returns the name of the entry
  21. func (te *TreeEntry) Name() string {
  22. if te.fullName != "" {
  23. return te.fullName
  24. }
  25. return te.name
  26. }
  27. // Mode returns the mode of the entry
  28. func (te *TreeEntry) Mode() EntryMode {
  29. return te.entryMode
  30. }
  31. // Size returns the size of the entry
  32. func (te *TreeEntry) Size() int64 {
  33. if te.IsDir() {
  34. return 0
  35. } else if te.sized {
  36. return te.size
  37. }
  38. stdout, err := NewCommand("cat-file", "-s", te.ID.String()).RunInDir(te.ptree.repo.Path)
  39. if err != nil {
  40. return 0
  41. }
  42. te.sized = true
  43. te.size, _ = strconv.ParseInt(strings.TrimSpace(stdout), 10, 64)
  44. return te.size
  45. }
  46. // IsSubModule if the entry is a sub module
  47. func (te *TreeEntry) IsSubModule() bool {
  48. return te.entryMode == EntryModeCommit
  49. }
  50. // IsDir if the entry is a sub dir
  51. func (te *TreeEntry) IsDir() bool {
  52. return te.entryMode == EntryModeTree
  53. }
  54. // IsLink if the entry is a symlink
  55. func (te *TreeEntry) IsLink() bool {
  56. return te.entryMode == EntryModeSymlink
  57. }
  58. // IsRegular if the entry is a regular file
  59. func (te *TreeEntry) IsRegular() bool {
  60. return te.entryMode == EntryModeBlob
  61. }
  62. // IsExecutable if the entry is an executable file (not necessarily binary)
  63. func (te *TreeEntry) IsExecutable() bool {
  64. return te.entryMode == EntryModeExec
  65. }
  66. // Blob returns the blob object the entry
  67. func (te *TreeEntry) Blob() *Blob {
  68. return &Blob{
  69. ID: te.ID,
  70. repoPath: te.ptree.repo.Path,
  71. name: te.Name(),
  72. size: te.size,
  73. gotSize: te.sized,
  74. }
  75. }