aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing
diff options
context:
space:
mode:
authorMáximo Cuadros <mcuadros@gmail.com>2022-11-17 04:35:40 +0100
committerGitHub <noreply@github.com>2022-11-17 04:35:40 +0100
commitc798d4a42004b1c8976a6a4f42f131f16d08b6fa (patch)
treeb1cf10327be4e2679c98820b04569a279dc5b31b /plumbing
parentacd6c657ada037bcc8dcdb1f4e77898c90613ffb (diff)
parent1115cb6a84ea40ae68962cb82a4bc2dbb44e0f4c (diff)
downloadgo-git-c798d4a42004b1c8976a6a4f42f131f16d08b6fa.tar.gz
Merge pull request #503 from jfontan/fix/similarity-matrix-too-big
plumbing: object, rename calculation uses too much memory
Diffstat (limited to 'plumbing')
-rw-r--r--plumbing/object/rename.go8
1 files changed, 7 insertions, 1 deletions
diff --git a/plumbing/object/rename.go b/plumbing/object/rename.go
index 7fed72c..0394613 100644
--- a/plumbing/object/rename.go
+++ b/plumbing/object/rename.go
@@ -403,10 +403,16 @@ func min(a, b int) int {
return b
}
+const maxMatrixSize = 10000
+
func buildSimilarityMatrix(srcs, dsts []*Change, renameScore int) (similarityMatrix, error) {
// Allocate for the worst-case scenario where every pair has a score
// that we need to consider. We might not need that many.
- matrix := make(similarityMatrix, 0, len(srcs)*len(dsts))
+ matrixSize := len(srcs) * len(dsts)
+ if matrixSize > maxMatrixSize {
+ matrixSize = maxMatrixSize
+ }
+ matrix := make(similarityMatrix, 0, matrixSize)
srcSizes := make([]int64, len(srcs))
dstSizes := make([]int64, len(dsts))
dstTooLarge := make(map[int]bool)