99 "os"
1010 "os/exec"
1111 "path/filepath"
12+ "sort"
1213 "strings"
1314)
1415
@@ -26,7 +27,7 @@ more of its dependacies have been modified`)
2627}
2728
2829var (
29- packages [] string // the packages to check for taint
30+ packages map [ string ] struct {} // the packages to check for taint
3031 changedDirs map [string ]struct {} // the directories which contain modified files
3132 cache map [string ]* build.Package // a map[>package name>]<build.Package> to skip repeat lookups
3233 gitDirPtr * string // the git directory to check for changes
3738func init () {
3839 cache = make (map [string ]* build.Package )
3940 changedDirs = make (map [string ]struct {})
41+ packages = make (map [string ]struct {})
4042}
4143
4244func main () {
@@ -70,16 +72,27 @@ func main() {
7072 if err != nil {
7173 log .Fatal (err )
7274 }
73- for _ , v := range packages {
75+ output := make (map [string ]struct {})
76+ for k := range packages {
7477 // get all the deps
75- deps , err := findDeps (v , cwd )
78+ deps , err := findDeps (k , cwd )
7679 if err != nil {
7780 log .Fatal (err )
7881 }
7982 if hasChanges (deps ) {
80- fmt . Println ( v )
83+ output [ k ] = struct {}{}
8184 }
8285 }
86+ // finally to make it all pretty, sort it in a slice
87+ prettyOutput := make ([]string , 0 , len (output ))
88+ for k := range output {
89+ prettyOutput = append (prettyOutput , k )
90+ }
91+ if len (prettyOutput ) == 0 {
92+ return
93+ }
94+ sort .Strings (prettyOutput )
95+ fmt .Println (strings .Join (prettyOutput , "\n " ))
8396}
8497
8598// checks to see if any of the deps have the same suffix as anything in the changedDirs
@@ -98,7 +111,7 @@ func hasChanges(deps []string) bool {
98111func readPackages () {
99112 scanner := bufio .NewScanner (os .Stdin )
100113 for scanner .Scan () {
101- packages = append ( packages , scanner .Text ())
114+ packages [ scanner .Text ()] = struct {}{}
102115 }
103116 if err := scanner .Err (); err != nil {
104117 log .Fatal (err )
0 commit comments