Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

gps: fine grained source transitions #1250

Merged
merged 2 commits into from
Feb 24, 2018
Merged
Show file tree
Hide file tree
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
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@ BUG FIXES:

IMPROVEMENTS:

* Reduce network access by trusting local source information and only pulling
from upstream when necessary ([#1250](https://github.com/golang/dep/pull/1250)).

# v0.4.1

BUG FIXES:
Expand Down
50 changes: 25 additions & 25 deletions gps/deduce.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ import (
"strings"
"sync"

radix "github.com/armon/go-radix"
"github.com/armon/go-radix"
"github.com/pkg/errors"
)

Expand Down Expand Up @@ -104,7 +104,7 @@ type pathDeducer interface {
// So the return of the above string would be
// "github.com/some-user/some-package"
deduceRoot(string) (string, error)
deduceSource(string, *url.URL) (maybeSource, error)
deduceSource(string, *url.URL) (maybeSources, error)
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Using concrete maybeSources everywhere was more significant in a previous iteration, but is still an overall simplifying change - barring some test boilerplate.

}

type githubDeducer struct {
Expand All @@ -120,7 +120,7 @@ func (m githubDeducer) deduceRoot(path string) (string, error) {
return "github.com" + v[2], nil
}

func (m githubDeducer) deduceSource(path string, u *url.URL) (maybeSource, error) {
func (m githubDeducer) deduceSource(path string, u *url.URL) (maybeSources, error) {
v := m.regexp.FindStringSubmatch(path)
if v == nil {
return nil, fmt.Errorf("%s is not a valid path for a source on github.com", path)
Expand All @@ -138,7 +138,7 @@ func (m githubDeducer) deduceSource(path string, u *url.URL) (maybeSource, error
if u.Scheme == "ssh" {
u.User = url.User("git")
}
return maybeGitSource{url: u}, nil
return maybeSources{maybeGitSource{url: u}}, nil
}

mb := make(maybeSources, len(gitSchemes))
Expand Down Expand Up @@ -167,7 +167,7 @@ func (m bitbucketDeducer) deduceRoot(path string) (string, error) {
return "bitbucket.org" + v[2], nil
}

func (m bitbucketDeducer) deduceSource(path string, u *url.URL) (maybeSource, error) {
func (m bitbucketDeducer) deduceSource(path string, u *url.URL) (maybeSources, error) {
v := m.regexp.FindStringSubmatch(path)
if v == nil {
return nil, fmt.Errorf("%s is not a valid path for a source on bitbucket.org", path)
Expand All @@ -189,12 +189,12 @@ func (m bitbucketDeducer) deduceSource(path string, u *url.URL) (maybeSource, er
// superset of the hg schemes
return nil, fmt.Errorf("%s is not a valid scheme for accessing a git repository", u.Scheme)
}
return maybeGitSource{url: u}, nil
return maybeSources{maybeGitSource{url: u}}, nil
} else if ishg {
if !validhg {
return nil, fmt.Errorf("%s is not a valid scheme for accessing an hg repository", u.Scheme)
}
return maybeHgSource{url: u}, nil
return maybeSources{maybeHgSource{url: u}}, nil
} else if !validgit && !validhg {
return nil, fmt.Errorf("%s is not a valid scheme for accessing either a git or hg repository", u.Scheme)
}
Expand Down Expand Up @@ -265,7 +265,7 @@ func (m gopkginDeducer) parseAndValidatePath(p string) ([]string, error) {
return v, nil
}

func (m gopkginDeducer) deduceSource(p string, u *url.URL) (maybeSource, error) {
func (m gopkginDeducer) deduceSource(p string, u *url.URL) (maybeSources, error) {
// Reuse root detection logic for initial validation
v, err := m.parseAndValidatePath(p)
if err != nil {
Expand Down Expand Up @@ -329,7 +329,7 @@ func (m launchpadDeducer) deduceRoot(path string) (string, error) {
return "launchpad.net" + v[2], nil
}

func (m launchpadDeducer) deduceSource(path string, u *url.URL) (maybeSource, error) {
func (m launchpadDeducer) deduceSource(path string, u *url.URL) (maybeSources, error) {
v := m.regexp.FindStringSubmatch(path)
if v == nil {
return nil, fmt.Errorf("%s is not a valid path for a source on launchpad.net", path)
Expand All @@ -342,7 +342,7 @@ func (m launchpadDeducer) deduceSource(path string, u *url.URL) (maybeSource, er
if !validateVCSScheme(u.Scheme, "bzr") {
return nil, fmt.Errorf("%s is not a valid scheme for accessing a bzr repository", u.Scheme)
}
return maybeBzrSource{url: u}, nil
return maybeSources{maybeBzrSource{url: u}}, nil
}

mb := make(maybeSources, len(bzrSchemes))
Expand All @@ -369,7 +369,7 @@ func (m launchpadGitDeducer) deduceRoot(path string) (string, error) {
return "git.launchpad.net" + v[2], nil
}

func (m launchpadGitDeducer) deduceSource(path string, u *url.URL) (maybeSource, error) {
func (m launchpadGitDeducer) deduceSource(path string, u *url.URL) (maybeSources, error) {
v := m.regexp.FindStringSubmatch(path)
if v == nil {
return nil, fmt.Errorf("%s is not a valid path for a source on git.launchpad.net", path)
Expand All @@ -382,7 +382,7 @@ func (m launchpadGitDeducer) deduceSource(path string, u *url.URL) (maybeSource,
if !validateVCSScheme(u.Scheme, "git") {
return nil, fmt.Errorf("%s is not a valid scheme for accessing a git repository", u.Scheme)
}
return maybeGitSource{url: u}, nil
return maybeSources{maybeGitSource{url: u}}, nil
}

mb := make(maybeSources, len(gitSchemes))
Expand All @@ -408,7 +408,7 @@ func (m jazzDeducer) deduceRoot(path string) (string, error) {
return "hub.jazz.net" + v[2], nil
}

func (m jazzDeducer) deduceSource(path string, u *url.URL) (maybeSource, error) {
func (m jazzDeducer) deduceSource(path string, u *url.URL) (maybeSources, error) {
v := m.regexp.FindStringSubmatch(path)
if v == nil {
return nil, fmt.Errorf("%s is not a valid path for a source on hub.jazz.net", path)
Expand All @@ -422,7 +422,7 @@ func (m jazzDeducer) deduceSource(path string, u *url.URL) (maybeSource, error)
u.Scheme = "https"
fallthrough
case "https":
return maybeGitSource{url: u}, nil
return maybeSources{maybeGitSource{url: u}}, nil
default:
return nil, fmt.Errorf("IBM's jazz hub only supports https, %s is not allowed", u.String())
}
Expand All @@ -441,7 +441,7 @@ func (m apacheDeducer) deduceRoot(path string) (string, error) {
return "git.apache.org" + v[2], nil
}

func (m apacheDeducer) deduceSource(path string, u *url.URL) (maybeSource, error) {
func (m apacheDeducer) deduceSource(path string, u *url.URL) (maybeSources, error) {
v := m.regexp.FindStringSubmatch(path)
if v == nil {
return nil, fmt.Errorf("%s is not a valid path for a source on git.apache.org", path)
Expand All @@ -454,7 +454,7 @@ func (m apacheDeducer) deduceSource(path string, u *url.URL) (maybeSource, error
if !validateVCSScheme(u.Scheme, "git") {
return nil, fmt.Errorf("%s is not a valid scheme for accessing a git repository", u.Scheme)
}
return maybeGitSource{url: u}, nil
return maybeSources{maybeGitSource{url: u}}, nil
}

mb := make(maybeSources, len(gitSchemes))
Expand All @@ -480,7 +480,7 @@ func (m vcsExtensionDeducer) deduceRoot(path string) (string, error) {
return v[1], nil
}

func (m vcsExtensionDeducer) deduceSource(path string, u *url.URL) (maybeSource, error) {
func (m vcsExtensionDeducer) deduceSource(path string, u *url.URL) (maybeSources, error) {
v := m.regexp.FindStringSubmatch(path)
if v == nil {
return nil, fmt.Errorf("%s contains no vcs extension hints for matching", path)
Expand All @@ -500,11 +500,11 @@ func (m vcsExtensionDeducer) deduceSource(path string, u *url.URL) (maybeSource,

switch v[4] {
case "git":
return maybeGitSource{url: u}, nil
return maybeSources{maybeGitSource{url: u}}, nil
case "bzr":
return maybeBzrSource{url: u}, nil
return maybeSources{maybeBzrSource{url: u}}, nil
case "hg":
return maybeHgSource{url: u}, nil
return maybeSources{maybeHgSource{url: u}}, nil
}
}

Expand Down Expand Up @@ -590,7 +590,7 @@ func (dc *deductionCoordinator) deduceRootPath(ctx context.Context, path string)
dc.mut.RUnlock()
if has && isPathPrefixOrEqual(prefix, path) {
switch d := data.(type) {
case maybeSource:
case maybeSources:
return pathDeduction{root: prefix, mb: d}, nil
case *httpMetadataDeducer:
// Multiple calls have come in for a similar path shape during
Expand Down Expand Up @@ -652,7 +652,7 @@ func (dc *deductionCoordinator) deduceRootPath(ctx context.Context, path string)
// the source.
type pathDeduction struct {
root string
mb maybeSource
mb maybeSources
}

var errNoKnownPathMatch = errors.New("no known path match")
Expand Down Expand Up @@ -759,11 +759,11 @@ func (hmd *httpMetadataDeducer) deduce(ctx context.Context, path string) (pathDe

switch vcs {
case "git":
pd.mb = maybeGitSource{url: repoURL}
pd.mb = maybeSources{maybeGitSource{url: repoURL}}
case "bzr":
pd.mb = maybeBzrSource{url: repoURL}
pd.mb = maybeSources{maybeBzrSource{url: repoURL}}
case "hg":
pd.mb = maybeHgSource{url: repoURL}
pd.mb = maybeSources{maybeHgSource{url: repoURL}}
default:
hmd.deduceErr = errors.Errorf("unsupported vcs type %s in go-get metadata from %s", vcs, path)
return
Expand Down
Loading