This repository has been archived by the owner on Sep 9, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1k
add SourceURLsForPath() to SourceManager interface #1166
Merged
sdboyer
merged 2 commits into
golang:master
from
michael-go:source-manager-expose-deduced-sources
Sep 19, 2017
Merged
Changes from 1 commit
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -132,8 +132,6 @@ var pathDeductionFixtures = map[string][]pathDeductionFixture{ | |
root: "gopkg.in/sdboyer/gps.v0", | ||
mb: maybeSources{ | ||
maybeGopkginSource{opath: "gopkg.in/sdboyer/gps.v0", url: mkurl("https://github.com/sdboyer/gps"), major: 0}, | ||
maybeGopkginSource{opath: "gopkg.in/sdboyer/gps.v0", url: mkurl("ssh://[email protected]/sdboyer/gps"), major: 0}, | ||
maybeGopkginSource{opath: "gopkg.in/sdboyer/gps.v0", url: mkurl("git://github.com/sdboyer/gps"), major: 0}, | ||
maybeGopkginSource{opath: "gopkg.in/sdboyer/gps.v0", url: mkurl("http://github.com/sdboyer/gps"), major: 0}, | ||
}, | ||
}, | ||
|
@@ -142,8 +140,6 @@ var pathDeductionFixtures = map[string][]pathDeductionFixture{ | |
root: "gopkg.in/sdboyer/gps.v0", | ||
mb: maybeSources{ | ||
maybeGopkginSource{opath: "gopkg.in/sdboyer/gps.v0", url: mkurl("https://github.com/sdboyer/gps"), major: 0}, | ||
maybeGopkginSource{opath: "gopkg.in/sdboyer/gps.v0", url: mkurl("ssh://[email protected]/sdboyer/gps"), major: 0}, | ||
maybeGopkginSource{opath: "gopkg.in/sdboyer/gps.v0", url: mkurl("git://github.com/sdboyer/gps"), major: 0}, | ||
maybeGopkginSource{opath: "gopkg.in/sdboyer/gps.v0", url: mkurl("http://github.com/sdboyer/gps"), major: 0}, | ||
}, | ||
}, | ||
|
@@ -152,8 +148,6 @@ var pathDeductionFixtures = map[string][]pathDeductionFixture{ | |
root: "gopkg.in/sdboyer/gps.v1", | ||
mb: maybeSources{ | ||
maybeGopkginSource{opath: "gopkg.in/sdboyer/gps.v1", url: mkurl("https://github.com/sdboyer/gps"), major: 1}, | ||
maybeGopkginSource{opath: "gopkg.in/sdboyer/gps.v1", url: mkurl("ssh://[email protected]/sdboyer/gps"), major: 1}, | ||
maybeGopkginSource{opath: "gopkg.in/sdboyer/gps.v1", url: mkurl("git://github.com/sdboyer/gps"), major: 1}, | ||
maybeGopkginSource{opath: "gopkg.in/sdboyer/gps.v1", url: mkurl("http://github.com/sdboyer/gps"), major: 1}, | ||
}, | ||
}, | ||
|
@@ -162,8 +156,6 @@ var pathDeductionFixtures = map[string][]pathDeductionFixture{ | |
root: "gopkg.in/yaml.v1", | ||
mb: maybeSources{ | ||
maybeGopkginSource{opath: "gopkg.in/yaml.v1", url: mkurl("https://github.com/go-yaml/yaml"), major: 1}, | ||
maybeGopkginSource{opath: "gopkg.in/yaml.v1", url: mkurl("ssh://[email protected]/go-yaml/yaml"), major: 1}, | ||
maybeGopkginSource{opath: "gopkg.in/yaml.v1", url: mkurl("git://github.com/go-yaml/yaml"), major: 1}, | ||
maybeGopkginSource{opath: "gopkg.in/yaml.v1", url: mkurl("http://github.com/go-yaml/yaml"), major: 1}, | ||
}, | ||
}, | ||
|
@@ -172,8 +164,6 @@ var pathDeductionFixtures = map[string][]pathDeductionFixture{ | |
root: "gopkg.in/yaml.v1", | ||
mb: maybeSources{ | ||
maybeGopkginSource{opath: "gopkg.in/yaml.v1", url: mkurl("https://github.com/go-yaml/yaml"), major: 1}, | ||
maybeGopkginSource{opath: "gopkg.in/yaml.v1", url: mkurl("ssh://[email protected]/go-yaml/yaml"), major: 1}, | ||
maybeGopkginSource{opath: "gopkg.in/yaml.v1", url: mkurl("git://github.com/go-yaml/yaml"), major: 1}, | ||
maybeGopkginSource{opath: "gopkg.in/yaml.v1", url: mkurl("http://github.com/go-yaml/yaml"), major: 1}, | ||
}, | ||
}, | ||
|
@@ -182,8 +172,6 @@ var pathDeductionFixtures = map[string][]pathDeductionFixture{ | |
root: "gopkg.in/inf.v0", | ||
mb: maybeSources{ | ||
maybeGopkginSource{opath: "gopkg.in/inf.v0", url: mkurl("https://github.com/go-inf/inf"), major: 0}, | ||
maybeGopkginSource{opath: "gopkg.in/inf.v0", url: mkurl("ssh://[email protected]/go-inf/inf"), major: 0}, | ||
maybeGopkginSource{opath: "gopkg.in/inf.v0", url: mkurl("git://github.com/go-inf/inf"), major: 0}, | ||
maybeGopkginSource{opath: "gopkg.in/inf.v0", url: mkurl("http://github.com/go-inf/inf"), major: 0}, | ||
}, | ||
}, | ||
|
@@ -582,6 +570,11 @@ func TestDeduceFromPath(t *testing.T) { | |
} else { | ||
t.Errorf("Deducer did not return expected source:\n\t(GOT) %s\n\t(WNT) %s", printmb(mb, t), printmb(fix.mb, t)) | ||
} | ||
} else { | ||
gotURLs, wantURLs := mb.possibleURLs(), fix.mb.possibleURLs() | ||
if !reflect.DeepEqual(gotURLs, wantURLs) { | ||
t.Errorf("Deducer did not return expected source:\n\t(GOT) %s\n\t(WNT) %s", gotURLs, wantURLs) | ||
} | ||
} | ||
}) | ||
} | ||
|
@@ -634,6 +627,19 @@ func TestVanityDeduction(t *testing.T) { | |
if goturl != wanturl { | ||
t.Errorf("Deduced repo ident does not match fixture:\n\t(GOT) %s\n\t(WNT) %s", goturl, wanturl) | ||
} | ||
|
||
urls, err := sm.SourceURLsForPath(fix.in) | ||
if err != nil { | ||
t.Errorf("Unexpected err on deducing source urls: %s", err) | ||
return | ||
} | ||
if len(urls) != 1 { | ||
t.Errorf("Deduced source URLs count for a vanity import should be 1, got %d", len(urls)) | ||
} | ||
goturl = urls[0].String() | ||
if goturl != wanturl { | ||
t.Errorf("Deduced source URL does not match fixture:\n\t(GOT) %s\n\t(WNT) %s", goturl, wanturl) | ||
} | ||
}) | ||
} | ||
} | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -9,6 +9,7 @@ import ( | |
"fmt" | ||
"io/ioutil" | ||
"log" | ||
"net/url" | ||
"os" | ||
"os/signal" | ||
"path/filepath" | ||
|
@@ -71,6 +72,9 @@ type SourceManager interface { | |
// project/source root. | ||
DeduceProjectRoot(ip string) (ProjectRoot, error) | ||
|
||
// SourceURLsForPath takes an import path and deduces the possible source URLs | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. let's be a little more verbose and explanatory with this: "SourceURLsForPath takes an import path and deduces the set of source URLs that may refer to a canonical upstream source. In general, these URLs differ only by protocol (e.g. https vs. ssh), not path." |
||
SourceURLsForPath(ip string) ([]*url.URL, error) | ||
|
||
// Release lets go of any locks held by the SourceManager. Once called, it is | ||
// no longer safe to call methods against it; all method calls will | ||
// immediately result in errors. | ||
|
@@ -536,6 +540,17 @@ func (sm *SourceMgr) InferConstraint(s string, pi ProjectIdentifier) (Constraint | |
return nil, errors.Errorf("%s is not a valid version for the package %s(%s)", s, pi.ProjectRoot, pi.Source) | ||
} | ||
|
||
// SourceURLsForPath takes an import path, deduces it's root path, | ||
// and returns a list of possible souce URLs for fetching it | ||
func (sm *SourceMgr) SourceURLsForPath(ip string) ([]*url.URL, error) { | ||
deduced, err := sm.deduceCoord.deduceRootPath(context.TODO(), ip) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return deduced.mb.possibleURLs(), nil | ||
} | ||
|
||
// disambiguateRevision looks up a revision in the underlying source, spitting | ||
// it back out in an unabbreviated, disambiguated form. | ||
// | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: let's make an incremental improvement on the output we currently have and change the message to
"failed to set sources from the following URLs:\n%s"
.(note also, use
%s
instead of%q
, as otherwise we'll end up quoting the whole group of URLs, which i don't think makes a ton of sense.)