diff options
author | zeripath <art27@cantab.net> | 2021-05-10 02:27:03 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-10 03:27:03 +0200 |
commit | 270aab429ef025df9a0b9bf9e3982729ae8df449 (patch) | |
tree | 215550ee5938876d4caf8516777d6f4bcaa91b40 /modules/git/parse_nogogit.go | |
parent | 038e1db4dfc7a7fc0a8675f66f6be9a3dd5f10c2 (diff) | |
download | gitea-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/parse_nogogit.go')
-rw-r--r-- | modules/git/parse_nogogit.go | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/modules/git/parse_nogogit.go b/modules/git/parse_nogogit.go index e9e93f66fd..b45b31f239 100644 --- a/modules/git/parse_nogogit.go +++ b/modules/git/parse_nogogit.go @@ -7,8 +7,10 @@ package git import ( + "bufio" "bytes" "fmt" + "io" "strconv" "strings" ) @@ -86,3 +88,49 @@ func parseTreeEntries(data []byte, ptree *Tree) ([]*TreeEntry, error) { } return entries, nil } + +func catBatchParseTreeEntries(ptree *Tree, rd *bufio.Reader, sz int64) ([]*TreeEntry, error) { + fnameBuf := make([]byte, 4096) + modeBuf := make([]byte, 40) + shaBuf := make([]byte, 40) + entries := make([]*TreeEntry, 0, 10) + +loop: + for sz > 0 { + mode, fname, sha, count, err := ParseTreeLine(rd, modeBuf, fnameBuf, shaBuf) + if err != nil { + if err == io.EOF { + break loop + } + return nil, err + } + sz -= int64(count) + entry := new(TreeEntry) + entry.ptree = ptree + + switch string(mode) { + case "100644": + entry.entryMode = EntryModeBlob + case "100755": + entry.entryMode = EntryModeExec + case "120000": + entry.entryMode = EntryModeSymlink + case "160000": + entry.entryMode = EntryModeCommit + case "40000": + entry.entryMode = EntryModeTree + default: + log("Unknown mode: %v", string(mode)) + return nil, fmt.Errorf("unknown mode: %v", string(mode)) + } + + entry.ID = MustID(sha) + entry.name = string(fname) + entries = append(entries, entry) + } + if _, err := rd.Discard(1); err != nil { + return entries, err + } + + return entries, nil +} |