diff options
Diffstat (limited to 'pkg/subsystem')
| -rw-r--r-- | pkg/subsystem/linux/parents.go | 15 | ||||
| -rw-r--r-- | pkg/subsystem/linux/parents_test.go | 3 | ||||
| -rw-r--r-- | pkg/subsystem/linux/subsystems.go | 8 |
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 }) |
