aboutsummaryrefslogtreecommitdiffstats
path: root/pkg/subsystem
diff options
context:
space:
mode:
Diffstat (limited to 'pkg/subsystem')
-rw-r--r--pkg/subsystem/entities.go22
-rw-r--r--pkg/subsystem/entities_test.go15
2 files changed, 37 insertions, 0 deletions
diff --git a/pkg/subsystem/entities.go b/pkg/subsystem/entities.go
index 1f7456e84..457e57a3e 100644
--- a/pkg/subsystem/entities.go
+++ b/pkg/subsystem/entities.go
@@ -44,6 +44,28 @@ func (subsystem *Subsystem) Emails() []string {
return ret
}
+func FilterList(list []*Subsystem, filter func(*Subsystem) bool) []*Subsystem {
+ keep := map[*Subsystem]bool{}
+ for _, item := range list {
+ keep[item] = filter(item)
+ }
+ newList := []*Subsystem{}
+ for _, item := range list {
+ if !keep[item] {
+ continue
+ }
+ newParents := []*Subsystem{}
+ for _, p := range item.Parents {
+ if keep[p] {
+ newParents = append(newParents, p)
+ }
+ }
+ item.Parents = newParents
+ newList = append(newList, item)
+ }
+ return newList
+}
+
// PathRule describes the part of the directory tree belonging to a single subsystem.
type PathRule struct {
IncludeRegexp string
diff --git a/pkg/subsystem/entities_test.go b/pkg/subsystem/entities_test.go
index 58166b91b..81c970b65 100644
--- a/pkg/subsystem/entities_test.go
+++ b/pkg/subsystem/entities_test.go
@@ -39,3 +39,18 @@ func TestSubsystemEmails(t *testing.T) {
"a@list.com", "b@list.com", "c@list.com", "d@list.com", "d@person.com",
})
}
+
+func TestFilterList(t *testing.T) {
+ parentParent := &Subsystem{}
+ parentA := &Subsystem{Parents: []*Subsystem{parentParent}}
+ parentB := &Subsystem{Parents: []*Subsystem{parentParent}}
+ entity := &Subsystem{Parents: []*Subsystem{parentA, parentB}}
+
+ newList := FilterList([]*Subsystem{parentA, parentB, parentParent, entity},
+ func(s *Subsystem) bool {
+ return s != parentB
+ },
+ )
+ assert.Len(t, newList, 3)
+ assert.ElementsMatch(t, entity.Parents, []*Subsystem{parentA})
+}