MCPcopy
hub / github.com/getsops/sops / DiffKeyGroups

Function DiffKeyGroups

cmd/sops/common/common.go:417–449  ·  view source on GitHub ↗

DiffKeyGroups returns the list of diffs found in two sops.keyGroup slices

(ours, theirs []sops.KeyGroup)

Source from the content-addressed store, hash-verified

415
416// DiffKeyGroups returns the list of diffs found in two sops.keyGroup slices
417func 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
452func PrettyPrintDiffs(diffs []Diff) {

Callers 2

updateFileFunction · 0.92
RunFunction · 0.92

Calls 2

maxFunction · 0.85
ToStringMethod · 0.65

Tested by

no test coverage detected