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

Commit 338675d

Browse files
authoredFeb 24, 2018
Merge pull request #1250 from jmank88/source_opt
gps: fine grained source transitions
2 parents b0a2e0f + 98031fc commit 338675d

22 files changed

+899
-784
lines changed
 

‎CHANGELOG.md

+3
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ BUG FIXES:
99

1010
IMPROVEMENTS:
1111

12+
* Reduce network access by trusting local source information and only pulling
13+
from upstream when necessary ([#1250](https://github.com/golang/dep/pull/1250)).
14+
1215
# v0.4.1
1316

1417
NEW FEATURES:

‎gps/deduce.go

+24-24
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ type pathDeducer interface {
104104
// So the return of the above string would be
105105
// "github.com/some-user/some-package"
106106
deduceRoot(string) (string, error)
107-
deduceSource(string, *url.URL) (maybeSource, error)
107+
deduceSource(string, *url.URL) (maybeSources, error)
108108
}
109109

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

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

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

170-
func (m bitbucketDeducer) deduceSource(path string, u *url.URL) (maybeSource, error) {
170+
func (m bitbucketDeducer) deduceSource(path string, u *url.URL) (maybeSources, error) {
171171
v := m.regexp.FindStringSubmatch(path)
172172
if v == nil {
173173
return nil, fmt.Errorf("%s is not a valid path for a source on bitbucket.org", path)
@@ -189,12 +189,12 @@ func (m bitbucketDeducer) deduceSource(path string, u *url.URL) (maybeSource, er
189189
// superset of the hg schemes
190190
return nil, fmt.Errorf("%s is not a valid scheme for accessing a git repository", u.Scheme)
191191
}
192-
return maybeGitSource{url: u}, nil
192+
return maybeSources{maybeGitSource{url: u}}, nil
193193
} else if ishg {
194194
if !validhg {
195195
return nil, fmt.Errorf("%s is not a valid scheme for accessing an hg repository", u.Scheme)
196196
}
197-
return maybeHgSource{url: u}, nil
197+
return maybeSources{maybeHgSource{url: u}}, nil
198198
} else if !validgit && !validhg {
199199
return nil, fmt.Errorf("%s is not a valid scheme for accessing either a git or hg repository", u.Scheme)
200200
}
@@ -265,7 +265,7 @@ func (m gopkginDeducer) parseAndValidatePath(p string) ([]string, error) {
265265
return v, nil
266266
}
267267

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

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

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

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

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

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

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

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

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

501501
switch v[4] {
502502
case "git":
503-
return maybeGitSource{url: u}, nil
503+
return maybeSources{maybeGitSource{url: u}}, nil
504504
case "bzr":
505-
return maybeBzrSource{url: u}, nil
505+
return maybeSources{maybeBzrSource{url: u}}, nil
506506
case "hg":
507-
return maybeHgSource{url: u}, nil
507+
return maybeSources{maybeHgSource{url: u}}, nil
508508
}
509509
}
510510

@@ -590,7 +590,7 @@ func (dc *deductionCoordinator) deduceRootPath(ctx context.Context, path string)
590590
dc.mut.RUnlock()
591591
if has && isPathPrefixOrEqual(prefix, path) {
592592
switch d := data.(type) {
593-
case maybeSource:
593+
case maybeSources:
594594
return pathDeduction{root: prefix, mb: d}, nil
595595
case *httpMetadataDeducer:
596596
// Multiple calls have come in for a similar path shape during
@@ -652,7 +652,7 @@ func (dc *deductionCoordinator) deduceRootPath(ctx context.Context, path string)
652652
// the source.
653653
type pathDeduction struct {
654654
root string
655-
mb maybeSource
655+
mb maybeSources
656656
}
657657

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

760760
switch vcs {
761761
case "git":
762-
pd.mb = maybeGitSource{url: repoURL}
762+
pd.mb = maybeSources{maybeGitSource{url: repoURL}}
763763
case "bzr":
764-
pd.mb = maybeBzrSource{url: repoURL}
764+
pd.mb = maybeSources{maybeBzrSource{url: repoURL}}
765765
case "hg":
766-
pd.mb = maybeHgSource{url: repoURL}
766+
pd.mb = maybeSources{maybeHgSource{url: repoURL}}
767767
default:
768768
hmd.deduceErr = errors.Errorf("unsupported vcs type %s in go-get metadata from %s", vcs, path)
769769
return

0 commit comments

Comments
 (0)