Skip to content

Commit df72cf6

Browse files
KN4CK3Rzeripath
andauthored
Fix LFS commit finder not working (#15856)
* Create a copy of the sha bytes. Co-authored-by: Andrew Thornton <[email protected]>
1 parent 1a56599 commit df72cf6

File tree

3 files changed

+12
-9
lines changed

3 files changed

+12
-9
lines changed

modules/git/batch_reader.go

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -186,17 +186,18 @@ headerLoop:
186186
// constant hextable to help quickly convert between 20byte and 40byte hashes
187187
const hextable = "0123456789abcdef"
188188

189-
// To40ByteSHA converts a 20-byte SHA in a 40-byte slice into a 40-byte sha in place
190-
// without allocations. This is at least 100x quicker that hex.EncodeToString
191-
// NB This requires that sha is a 40-byte slice
192-
func To40ByteSHA(sha []byte) []byte {
189+
// To40ByteSHA converts a 20-byte SHA into a 40-byte sha. Input and output can be the
190+
// same 40 byte slice to support in place conversion without allocations.
191+
// This is at least 100x quicker that hex.EncodeToString
192+
// NB This requires that out is a 40-byte slice
193+
func To40ByteSHA(sha, out []byte) []byte {
193194
for i := 19; i >= 0; i-- {
194195
v := sha[i]
195196
vhi, vlo := v>>4, v&0x0f
196197
shi, slo := hextable[vhi], hextable[vlo]
197-
sha[i*2], sha[i*2+1] = shi, slo
198+
out[i*2], out[i*2+1] = shi, slo
198199
}
199-
return sha
200+
return out
200201
}
201202

202203
// ParseTreeLineSkipMode reads an entry from a tree in a cat-file --batch stream

modules/git/commit_info_nogogit.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ revListLoop:
310310
commits[0] = string(commitID)
311311
}
312312
}
313-
treeID = To40ByteSHA(treeID)
313+
treeID = To40ByteSHA(treeID, treeID)
314314
_, err = batchStdinWriter.Write(treeID)
315315
if err != nil {
316316
return nil, err

modules/git/pipeline/lfs_nogogit.go

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ func FindLFSFile(repo *git.Repository, hash git.SHA1) ([]*LFSResult, error) {
7272

7373
fnameBuf := make([]byte, 4096)
7474
modeBuf := make([]byte, 40)
75-
workingShaBuf := make([]byte, 40)
75+
workingShaBuf := make([]byte, 20)
7676

7777
for scan.Scan() {
7878
// Get the next commit ID
@@ -140,7 +140,9 @@ func FindLFSFile(repo *git.Repository, hash git.SHA1) ([]*LFSResult, error) {
140140
}
141141
resultsMap[curCommit.ID.String()+":"+curPath+string(fname)] = &result
142142
} else if string(mode) == git.EntryModeTree.String() {
143-
trees = append(trees, git.To40ByteSHA(sha20byte))
143+
sha40Byte := make([]byte, 40)
144+
git.To40ByteSHA(sha20byte, sha40Byte)
145+
trees = append(trees, sha40Byte)
144146
paths = append(paths, curPath+string(fname)+"/")
145147
}
146148
}

0 commit comments

Comments
 (0)