diff options
author | zeripath <art27@cantab.net> | 2021-02-17 21:32:25 +0000 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-02-17 22:32:25 +0100 |
commit | ae7e6cd474747dce1f65c0b1c6e1d6b09ab0bccb (patch) | |
tree | 669743542988c694b242f92d512bb219eb300635 /modules/git/parse_nogogit.go | |
parent | 7ba158183a34d71b3989512c059a01d35c4c4673 (diff) | |
download | gitea-ae7e6cd474747dce1f65c0b1c6e1d6b09ab0bccb.tar.gz gitea-ae7e6cd474747dce1f65c0b1c6e1d6b09ab0bccb.zip |
Reduce calls to git cat-file -s (#14682)
* Reduce calls to git cat-file -s
There are multiple places where there are repeated calls to git cat-file
-s due to the blobs not being created with their size.
Through judicious use of git ls-tree -l and slight adjustments to the
indexer code we can avoid a lot of these calls.
* simplify by always expecting the long format
* Also always set the sized field and tell the indexer the update is sized
Diffstat (limited to 'modules/git/parse_nogogit.go')
-rw-r--r-- | modules/git/parse_nogogit.go | 16 |
1 files changed, 13 insertions, 3 deletions
diff --git a/modules/git/parse_nogogit.go b/modules/git/parse_nogogit.go index 26dd700af7..e9e93f66fd 100644 --- a/modules/git/parse_nogogit.go +++ b/modules/git/parse_nogogit.go @@ -10,9 +10,10 @@ import ( "bytes" "fmt" "strconv" + "strings" ) -// ParseTreeEntries parses the output of a `git ls-tree` command. +// ParseTreeEntries parses the output of a `git ls-tree -l` command. func ParseTreeEntries(data []byte) ([]*TreeEntry, error) { return parseTreeEntries(data, nil) } @@ -20,7 +21,7 @@ func ParseTreeEntries(data []byte) ([]*TreeEntry, error) { func parseTreeEntries(data []byte, ptree *Tree) ([]*TreeEntry, error) { entries := make([]*TreeEntry, 0, 10) for pos := 0; pos < len(data); { - // expect line to be of the form "<mode> <type> <sha>\t<filename>" + // expect line to be of the form "<mode> <type> <sha> <space-padded-size>\t<filename>" entry := new(TreeEntry) entry.ptree = ptree if pos+6 > len(data) { @@ -56,7 +57,16 @@ func parseTreeEntries(data []byte, ptree *Tree) ([]*TreeEntry, error) { entry.ID = id pos += 41 // skip over sha and trailing space - end := pos + bytes.IndexByte(data[pos:], '\n') + end := pos + bytes.IndexByte(data[pos:], '\t') + if end < pos { + return nil, fmt.Errorf("Invalid ls-tree -l output: %s", string(data)) + } + entry.size, _ = strconv.ParseInt(strings.TrimSpace(string(data[pos:end])), 10, 64) + entry.sized = true + + pos = end + 1 + + end = pos + bytes.IndexByte(data[pos:], '\n') if end < pos { return nil, fmt.Errorf("Invalid ls-tree output: %s", string(data)) } |