Skip to content

Commit 2255aff

Browse files
lunnyzeripath
andauthored
Fix lfs management find (#15537)
Fix #15236 * Do not do 40byte conversion within ParseTreeLine * Missed a to40ByteSHA Signed-off-by: Andrew Thornton <[email protected]> Co-authored-by: Andrew Thornton <[email protected]>
1 parent 9b8ffa1 commit 2255aff

File tree

4 files changed

+7
-4
lines changed

4 files changed

+7
-4
lines changed

modules/git/batch_reader.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,10 +149,10 @@ headerLoop:
149149
// constant hextable to help quickly convert between 20byte and 40byte hashes
150150
const hextable = "0123456789abcdef"
151151

152-
// to40ByteSHA converts a 20-byte SHA in a 40-byte slice into a 40-byte sha in place
152+
// To40ByteSHA converts a 20-byte SHA in a 40-byte slice into a 40-byte sha in place
153153
// without allocations. This is at least 100x quicker that hex.EncodeToString
154154
// NB This requires that sha is a 40-byte slice
155-
func to40ByteSHA(sha []byte) []byte {
155+
func To40ByteSHA(sha []byte) []byte {
156156
for i := 19; i >= 0; i-- {
157157
v := sha[i]
158158
vhi, vlo := v>>4, v&0x0f

modules/git/commit_info_nogogit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -300,7 +300,7 @@ revListLoop:
300300
commits[0] = string(commitID)
301301
}
302302
}
303-
treeID = to40ByteSHA(treeID)
303+
treeID = To40ByteSHA(treeID)
304304
_, err = batchStdinWriter.Write(treeID)
305305
if err != nil {
306306
return nil, err

modules/git/pipeline/lfs_nogogit.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -127,11 +127,12 @@ func FindLFSFile(repo *git.Repository, hash git.SHA1) ([]*LFSResult, error) {
127127
case "tree":
128128
var n int64
129129
for n < size {
130-
mode, fname, sha, count, err := git.ParseTreeLine(batchReader, modeBuf, fnameBuf, workingShaBuf)
130+
mode, fname, sha20byte, count, err := git.ParseTreeLine(batchReader, modeBuf, fnameBuf, workingShaBuf)
131131
if err != nil {
132132
return nil, err
133133
}
134134
n += int64(count)
135+
sha := git.To40ByteSHA(sha20byte)
135136
if bytes.Equal(sha, []byte(hashStr)) {
136137
result := LFSResult{
137138
Name: curPath + string(fname),

modules/lfs/pointer_scanner_nogogit.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import (
1111
"context"
1212
"io"
1313
"strconv"
14+
"strings"
1415
"sync"
1516

1617
"code.gitea.io/gitea/modules/git"
@@ -78,6 +79,7 @@ loop:
7879
_ = catFileBatchReader.CloseWithError(err)
7980
break
8081
}
82+
sha = strings.TrimSpace(sha)
8183
// Throw away the blob
8284
if _, err := bufferedReader.ReadString(' '); err != nil {
8385
_ = catFileBatchReader.CloseWithError(err)

0 commit comments

Comments
 (0)