mirror of
https://github.com/StackExchange/dnscontrol.git
synced 2024-05-11 05:55:12 +00:00
Implement a simple lexagraphic sort. (#755)
This commit is contained in:
@ -207,9 +207,45 @@ func (d *differ) IncrementalDiff(existing []*models.RecordConfig) (unchanged, cr
|
||||
create = append(create, Correlation{d, nil, rec})
|
||||
}
|
||||
}
|
||||
|
||||
// Sort the lists. This is purely cosmetic.
|
||||
sort.Slice(unchanged, func(i, j int) bool { return ChangesetLess(unchanged, i, j) })
|
||||
sort.Slice(create, func(i, j int) bool { return ChangesetLess(create, i, j) })
|
||||
sort.Slice(toDelete, func(i, j int) bool { return ChangesetLess(toDelete, i, j) })
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func ChangesetLess(c Changeset, i, j int) bool {
|
||||
var a, b string
|
||||
// Which fields are we comparing?
|
||||
// Usually only Desired OR Existing content exists (we're either
|
||||
// adding or deleting records). In those cases, just use whichever
|
||||
// isn't nil.
|
||||
// In the case where both Desired AND Existing exist, it doesn't
|
||||
// matter which we use as long as we are consistent. I flipped a
|
||||
// coin and picked to use Desired in that case.
|
||||
|
||||
if c[i].Desired != nil {
|
||||
a = c[i].Desired.NameFQDN
|
||||
} else {
|
||||
a = c[i].Existing.NameFQDN
|
||||
}
|
||||
|
||||
if c[j].Desired != nil {
|
||||
b = c[j].Desired.NameFQDN
|
||||
} else {
|
||||
b = c[j].Existing.NameFQDN
|
||||
}
|
||||
|
||||
return a < b
|
||||
|
||||
// TODO(tlim): This won't correctly sort:
|
||||
// []string{"example.com", "foo.example.com", "bar.example.com"}
|
||||
// A simple way to do that correctly is to split on ".", reverse the
|
||||
// elements, and sort on the result.
|
||||
}
|
||||
|
||||
func (d *differ) ChangedGroups(existing []*models.RecordConfig) map[models.RecordKey][]string {
|
||||
changedKeys := map[models.RecordKey][]string{}
|
||||
_, create, delete, modify := d.IncrementalDiff(existing)
|
||||
|
Reference in New Issue
Block a user