From 8cdf70ac123b26d2234014bce344332f9b0787b3 Mon Sep 17 00:00:00 2001 From: Miguel Molina Date: Mon, 4 May 2020 09:14:42 +0200 Subject: plumbing: exact renames detection could leave gaps in the changes This fixes an issue where exact renames detection could leave gaps with nil changes in the added and deleted change slices. That could lead to panics in the content rename detection and others if the user had set OnlyExact to true. Signed-off-by: Miguel Molina --- plumbing/object/rename.go | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) (limited to 'plumbing/object/rename.go') diff --git a/plumbing/object/rename.go b/plumbing/object/rename.go index 9ce41b3..b0c62b2 100644 --- a/plumbing/object/rename.go +++ b/plumbing/object/rename.go @@ -177,14 +177,14 @@ func (d *renameDetector) detectExactRenames() { } for _, c := range added { - if _, ok := usedAdds[c]; !ok { + if _, ok := usedAdds[c]; !ok && c != nil { addedLeft = append(addedLeft, c) } } var newDeletes = make([]*Change, 0, len(deleted)-len(usedDeletes)) for _, c := range deleted { - if _, ok := usedDeletes[c]; !ok { + if _, ok := usedDeletes[c]; !ok && c != nil { newDeletes = append(newDeletes, c) } } @@ -197,11 +197,7 @@ func (d *renameDetector) detectExactRenames() { d.added = addedLeft d.deleted = nil for _, dels := range deletes { - for _, del := range dels { - if del != nil { - d.deleted = append(d.deleted, del) - } - } + d.deleted = append(d.deleted, dels...) } } @@ -713,7 +709,7 @@ func (i *similarityIndex) common(dst *similarityIndex) uint64 { } func (i *similarityIndex) add(key int, cnt uint64) error { - key = int(uint32(key)*0x9e370001 >> 1) + key = int(uint32(key) * 0x9e370001 >> 1) j := i.slot(key) for { -- cgit