Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add -git_revision flag to estimate command #243

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 22 additions & 7 deletions estimate.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ import (
// majorVersionRegexp checks if an import path contains a major version suffix.
var majorVersionRegexp = regexp.MustCompile(`([/.])v([0-9]+)$`)

func get(gopath, repodir, repo string) error {
func get(gopath, repodir, repo, rev string) error {
done := make(chan struct{})
defer close(done)
go progressSize("go get", repodir, done)
Expand All @@ -29,7 +29,11 @@ func get(gopath, repodir, repo string) error {
// to package into a single Debian package, and using “go get -t
// github.com/jacobsa/util” fails because there are no buildable go files
// in the top level of that repository.
cmd := exec.Command("go", "get", "-t", repo+"/...")
packages := repo + "/..."
if rev != "" {
packages += "@" + rev
}
cmd := exec.Command("go", "get", "-t", packages)
cmd.Dir = repodir
cmd.Stderr = os.Stderr
cmd.Env = append([]string{
Expand Down Expand Up @@ -76,7 +80,7 @@ func otherVersions(mod string) (mods []string) {
return
}

func estimate(importpath string) error {
func estimate(importpath, revision string) error {
removeTemp := func(path string) {
if err := forceRemoveAll(path); err != nil {
log.Printf("could not remove all %s: %v", path, err)
Expand All @@ -102,7 +106,7 @@ func estimate(importpath string) error {
return fmt.Errorf("create dummymod: %w", err)
}

if err := get(gopath, repodir, importpath); err != nil {
if err := get(gopath, repodir, importpath, revision); err != nil {
return fmt.Errorf("go get: %w", err)
}

Expand All @@ -113,7 +117,7 @@ func estimate(importpath string) error {

if found {
// Fetch un-vendored dependencies
if err := get(gopath, repodir, importpath); err != nil {
if err := get(gopath, repodir, importpath, revision); err != nil {
return fmt.Errorf("fetch un-vendored: go get: %w", err)
}
}
Expand Down Expand Up @@ -246,8 +250,19 @@ func execEstimate(args []string) {
fmt.Fprintf(os.Stderr, "Estimates the work necessary to bring <go-module-importpath> into Debian\n"+
"by printing all currently unpacked repositories.\n")
fmt.Fprintf(os.Stderr, "Example: %s estimate github.com/Debian/dh-make-golang\n", os.Args[0])
fmt.Fprintf(os.Stderr, "\n")
fmt.Fprintf(os.Stderr, "Flags:\n")
fs.PrintDefaults()
}

var gitRevision string
fs.StringVar(&gitRevision,
"git_revision",
"",
"git revision (see gitrevisions(7)) of the specified Go package\n"+
"to estimate, defaulting to the default behavior of go get.\n"+
"Useful in case you do not want to estimate the latest version.")

err := fs.Parse(args)
if err != nil {
log.Fatalf("parse args: %s", err)
Expand All @@ -258,9 +273,9 @@ func execEstimate(args []string) {
os.Exit(1)
}

// TODO: support the -git_revision flag
gitRevision = strings.TrimSpace(gitRevision)

if err := estimate(fs.Arg(0)); err != nil {
if err := estimate(fs.Arg(0), gitRevision); err != nil {
log.Fatalf("estimate: %s", err)
}
}
Loading