aboutsummaryrefslogtreecommitdiffstats
path: root/plumbing/object
diff options
context:
space:
mode:
authorJavi Fontan <jfontan@gmail.com>2022-03-30 12:32:26 +0200
committerJavi Fontan <jfontan@gmail.com>2022-03-30 12:32:26 +0200
commit1115cb6a84ea40ae68962cb82a4bc2dbb44e0f4c (patch)
tree599307a23030a3113da5606d456d20d0d08fdbd0 /plumbing/object
parentc785af3f4559ebac52c42f12d17cb118aac383ad (diff)
downloadgo-git-1115cb6a84ea40ae68962cb82a4bc2dbb44e0f4c.tar.gz
plumbing: object, rename calculation uses too much memory
The size of the similarity matrix is not limited and can be quite big when lots of files are deleted and added in a commit. Signed-off-by: Javi Fontan <jfontan@gmail.com>
Diffstat (limited to 'plumbing/object')
-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)