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.

57 lines
1.4 KiB

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
4 years ago
  1. // Copyright 2015 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. "encoding/hex"
  8. "fmt"
  9. "regexp"
  10. "strings"
  11. )
  12. // EmptySHA defines empty git SHA
  13. const EmptySHA = "0000000000000000000000000000000000000000"
  14. // EmptyTreeSHA is the SHA of an empty tree
  15. const EmptyTreeSHA = "4b825dc642cb6eb9a060e54bf8d69288fbee4904"
  16. // SHAPattern can be used to determine if a string is an valid sha
  17. var SHAPattern = regexp.MustCompile(`^[0-9a-f]{4,40}$`)
  18. // MustID always creates a new SHA1 from a [20]byte array with no validation of input.
  19. func MustID(b []byte) SHA1 {
  20. var id SHA1
  21. copy(id[:], b)
  22. return id
  23. }
  24. // NewID creates a new SHA1 from a [20]byte array.
  25. func NewID(b []byte) (SHA1, error) {
  26. if len(b) != 20 {
  27. return SHA1{}, fmt.Errorf("Length must be 20: %v", b)
  28. }
  29. return MustID(b), nil
  30. }
  31. // MustIDFromString always creates a new sha from a ID with no validation of input.
  32. func MustIDFromString(s string) SHA1 {
  33. b, _ := hex.DecodeString(s)
  34. return MustID(b)
  35. }
  36. // NewIDFromString creates a new SHA1 from a ID string of length 40.
  37. func NewIDFromString(s string) (SHA1, error) {
  38. var id SHA1
  39. s = strings.TrimSpace(s)
  40. if len(s) != 40 {
  41. return id, fmt.Errorf("Length must be 40: %s", s)
  42. }
  43. b, err := hex.DecodeString(s)
  44. if err != nil {
  45. return id, err
  46. }
  47. return NewID(b)
  48. }