aboutsummaryrefslogtreecommitdiffstats
path: root/pkg
diff options
context:
space:
mode:
authorAleksandr Nogikh <nogikh@google.com>2023-02-10 11:14:17 +0100
committerAleksandr Nogikh <wp32pw@gmail.com>2023-02-10 14:34:44 +0100
commit0241baba08ba2fd732e46a9634434154d58092e3 (patch)
tree1095c9b1ef242c6e1715f5e75818b5879a830db3 /pkg
parentd9997523a37a026098016ff4f0ecddfcf5c0d4b4 (diff)
pkg/subsystem: extract names after all preprocessing
In the previous steps we eliminate some of the extracted subsystems. It helps to have fewer contention while assigning the names. As a result, we need to only rely on emails during parents trasnformations.
Diffstat (limited to 'pkg')
-rw-r--r--pkg/subsystem/linux/parents.go15
-rw-r--r--pkg/subsystem/linux/parents_test.go3
-rw-r--r--pkg/subsystem/linux/subsystems.go8
3 files changed, 15 insertions, 11 deletions
diff --git a/pkg/subsystem/linux/parents.go b/pkg/subsystem/linux/parents.go
index 739514c68..6d27565bf 100644
--- a/pkg/subsystem/linux/parents.go
+++ b/pkg/subsystem/linux/parents.go
@@ -68,12 +68,15 @@ func dropSmallSubsystems(matrix *match.CoincidenceMatrix, list []*entity.Subsyst
// we drop A, since it brings little value.
func dropDuplicateSubsystems(matrix *match.CoincidenceMatrix, list []*entity.Subsystem) []*entity.Subsystem {
drop := map[*entity.Subsystem]struct{}{}
- nameIsBetter := func(first, second string) bool {
- // Let's prefer shorter names first.
- if len(first) < len(second) {
- return true
+ firstIsBetter := func(first, second *entity.Subsystem) bool {
+ firstEmail, secondEmail := "", ""
+ if len(first.Lists) > 0 {
+ firstEmail = first.Lists[0]
+ }
+ if len(second.Lists) > 0 {
+ secondEmail = second.Lists[0]
}
- return first < second
+ return firstEmail < secondEmail
}
matrix.NonEmptyPairs(func(a, b *entity.Subsystem, count int) {
// Only consider cases when A is fully enclosed in B, i.e. M[A][B] == M[A][A].
@@ -82,7 +85,7 @@ func dropDuplicateSubsystems(matrix *match.CoincidenceMatrix, list []*entity.Sub
}
// If A and B 100% coincide, eliminate A and keep B if A > B.
if count == matrix.Count(b) {
- if nameIsBetter(a.Name, b.Name) {
+ if firstIsBetter(a, b) {
return
}
drop[a] = struct{}{}
diff --git a/pkg/subsystem/linux/parents_test.go b/pkg/subsystem/linux/parents_test.go
index 06f7e1a3c..f1942671d 100644
--- a/pkg/subsystem/linux/parents_test.go
+++ b/pkg/subsystem/linux/parents_test.go
@@ -39,7 +39,8 @@ func TestDropDuplicateSubsystems(t *testing.T) {
expected = append(expected, kernel)
// Fully overlap.
- sameA, sameB := &entity.Subsystem{Name: "SameA"}, &entity.Subsystem{Name: "SameB"}
+ sameA := &entity.Subsystem{Lists: []string{"SameA@gmail.com"}}
+ sameB := &entity.Subsystem{Lists: []string{"SameB@gmail.com"}}
matrix.Record(kernel, sameA, sameB)
matrix.Record(kernel, sameA, sameB)
matrix.Record(kernel, sameA, sameB)
diff --git a/pkg/subsystem/linux/subsystems.go b/pkg/subsystem/linux/subsystems.go
index 8c7d1a673..5ca57a1be 100644
--- a/pkg/subsystem/linux/subsystems.go
+++ b/pkg/subsystem/linux/subsystems.go
@@ -31,10 +31,6 @@ func listFromRepoInner(root fs.FS, rules *customRules) ([]*entity.Subsystem, err
extraRules: rules,
}
list := ctx.groupByList()
- if err := setSubsystemNames(list); err != nil {
- return nil, fmt.Errorf("failed to set names: %w", err)
- }
- ctx.applyExtraRules(list)
matrix, err := match.BuildCoincidenceMatrix(root, list, dropPatterns)
if err != nil {
return nil, err
@@ -43,6 +39,10 @@ func listFromRepoInner(root fs.FS, rules *customRules) ([]*entity.Subsystem, err
if err != nil {
return nil, err
}
+ if err := setSubsystemNames(list); err != nil {
+ return nil, fmt.Errorf("failed to set names: %w", err)
+ }
+ ctx.applyExtraRules(list)
// Sort subsystems by name to keep output consistent.
sort.Slice(list, func(i, j int) bool { return list[i].Name < list[j].Name })