(report *Report, possiblyRemoved []string, oldIndex map[string]*manifest.MappingResult, possiblyAdded []string, newIndex map[string]*manifest.MappingResult, options *Options)
| 191 | ) |
| 192 | |
| 193 | func contentSearch(report *Report, possiblyRemoved []string, oldIndex map[string]*manifest.MappingResult, possiblyAdded []string, newIndex map[string]*manifest.MappingResult, options *Options) ([]string, []string) { |
| 194 | if options.FindRenames <= 0 { |
| 195 | return possiblyRemoved, possiblyAdded |
| 196 | } |
| 197 | |
| 198 | var removed []string |
| 199 | |
| 200 | for _, removedKey := range possiblyRemoved { |
| 201 | oldContent := oldIndex[removedKey] |
| 202 | var smallestKey string |
| 203 | var smallestFraction float32 = math.MaxFloat32 |
| 204 | for _, addedKey := range possiblyAdded { |
| 205 | newContent := newIndex[addedKey] |
| 206 | if oldContent.Kind != newContent.Kind { |
| 207 | continue |
| 208 | } |
| 209 | |
| 210 | oldLen := len(oldContent.Content) |
| 211 | newLen := len(newContent.Content) |
| 212 | if oldLen == 0 || newLen == 0 { |
| 213 | continue |
| 214 | } |
| 215 | // Skip the length-ratio filter for Secrets: their raw content length can |
| 216 | // differ greatly from the post-processed (redacted/decoded) length, so the |
| 217 | // ratio would be an unreliable predictor of content similarity. |
| 218 | if oldContent.Kind != kindSecret { |
| 219 | ratio := float32(oldLen) / float32(newLen) |
| 220 | if ratio < renameDetectionMinLengthRatio || ratio > renameDetectionMaxLengthRatio { |
| 221 | continue |
| 222 | } |
| 223 | } |
| 224 | |
| 225 | switch { |
| 226 | case options.ShowSecretsDecoded: |
| 227 | decodeSecrets(oldContent, newContent) |
| 228 | case !options.ShowSecrets: |
| 229 | redactSecrets(oldContent, newContent) |
| 230 | } |
| 231 | |
| 232 | diff := diffMappingResults(oldContent, newContent, options.StripTrailingCR) |
| 233 | delta := actualChanges(diff) |
| 234 | if delta == 0 || len(diff) == 0 { |
| 235 | continue |
| 236 | } |
| 237 | fraction := float32(delta) / float32(len(diff)) |
| 238 | if fraction > 0 && fraction < smallestFraction { |
| 239 | smallestKey = addedKey |
| 240 | smallestFraction = fraction |
| 241 | } |
| 242 | } |
| 243 | |
| 244 | if smallestFraction < options.FindRenames { |
| 245 | index := sort.SearchStrings(possiblyAdded, smallestKey) |
| 246 | possiblyAdded = append(possiblyAdded[:index], possiblyAdded[index+1:]...) |
| 247 | newContent := newIndex[smallestKey] |
| 248 | doDiff(report, removedKey, oldContent, newContent, options) |
| 249 | } else { |
| 250 | removed = append(removed, removedKey) |
no test coverage detected