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.

68 lines
1.7 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
  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 git
  6. import (
  7. "bytes"
  8. "io"
  9. "strings"
  10. )
  11. // ObjectType git object type
  12. type ObjectType string
  13. const (
  14. // ObjectCommit commit object type
  15. ObjectCommit ObjectType = "commit"
  16. // ObjectTree tree object type
  17. ObjectTree ObjectType = "tree"
  18. // ObjectBlob blob object type
  19. ObjectBlob ObjectType = "blob"
  20. // ObjectTag tag object type
  21. ObjectTag ObjectType = "tag"
  22. // ObjectBranch branch object type
  23. ObjectBranch ObjectType = "branch"
  24. )
  25. // Bytes returns the byte array for the Object Type
  26. func (o ObjectType) Bytes() []byte {
  27. return []byte(o)
  28. }
  29. // HashObject takes a reader and returns SHA1 hash for that reader
  30. func (repo *Repository) HashObject(reader io.Reader) (SHA1, error) {
  31. idStr, err := repo.hashObject(reader)
  32. if err != nil {
  33. return SHA1{}, err
  34. }
  35. return NewIDFromString(idStr)
  36. }
  37. func (repo *Repository) hashObject(reader io.Reader) (string, error) {
  38. cmd := NewCommand("hash-object", "-w", "--stdin")
  39. stdout := new(bytes.Buffer)
  40. stderr := new(bytes.Buffer)
  41. err := cmd.RunInDirFullPipeline(repo.Path, stdout, stderr, reader)
  42. if err != nil {
  43. return "", err
  44. }
  45. return strings.TrimSpace(stdout.String()), nil
  46. }
  47. // GetRefType gets the type of the ref based on the string
  48. func (repo *Repository) GetRefType(ref string) ObjectType {
  49. if repo.IsTagExist(ref) {
  50. return ObjectTag
  51. } else if repo.IsBranchExist(ref) {
  52. return ObjectBranch
  53. } else if repo.IsCommitExist(ref) {
  54. return ObjectCommit
  55. } else if _, err := repo.GetBlob(ref); err == nil {
  56. return ObjectBlob
  57. }
  58. return ObjectType("invalid")
  59. }