]> source.dussan.org Git - gitea.git/commitdiff
Fix lfs management find (#15537)
authorLunny Xiao <xiaolunwen@gmail.com>
Wed, 21 Apr 2021 16:31:59 +0000 (00:31 +0800)
committerGitHub <noreply@github.com>
Wed, 21 Apr 2021 16:31:59 +0000 (18:31 +0200)
Fix #15236

* Do not do 40byte conversion within ParseTreeLine
* Missed a to40ByteSHA

Signed-off-by: Andrew Thornton <art27@cantab.net>
Co-authored-by: Andrew Thornton <art27@cantab.net>
modules/git/batch_reader.go
modules/git/commit_info_nogogit.go
modules/git/pipeline/lfs_nogogit.go
modules/lfs/pointer_scanner_nogogit.go

index 6014508b9300ed82c7a3f19d2137dd23804b5972..1905067cb4a3373ff3fcbf4f13c2c4ae9b99cf23 100644 (file)
@@ -149,10 +149,10 @@ headerLoop:
 // constant hextable to help quickly convert between 20byte and 40byte hashes
 const hextable = "0123456789abcdef"
 
-// to40ByteSHA converts a 20-byte SHA in a 40-byte slice into a 40-byte sha in place
+// To40ByteSHA converts a 20-byte SHA in a 40-byte slice into a 40-byte sha in place
 // without allocations. This is at least 100x quicker that hex.EncodeToString
 // NB This requires that sha is a 40-byte slice
-func to40ByteSHA(sha []byte) []byte {
+func To40ByteSHA(sha []byte) []byte {
        for i := 19; i >= 0; i-- {
                v := sha[i]
                vhi, vlo := v>>4, v&0x0f
index b844468c8c41b7aeec402a462fb31e2476cc2180..f14b7b82910fc42544f64965441060c676e73348 100644 (file)
@@ -300,7 +300,7 @@ revListLoop:
                                        commits[0] = string(commitID)
                                }
                        }
-                       treeID = to40ByteSHA(treeID)
+                       treeID = To40ByteSHA(treeID)
                        _, err = batchStdinWriter.Write(treeID)
                        if err != nil {
                                return nil, err
index f6faa3a48aa1d787f63e8f835142df00714ab4e7..79f7528d3335e3b40c66f142f547d41a8f9feb56 100644 (file)
@@ -127,11 +127,12 @@ func FindLFSFile(repo *git.Repository, hash git.SHA1) ([]*LFSResult, error) {
                        case "tree":
                                var n int64
                                for n < size {
-                                       mode, fname, sha, count, err := git.ParseTreeLine(batchReader, modeBuf, fnameBuf, workingShaBuf)
+                                       mode, fname, sha20byte, count, err := git.ParseTreeLine(batchReader, modeBuf, fnameBuf, workingShaBuf)
                                        if err != nil {
                                                return nil, err
                                        }
                                        n += int64(count)
+                                       sha := git.To40ByteSHA(sha20byte)
                                        if bytes.Equal(sha, []byte(hashStr)) {
                                                result := LFSResult{
                                                        Name:         curPath + string(fname),
index 28d4afba613f96cb3eecd029be756d39e564b021..b5654d5de751e4f625eb050f1a94e2f806252ca8 100644 (file)
@@ -11,6 +11,7 @@ import (
        "context"
        "io"
        "strconv"
+       "strings"
        "sync"
 
        "code.gitea.io/gitea/modules/git"
@@ -78,6 +79,7 @@ loop:
                        _ = catFileBatchReader.CloseWithError(err)
                        break
                }
+               sha = strings.TrimSpace(sha)
                // Throw away the blob
                if _, err := bufferedReader.ReadString(' '); err != nil {
                        _ = catFileBatchReader.CloseWithError(err)