Skip to content

Commit d1d0372

Browse files
committed
Only highlight unique repositories in estimate
Keep printing all needed modules recursively, but instead of only dimming the duplicated modules, we also dim the rest of the import path after the repo root, and modules whose repo root has already been printed. This allows to only highlight the repository names (the actual thing that we package in Debian) and only once, so it give a better appreciation of the work packaging work required.
1 parent d156df1 commit d1d0372

File tree

1 file changed

+23
-8
lines changed

1 file changed

+23
-8
lines changed

estimate.go

Lines changed: 23 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -174,6 +174,7 @@ func estimate(importpath string) error {
174174
// Analyse the dependency graph
175175
var lines []string
176176
seen := make(map[string]bool)
177+
rrseen := make(map[string]bool)
177178
needed := make(map[string]int)
178179
var visit func(n *Node, indent int)
179180
visit = func(n *Node, indent int) {
@@ -198,6 +199,14 @@ func estimate(importpath string) error {
198199
if _, ok := golangBinaries[mod]; ok {
199200
return // already packaged in Debian
200201
}
202+
var repoRoot string
203+
rr, err := vcs.RepoRootForImportPath(mod, false)
204+
if err != nil {
205+
log.Printf("Could not determine repo path for import path %q: %v\n", mod, err)
206+
repoRoot = mod
207+
} else {
208+
repoRoot = rr.Root
209+
}
201210
var debianVersion string
202211
// Check for potential other major versions already in Debian.
203212
for _, otherVersion := range otherVersions(mod) {
@@ -210,21 +219,27 @@ func estimate(importpath string) error {
210219
// When multiple modules are developped in the same repo,
211220
// the repo root is often used as the import path metadata
212221
// 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 {
222+
if _, ok := golangBinaries[repoRoot]; ok {
217223
// Log info to indicate that it is an approximate match
218224
// but consider that it is packaged and skip the children.
219-
log.Printf("%s is packaged as %s in Debian", mod, rr.Root)
225+
log.Printf("%s is packaged as %s in Debian", mod, repoRoot)
220226
return
221227
}
222228
}
223-
if debianVersion != "" {
224-
lines = append(lines, fmt.Sprintf("%s%s\t(%s in Debian)", strings.Repeat(" ", indent), mod, debianVersion))
229+
line := strings.Repeat(" ", indent)
230+
if rrseen[repoRoot] {
231+
line += fmt.Sprintf("\033[90m%s\033[0m", mod)
232+
} else if strings.HasPrefix(mod, repoRoot) && len(mod) > len(repoRoot) {
233+
suffix := mod[len(repoRoot):]
234+
line += fmt.Sprintf("%s\033[90m%s\033[0m", repoRoot, suffix)
225235
} else {
226-
lines = append(lines, fmt.Sprintf("%s%s", strings.Repeat(" ", indent), mod))
236+
line += mod
237+
}
238+
if debianVersion != "" {
239+
line += fmt.Sprintf("\t(%s in Debian)", debianVersion)
227240
}
241+
lines = append(lines, line)
242+
rrseen[repoRoot] = true
228243
needed[mod] = 1
229244
}
230245
for _, n := range n.children {

0 commit comments

Comments
 (0)