@@ -174,50 +174,58 @@ func estimate(importpath string) error {
174174 // Analyse the dependency graph
175175 var lines []string
176176 seen := make (map [string ]bool )
177+ needed := make (map [string ]int )
177178 var visit func (n * Node , indent int )
178179 visit = func (n * Node , indent int ) {
179180 // Get the module name without its version, as go mod graph
180181 // can return multiple times the same module with different
181182 // versions.
182183 mod , _ , _ := strings .Cut (n .name , "@" )
183- if seen [mod ] {
184+ count , isNeeded := needed [mod ]
185+ if isNeeded {
186+ count ++
187+ needed [mod ] = count
188+ lines = append (lines , fmt .Sprintf ("%s\033 [90m%s (%d)\033 [0m" , strings .Repeat (" " , indent ), mod , count ))
189+ } else if seen [mod ] {
184190 return
185- }
186- seen [mod ] = true
187- // Go version dependency is indicated as a dependency to "go" and
188- // "toolchain", we do not use this information for now.
189- if mod == "go" || mod == "toolchain" {
190- return
191- }
192- if _ , ok := golangBinaries [mod ]; ok {
193- return // already packaged in Debian
194- }
195- var debianVersion string
196- // Check for potential other major versions already in Debian.
197- for _ , otherVersion := range otherVersions (mod ) {
198- if _ , ok := golangBinaries [otherVersion ]; ok {
199- debianVersion = otherVersion
200- break
201- }
202- }
203- if debianVersion == "" {
204- // When multiple modules are developped in the same repo,
205- // the repo root is often used as the import path metadata
206- // in Debian, so we do a last try with that.
207- rr , err := vcs .RepoRootForImportPath (mod , false )
208- if err != nil {
209- log .Printf ("Could not determine repo path for import path %q: %v\n " , mod , err )
210- } else if _ , ok := golangBinaries [rr .Root ]; ok {
211- // Log info to indicate that it is an approximate match
212- // but consider that it is packaged and skip the children.
213- log .Printf ("%s is packaged as %s in Debian" , mod , rr .Root )
191+ } else {
192+ seen [mod ] = true
193+ // Go version dependency is indicated as a dependency to "go" and
194+ // "toolchain", we do not use this information for now.
195+ if mod == "go" || mod == "toolchain" {
214196 return
215197 }
216- }
217- if debianVersion != "" {
218- lines = append (lines , fmt .Sprintf ("%s%s\t (%s in Debian)" , strings .Repeat (" " , indent ), mod , debianVersion ))
219- } else {
220- lines = append (lines , fmt .Sprintf ("%s%s" , strings .Repeat (" " , indent ), mod ))
198+ if _ , ok := golangBinaries [mod ]; ok {
199+ return // already packaged in Debian
200+ }
201+ var debianVersion string
202+ // Check for potential other major versions already in Debian.
203+ for _ , otherVersion := range otherVersions (mod ) {
204+ if _ , ok := golangBinaries [otherVersion ]; ok {
205+ debianVersion = otherVersion
206+ break
207+ }
208+ }
209+ if debianVersion == "" {
210+ // When multiple modules are developped in the same repo,
211+ // the repo root is often used as the import path metadata
212+ // in Debian, so we do a last try with that.
213+ rr , err := vcs .RepoRootForImportPath (mod , false )
214+ if err != nil {
215+ log .Printf ("Could not determine repo path for import path %q: %v\n " , mod , err )
216+ } else if _ , ok := golangBinaries [rr .Root ]; ok {
217+ // Log info to indicate that it is an approximate match
218+ // but consider that it is packaged and skip the children.
219+ log .Printf ("%s is packaged as %s in Debian" , mod , rr .Root )
220+ return
221+ }
222+ }
223+ if debianVersion != "" {
224+ lines = append (lines , fmt .Sprintf ("%s%s\t (%s in Debian)" , strings .Repeat (" " , indent ), mod , debianVersion ))
225+ } else {
226+ lines = append (lines , fmt .Sprintf ("%s%s" , strings .Repeat (" " , indent ), mod ))
227+ }
228+ needed [mod ] = 1
221229 }
222230 for _ , n := range n .children {
223231 visit (n , indent + 1 )
0 commit comments