@@ -178,50 +178,73 @@ func estimate(importpath, revision string) error {
178178 // Analyse the dependency graph
179179 var lines []string
180180 seen := make (map [string ]bool )
181+ rrseen := make (map [string ]bool )
182+ needed := make (map [string ]int )
181183 var visit func (n * Node , indent int )
182184 visit = func (n * Node , indent int ) {
183185 // Get the module name without its version, as go mod graph
184186 // can return multiple times the same module with different
185187 // versions.
186188 mod , _ , _ := strings .Cut (n .name , "@" )
187- if seen [mod ] {
189+ count , isNeeded := needed [mod ]
190+ if isNeeded {
191+ count ++
192+ needed [mod ] = count
193+ lines = append (lines , fmt .Sprintf ("%s\033 [90m%s (%d)\033 [0m" , strings .Repeat (" " , indent ), mod , count ))
194+ } else if seen [mod ] {
188195 return
189- }
190- seen [mod ] = true
191- // Go version dependency is indicated as a dependency to "go" and
192- // "toolchain", we do not use this information for now.
193- if mod == "go" || mod == "toolchain" {
194- return
195- }
196- if _ , ok := golangBinaries [mod ]; ok {
197- return // already packaged in Debian
198- }
199- var debianVersion string
200- // Check for potential other major versions already in Debian.
201- for _ , otherVersion := range otherVersions (mod ) {
202- if _ , ok := golangBinaries [otherVersion ]; ok {
203- debianVersion = otherVersion
204- break
196+ } else {
197+ seen [mod ] = true
198+ // Go version dependency is indicated as a dependency to "go" and
199+ // "toolchain", we do not use this information for now.
200+ if mod == "go" || mod == "toolchain" {
201+ return
205202 }
206- }
207- if debianVersion == "" {
208- // When multiple modules are developped in the same repo,
209- // the repo root is often used as the import path metadata
210- // in Debian, so we do a last try with that.
203+ if _ , ok := golangBinaries [mod ]; ok {
204+ return // already packaged in Debian
205+ }
206+ var repoRoot string
211207 rr , err := vcs .RepoRootForImportPath (mod , false )
212208 if err != nil {
213209 log .Printf ("Could not determine repo path for import path %q: %v\n " , mod , err )
214- } else if _ , ok := golangBinaries [rr .Root ]; ok {
215- // Log info to indicate that it is an approximate match
216- // but consider that it is packaged and skip the children.
217- log .Printf ("%s is packaged as %s in Debian" , mod , rr .Root )
218- return
210+ repoRoot = mod
211+ } else {
212+ repoRoot = rr .Root
219213 }
220- }
221- if debianVersion != "" {
222- lines = append (lines , fmt .Sprintf ("%s%s\t (%s in Debian)" , strings .Repeat (" " , indent ), mod , debianVersion ))
223- } else {
224- lines = append (lines , fmt .Sprintf ("%s%s" , strings .Repeat (" " , indent ), mod ))
214+ var debianVersion string
215+ // Check for potential other major versions already in Debian.
216+ for _ , otherVersion := range otherVersions (mod ) {
217+ if _ , ok := golangBinaries [otherVersion ]; ok {
218+ debianVersion = otherVersion
219+ break
220+ }
221+ }
222+ if debianVersion == "" {
223+ // When multiple modules are developped in the same repo,
224+ // the repo root is often used as the import path metadata
225+ // in Debian, so we do a last try with that.
226+ if _ , ok := golangBinaries [repoRoot ]; ok {
227+ // Log info to indicate that it is an approximate match
228+ // but consider that it is packaged and skip the children.
229+ log .Printf ("%s is packaged as %s in Debian" , mod , repoRoot )
230+ return
231+ }
232+ }
233+ line := strings .Repeat (" " , indent )
234+ if rrseen [repoRoot ] {
235+ line += fmt .Sprintf ("\033 [90m%s\033 [0m" , mod )
236+ } else if strings .HasPrefix (mod , repoRoot ) && len (mod ) > len (repoRoot ) {
237+ suffix := mod [len (repoRoot ):]
238+ line += fmt .Sprintf ("%s\033 [90m%s\033 [0m" , repoRoot , suffix )
239+ } else {
240+ line += mod
241+ }
242+ if debianVersion != "" {
243+ line += fmt .Sprintf ("\t (%s in Debian)" , debianVersion )
244+ }
245+ lines = append (lines , line )
246+ rrseen [repoRoot ] = true
247+ needed [mod ] = 1
225248 }
226249 for _ , n := range n .children {
227250 visit (n , indent + 1 )
0 commit comments