@@ -2,9 +2,11 @@ package main
22
33import (
44 "bytes"
5+ "encoding/json"
56 "flag"
67 "fmt"
78 "log"
9+ "net/http"
810 "os"
911 "os/exec"
1012 "path/filepath"
@@ -15,6 +17,10 @@ import (
1517 "golang.org/x/tools/go/vcs"
1618)
1719
20+ const (
21+ sourcesInNewURL = "https://api.ftp-master.debian.org/sources_in_suite/new"
22+ )
23+
1824// majorVersionRegexp checks if an import path contains a major version suffix.
1925var majorVersionRegexp = regexp .MustCompile (`([/.])v([0-9]+)$` )
2026
@@ -25,6 +31,29 @@ var moduleBlocklist = map[string]string{
2531 "github.com/Microsoft/go-winio" : "Windows only" ,
2632}
2733
34+ func getSourcesInNew () (map [string ]string , error ) {
35+ sourcesInNew := make (map [string ]string )
36+
37+ resp , err := http .Get (sourcesInNewURL )
38+ if err != nil {
39+ return nil , fmt .Errorf ("getting %q: %w" , golangBinariesURL , err )
40+ }
41+ if got , want := resp .StatusCode , http .StatusOK ; got != want {
42+ return nil , fmt .Errorf ("unexpected HTTP status code: got %d, want %d" , got , want )
43+ }
44+ var pkgs []struct {
45+ Source string `json:"source"`
46+ Version string `json:"version"`
47+ }
48+ if err := json .NewDecoder (resp .Body ).Decode (& pkgs ); err != nil {
49+ return nil , fmt .Errorf ("decode: %w" , err )
50+ }
51+ for _ , pkg := range pkgs {
52+ sourcesInNew [pkg .Source ] = pkg .Version
53+ }
54+ return sourcesInNew , nil
55+ }
56+
2857func get (gopath , repodir , repo , rev string ) error {
2958 done := make (chan struct {})
3059 defer close (done )
@@ -97,14 +126,14 @@ func otherVersions(mod string) (mods []string) {
97126// findOtherVersion search in m for potential other versions of the given
98127// module and returns the number of the major version found, 0 if not,
99128// along with the corresponding package name.
100- func findOtherVersion (m map [string ]string , mod string ) (int , string ) {
129+ func findOtherVersion (m map [string ]debianPackage , mod string ) (int , debianPackage ) {
101130 versions := otherVersions (mod )
102131 for i , version := range versions {
103132 if pkg , ok := m [version ]; ok {
104133 return len (versions ) - i , pkg
105134 }
106135 }
107- return 0 , ""
136+ return 0 , debianPackage {}
108137}
109138
110139// trackerLink generates an OSC 8 hyperlink to the tracker for the given Debian
@@ -170,7 +199,11 @@ func estimate(importpath, revision string) error {
170199 // Retrieve already-packaged ones
171200 golangBinaries , err := getGolangBinaries ()
172201 if err != nil {
173- return nil
202+ return fmt .Errorf ("get golang debian packages: %w" , err )
203+ }
204+ sourcesInNew , err := getSourcesInNew ()
205+ if err != nil {
206+ return fmt .Errorf ("get packages in new: %w" , err )
174207 }
175208
176209 // Build a graph in memory from the output of go mod graph
@@ -233,7 +266,11 @@ func estimate(importpath, revision string) error {
233266 if mod == "go" || mod == "toolchain" {
234267 return
235268 }
236- if _ , ok := golangBinaries [mod ]; ok {
269+ if pkg , ok := golangBinaries [mod ]; ok {
270+ if _ , ok := sourcesInNew [pkg .source ]; ok {
271+ line := fmt .Sprintf ("%s\033 [36m%s (in NEW)\033 [0m" , strings .Repeat (" " , indent ), mod )
272+ lines = append (lines , line )
273+ }
237274 return // already packaged in Debian
238275 }
239276 var repoRoot string
@@ -250,9 +287,13 @@ func estimate(importpath, revision string) error {
250287 // Log info to indicate that it is an approximate match
251288 // but consider that it is packaged and skip the children.
252289 if v == 1 {
253- log .Printf ("%s has no version string in Debian (%s)" , mod , trackerLink (pkg ))
290+ log .Printf ("%s has no version string in Debian (%s)" , mod , trackerLink (pkg . source ))
254291 } else {
255- log .Printf ("%s is v%d in Debian (%s)" , mod , v , trackerLink (pkg ))
292+ log .Printf ("%s is v%d in Debian (%s)" , mod , v , trackerLink (pkg .source ))
293+ }
294+ if _ , ok := sourcesInNew [pkg .source ]; ok {
295+ line := fmt .Sprintf ("%s\033 [36m%s (in NEW)\033 [0m" , strings .Repeat (" " , indent ), mod )
296+ lines = append (lines , line )
256297 }
257298 return
258299 }
@@ -262,7 +303,11 @@ func estimate(importpath, revision string) error {
262303 if pkg , ok := golangBinaries [repoRoot ]; ok {
263304 // Log info to indicate that it is an approximate match
264305 // but consider that it is packaged and skip the children.
265- log .Printf ("%s is packaged as %s in Debian (%s)" , mod , repoRoot , trackerLink (pkg ))
306+ log .Printf ("%s is packaged as %s in Debian (%s)" , mod , repoRoot , trackerLink (pkg .source ))
307+ if _ , ok := sourcesInNew [pkg .source ]; ok {
308+ line := fmt .Sprintf ("%s\033 [36m%s (in NEW)\033 [0m" , strings .Repeat (" " , indent ), mod )
309+ lines = append (lines , line )
310+ }
266311 return
267312 }
268313 // Ignore modules from the blocklist.
0 commit comments