DiffKeyGroups returns the list of diffs found in two sops.keyGroup slices
(ours, theirs []sops.KeyGroup)
| 415 | |
| 416 | // DiffKeyGroups returns the list of diffs found in two sops.keyGroup slices |
| 417 | func DiffKeyGroups(ours, theirs []sops.KeyGroup) []Diff { |
| 418 | var diffs []Diff |
| 419 | for i := 0; i < max(len(ours), len(theirs)); i++ { |
| 420 | var diff Diff |
| 421 | var ourGroup, theirGroup sops.KeyGroup |
| 422 | if len(ours) > i { |
| 423 | ourGroup = ours[i] |
| 424 | } |
| 425 | if len(theirs) > i { |
| 426 | theirGroup = theirs[i] |
| 427 | } |
| 428 | ourKeys := make(map[string]struct{}) |
| 429 | theirKeys := make(map[string]struct{}) |
| 430 | for _, key := range ourGroup { |
| 431 | ourKeys[key.ToString()] = struct{}{} |
| 432 | } |
| 433 | for _, key := range theirGroup { |
| 434 | if _, ok := ourKeys[key.ToString()]; ok { |
| 435 | diff.Common = append(diff.Common, key) |
| 436 | } else { |
| 437 | diff.Added = append(diff.Added, key) |
| 438 | } |
| 439 | theirKeys[key.ToString()] = struct{}{} |
| 440 | } |
| 441 | for _, key := range ourGroup { |
| 442 | if _, ok := theirKeys[key.ToString()]; !ok { |
| 443 | diff.Removed = append(diff.Removed, key) |
| 444 | } |
| 445 | } |
| 446 | diffs = append(diffs, diff) |
| 447 | } |
| 448 | return diffs |
| 449 | } |
| 450 | |
| 451 | // PrettyPrintDiffs prints a slice of Diff objects to stdout |
| 452 | func PrettyPrintDiffs(diffs []Diff) { |
no test coverage detected