@@ -512,14 +512,54 @@ func (rr *reproRunner) Run(r *repro.Result) {
512512 rr .done <- ret
513513}
514514
515- func PatchFocusAreas (cfg * mgrconfig.Config , gitPatch []byte ) {
516- const maxAffectedByHeader = 50
515+ func PatchFocusAreas (cfg * mgrconfig.Config , gitPatches [][]byte ) {
516+ direct , transitive := affectedFiles (cfg , gitPatches )
517+ if len (direct ) > 0 {
518+ sort .Strings (direct )
519+ log .Logf (0 , "adding directly modified files to focus_order: %q" , direct )
520+ cfg .Experimental .FocusAreas = append (cfg .Experimental .FocusAreas ,
521+ mgrconfig.FocusArea {
522+ Name : "modified" ,
523+ Filter : mgrconfig.CovFilterCfg {
524+ Files : direct ,
525+ },
526+ Weight : 3.0 ,
527+ })
528+ }
529+
530+ if len (transitive ) > 0 {
531+ sort .Strings (transitive )
532+ log .Logf (0 , "adding transitively affected to focus_order: %q" , transitive )
533+ cfg .Experimental .FocusAreas = append (cfg .Experimental .FocusAreas ,
534+ mgrconfig.FocusArea {
535+ Name : "included" ,
536+ Filter : mgrconfig.CovFilterCfg {
537+ Files : transitive ,
538+ },
539+ Weight : 2.0 ,
540+ })
541+ }
542+
543+ // Still fuzz the rest of the kernel.
544+ if len (cfg .Experimental .FocusAreas ) > 0 {
545+ cfg .Experimental .FocusAreas = append (cfg .Experimental .FocusAreas ,
546+ mgrconfig.FocusArea {
547+ Weight : 1.0 ,
548+ })
549+ }
550+ }
517551
518- names := map [string ]bool {}
519- includedNames := map [string ]bool {}
520- for _ , file := range vcs .ParseGitDiff (gitPatch ) {
521- names [file ] = true
552+ func affectedFiles (cfg * mgrconfig.Config , gitPatches [][]byte ) (direct , transitive []string ) {
553+ const maxAffectedByHeader = 50
522554
555+ directMap := make (map [string ]struct {})
556+ transitiveMap := make (map [string ]struct {})
557+ var allFiles []string
558+ for _ , patch := range gitPatches {
559+ allFiles = append (allFiles , vcs .ParseGitDiff (patch )... )
560+ }
561+ for _ , file := range allFiles {
562+ directMap [file ] = struct {}{}
523563 if strings .HasSuffix (file , ".h" ) && cfg .KernelSrc != "" {
524564 // Ideally, we should combine this with the recompilation process - then we know
525565 // exactly which files were affected by the patch.
@@ -540,53 +580,18 @@ func PatchFocusAreas(cfg *mgrconfig.Config, gitPatch []byte) {
540580 if name == "" {
541581 continue
542582 }
543- includedNames [name ] = true
583+ transitiveMap [name ] = struct {}{}
544584 }
545585 }
546586 }
547-
548- var namesList , includedList []string
549- for name := range names {
550- namesList = append (namesList , name )
587+ for name := range directMap {
588+ direct = append (direct , name )
551589 }
552- for name := range includedNames {
553- if names [name ] {
590+ for name := range transitiveMap {
591+ if _ , ok := directMap [name ]; ok {
554592 continue
555593 }
556- includedList = append (includedList , name )
557- }
558-
559- if len (namesList ) > 0 {
560- sort .Strings (namesList )
561- log .Logf (0 , "adding the following modified files to focus_order: %q" , namesList )
562- cfg .Experimental .FocusAreas = append (cfg .Experimental .FocusAreas ,
563- mgrconfig.FocusArea {
564- Name : "modified" ,
565- Filter : mgrconfig.CovFilterCfg {
566- Files : namesList ,
567- },
568- Weight : 3.0 ,
569- })
570- }
571-
572- if len (includedList ) > 0 {
573- sort .Strings (includedList )
574- log .Logf (0 , "adding the following included files to focus_order: %q" , includedList )
575- cfg .Experimental .FocusAreas = append (cfg .Experimental .FocusAreas ,
576- mgrconfig.FocusArea {
577- Name : "included" ,
578- Filter : mgrconfig.CovFilterCfg {
579- Files : includedList ,
580- },
581- Weight : 2.0 ,
582- })
583- }
584-
585- // Still fuzz the rest of the kernel.
586- if len (cfg .Experimental .FocusAreas ) > 0 {
587- cfg .Experimental .FocusAreas = append (cfg .Experimental .FocusAreas ,
588- mgrconfig.FocusArea {
589- Weight : 1.0 ,
590- })
594+ transitive = append (transitive , name )
591595 }
596+ return
592597}
0 commit comments