Skip to content

Commit b86d7b8

Browse files
lunnyzeripath
andcommitted
Fix lfs management find (go-gitea#15537)
Fix go-gitea#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 a719311 commit b86d7b8

File tree

3 files changed

+5
-4
lines changed

3 files changed

+5
-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),

0 commit comments

Comments
 (0)