aboutsummaryrefslogtreecommitdiffstats
path: root/modules/git/tree_nogogit.go
diff options
context:
space:
mode:
authorzeripath <art27@cantab.net>2021-05-10 02:27:03 +0100
committerGitHub <noreply@github.com>2021-05-10 03:27:03 +0200
commit270aab429ef025df9a0b9bf9e3982729ae8df449 (patch)
tree215550ee5938876d4caf8516777d6f4bcaa91b40 /modules/git/tree_nogogit.go
parent038e1db4dfc7a7fc0a8675f66f6be9a3dd5f10c2 (diff)
downloadgitea-270aab429ef025df9a0b9bf9e3982729ae8df449.tar.gz
gitea-270aab429ef025df9a0b9bf9e3982729ae8df449.zip
On open repository open common cat file batch and batch-check (#15667)
Use common git cat-file --batch and git cat-file --batch-check to significantly reduce calls to git. Signed-off-by: Andrew Thornton <art27@cantab.net>
Diffstat (limited to 'modules/git/tree_nogogit.go')
-rw-r--r--modules/git/tree_nogogit.go48
1 files changed, 48 insertions, 0 deletions
diff --git a/modules/git/tree_nogogit.go b/modules/git/tree_nogogit.go
index 3ebdf10631..9661d8faea 100644
--- a/modules/git/tree_nogogit.go
+++ b/modules/git/tree_nogogit.go
@@ -7,6 +7,8 @@
package git
import (
+ "io"
+ "math"
"strings"
)
@@ -32,6 +34,52 @@ func (t *Tree) ListEntries() (Entries, error) {
return t.entries, nil
}
+ if t.repo != nil {
+ wr, rd, cancel := t.repo.CatFileBatch()
+ defer cancel()
+
+ _, _ = wr.Write([]byte(t.ID.String() + "\n"))
+ _, typ, sz, err := ReadBatchLine(rd)
+ if err != nil {
+ return nil, err
+ }
+ if typ == "commit" {
+ treeID, err := ReadTreeID(rd, sz)
+ if err != nil && err != io.EOF {
+ return nil, err
+ }
+ _, _ = wr.Write([]byte(treeID + "\n"))
+ _, typ, sz, err = ReadBatchLine(rd)
+ if err != nil {
+ return nil, err
+ }
+ }
+ if typ == "tree" {
+ t.entries, err = catBatchParseTreeEntries(t, rd, sz)
+ if err != nil {
+ return nil, err
+ }
+ t.entriesParsed = true
+ return t.entries, nil
+ }
+
+ // Not a tree just use ls-tree instead
+ for sz > math.MaxInt32 {
+ discarded, err := rd.Discard(math.MaxInt32)
+ sz -= int64(discarded)
+ if err != nil {
+ return nil, err
+ }
+ }
+ for sz > 0 {
+ discarded, err := rd.Discard(int(sz))
+ sz -= int64(discarded)
+ if err != nil {
+ return nil, err
+ }
+ }
+ }
+
stdout, err := NewCommand("ls-tree", "-l", t.ID.String()).RunInDirBytes(t.repo.Path)
if err != nil {
if strings.Contains(err.Error(), "fatal: Not a valid object name") || strings.Contains(err.Error(), "fatal: not a tree object") {