@@ -2,9 +2,11 @@ package main
2
2
3
3
import (
4
4
"bytes"
5
+ "encoding/json"
5
6
"flag"
6
7
"fmt"
7
8
"log"
9
+ "net/http"
8
10
"os"
9
11
"os/exec"
10
12
"path/filepath"
@@ -15,6 +17,10 @@ import (
15
17
"golang.org/x/tools/go/vcs"
16
18
)
17
19
20
+ const (
21
+ sourcesInNewURL = "https://api.ftp-master.debian.org/sources_in_suite/new"
22
+ )
23
+
18
24
// majorVersionRegexp checks if an import path contains a major version suffix.
19
25
var majorVersionRegexp = regexp .MustCompile (`([/.])v([0-9]+)$` )
20
26
@@ -25,6 +31,29 @@ var moduleBlocklist = map[string]string{
25
31
"github.com/Microsoft/go-winio" : "Windows only" ,
26
32
}
27
33
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
+
28
57
func get (gopath , repodir , repo , rev string ) error {
29
58
done := make (chan struct {})
30
59
defer close (done )
@@ -97,14 +126,14 @@ func otherVersions(mod string) (mods []string) {
97
126
// findOtherVersion search in m for potential other versions of the given
98
127
// module and returns the number of the major version found, 0 if not,
99
128
// 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 ) {
101
130
versions := otherVersions (mod )
102
131
for i , version := range versions {
103
132
if pkg , ok := m [version ]; ok {
104
133
return len (versions ) - i , pkg
105
134
}
106
135
}
107
- return 0 , ""
136
+ return 0 , debianPackage {}
108
137
}
109
138
110
139
// trackerLink generates an OSC 8 hyperlink to the tracker for the given Debian
@@ -170,7 +199,11 @@ func estimate(importpath, revision string) error {
170
199
// Retrieve already-packaged ones
171
200
golangBinaries , err := getGolangBinaries ()
172
201
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 )
174
207
}
175
208
176
209
// Build a graph in memory from the output of go mod graph
@@ -233,7 +266,11 @@ func estimate(importpath, revision string) error {
233
266
if mod == "go" || mod == "toolchain" {
234
267
return
235
268
}
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
+ }
237
274
return // already packaged in Debian
238
275
}
239
276
var repoRoot string
@@ -250,9 +287,13 @@ func estimate(importpath, revision string) error {
250
287
// Log info to indicate that it is an approximate match
251
288
// but consider that it is packaged and skip the children.
252
289
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 ))
254
291
} 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 )
256
297
}
257
298
return
258
299
}
@@ -262,7 +303,11 @@ func estimate(importpath, revision string) error {
262
303
if pkg , ok := golangBinaries [repoRoot ]; ok {
263
304
// Log info to indicate that it is an approximate match
264
305
// 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
+ }
266
311
return
267
312
}
268
313
// Ignore modules from the blocklist.
0 commit comments