Calculate distance of every diff-line to the closest change
(diffs []difflib.DiffRecord)
| 532 | |
| 533 | // Calculate distance of every diff-line to the closest change |
| 534 | func calculateDistances(diffs []difflib.DiffRecord) map[int]int { |
| 535 | distances := map[int]int{} |
| 536 | |
| 537 | // Iterate forwards through diffs, set 'distance' based on closest 'change' before this line |
| 538 | change := -1 |
| 539 | for i, diff := range diffs { |
| 540 | if diff.Delta != difflib.Common { |
| 541 | change = i |
| 542 | } |
| 543 | distance := math.MaxInt32 |
| 544 | if change != -1 { |
| 545 | distance = i - change |
| 546 | } |
| 547 | distances[i] = distance |
| 548 | } |
| 549 | |
| 550 | // Iterate backwards through diffs, reduce 'distance' based on closest 'change' after this line |
| 551 | change = -1 |
| 552 | for i := len(diffs) - 1; i >= 0; i-- { |
| 553 | diff := diffs[i] |
| 554 | if diff.Delta != difflib.Common { |
| 555 | change = i |
| 556 | } |
| 557 | if change != -1 { |
| 558 | distance := change - i |
| 559 | if distance < distances[i] { |
| 560 | distances[i] = distance |
| 561 | } |
| 562 | } |
| 563 | } |
| 564 | |
| 565 | return distances |
| 566 | } |
| 567 | |
| 568 | // reIndexForRelease based on template names |
| 569 | func reIndexForRelease(index map[string]*manifest.MappingResult) map[string]*manifest.MappingResult { |