Skip to content

Commit 7be9ad3

Browse files
committed
estimate: print Debian package's name & URL for approximate matches
This allows to get an easy access to the tracker page of the corresponding packages in case of approximate matches, which is especially useful when the major version present in Debian cannot be determined from the value of Go-Import-Path.
1 parent 4dc56a5 commit 7be9ad3

File tree

1 file changed

+17
-10
lines changed

1 file changed

+17
-10
lines changed

estimate.go

Lines changed: 17 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -95,15 +95,22 @@ func otherVersions(mod string) (mods []string) {
9595
}
9696

9797
// findOtherVersion search in m for potential other versions of the given
98-
// module and returns the number of the major version found, 0 if not.
99-
func findOtherVersion(m map[string]string, mod string) int {
98+
// module and returns the number of the major version found, 0 if not,
99+
// along with the corresponding package name.
100+
func findOtherVersion(m map[string]string, mod string) (int, string) {
100101
versions := otherVersions(mod)
101102
for i, version := range versions {
102-
if _, ok := m[version]; ok {
103-
return len(versions) - i
103+
if pkg, ok := m[version]; ok {
104+
return len(versions) - i, pkg
104105
}
105106
}
106-
return 0
107+
return 0, ""
108+
}
109+
110+
// trackerLink generates an OSC 8 hyperlink to the tracker for the given Debian
111+
// package name.
112+
func trackerLink(pkg string) string {
113+
return fmt.Sprintf("\033]8;;https://tracker.debian.org/pkg/%[1]s\033\\%[1]s\033]8;;\033\\", pkg)
107114
}
108115

109116
func estimate(importpath, revision string) error {
@@ -238,24 +245,24 @@ func estimate(importpath, revision string) error {
238245
repoRoot = rr.Root
239246
}
240247
// Check for potential other major versions already in Debian.
241-
v := findOtherVersion(golangBinaries, mod)
248+
v, pkg := findOtherVersion(golangBinaries, mod)
242249
if v != 0 {
243250
// Log info to indicate that it is an approximate match
244251
// but consider that it is packaged and skip the children.
245252
if v == 1 {
246-
log.Printf("%s has no version string in Debian", mod)
253+
log.Printf("%s has no version string in Debian (%s)", mod, trackerLink(pkg))
247254
} else {
248-
log.Printf("%s is v%d in Debian", mod, v)
255+
log.Printf("%s is v%d in Debian (%s)", mod, v, trackerLink(pkg))
249256
}
250257
return
251258
}
252259
// When multiple modules are developped in the same repo,
253260
// the repo root is often used as the import path metadata
254261
// in Debian, so we do a last try with that.
255-
if _, ok := golangBinaries[repoRoot]; ok {
262+
if pkg, ok := golangBinaries[repoRoot]; ok {
256263
// Log info to indicate that it is an approximate match
257264
// but consider that it is packaged and skip the children.
258-
log.Printf("%s is packaged as %s in Debian", mod, repoRoot)
265+
log.Printf("%s is packaged as %s in Debian (%s)", mod, repoRoot, trackerLink(pkg))
259266
return
260267
}
261268
// Ignore modules from the blocklist.

0 commit comments

Comments
 (0)