@@ -17,7 +17,7 @@ import (
17
17
// majorVersionRegexp checks if an import path contains a major version suffix.
18
18
var majorVersionRegexp = regexp .MustCompile (`([/.])v([0-9]+)$` )
19
19
20
- func get (gopath , repodir , repo string ) error {
20
+ func get (gopath , repodir , repo , rev string ) error {
21
21
done := make (chan struct {})
22
22
defer close (done )
23
23
go progressSize ("go get" , repodir , done )
@@ -29,7 +29,11 @@ func get(gopath, repodir, repo string) error {
29
29
// to package into a single Debian package, and using “go get -t
30
30
// github.com/jacobsa/util” fails because there are no buildable go files
31
31
// in the top level of that repository.
32
- cmd := exec .Command ("go" , "get" , "-t" , repo + "/..." )
32
+ packages := repo + "/..."
33
+ if rev != "" {
34
+ packages += "@" + rev
35
+ }
36
+ cmd := exec .Command ("go" , "get" , "-t" , packages )
33
37
cmd .Dir = repodir
34
38
cmd .Stderr = os .Stderr
35
39
cmd .Env = append ([]string {
@@ -76,7 +80,7 @@ func otherVersions(mod string) (mods []string) {
76
80
return
77
81
}
78
82
79
- func estimate (importpath string ) error {
83
+ func estimate (importpath , revision string ) error {
80
84
removeTemp := func (path string ) {
81
85
if err := forceRemoveAll (path ); err != nil {
82
86
log .Printf ("could not remove all %s: %v" , path , err )
@@ -102,7 +106,7 @@ func estimate(importpath string) error {
102
106
return fmt .Errorf ("create dummymod: %w" , err )
103
107
}
104
108
105
- if err := get (gopath , repodir , importpath ); err != nil {
109
+ if err := get (gopath , repodir , importpath , revision ); err != nil {
106
110
return fmt .Errorf ("go get: %w" , err )
107
111
}
108
112
@@ -113,7 +117,7 @@ func estimate(importpath string) error {
113
117
114
118
if found {
115
119
// Fetch un-vendored dependencies
116
- if err := get (gopath , repodir , importpath ); err != nil {
120
+ if err := get (gopath , repodir , importpath , revision ); err != nil {
117
121
return fmt .Errorf ("fetch un-vendored: go get: %w" , err )
118
122
}
119
123
}
@@ -246,8 +250,19 @@ func execEstimate(args []string) {
246
250
fmt .Fprintf (os .Stderr , "Estimates the work necessary to bring <go-module-importpath> into Debian\n " +
247
251
"by printing all currently unpacked repositories.\n " )
248
252
fmt .Fprintf (os .Stderr , "Example: %s estimate github.com/Debian/dh-make-golang\n " , os .Args [0 ])
253
+ fmt .Fprintf (os .Stderr , "\n " )
254
+ fmt .Fprintf (os .Stderr , "Flags:\n " )
255
+ fs .PrintDefaults ()
249
256
}
250
257
258
+ var gitRevision string
259
+ fs .StringVar (& gitRevision ,
260
+ "git_revision" ,
261
+ "" ,
262
+ "git revision (see gitrevisions(7)) of the specified Go package\n " +
263
+ "to estimate, defaulting to the default behavior of go get.\n " +
264
+ "Useful in case you do not want to estimate the latest version." )
265
+
251
266
err := fs .Parse (args )
252
267
if err != nil {
253
268
log .Fatalf ("parse args: %s" , err )
@@ -258,9 +273,9 @@ func execEstimate(args []string) {
258
273
os .Exit (1 )
259
274
}
260
275
261
- // TODO: support the -git_revision flag
276
+ gitRevision = strings . TrimSpace ( gitRevision )
262
277
263
- if err := estimate (fs .Arg (0 )); err != nil {
278
+ if err := estimate (fs .Arg (0 ), gitRevision ); err != nil {
264
279
log .Fatalf ("estimate: %s" , err )
265
280
}
266
281
}
0 commit comments