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

add SourceURLsForPath() to SourceManager interface #1166

Merged

Conversation

michael-go
Copy link
Contributor

What does this do / why do we need it?

This exposes all possible source URLs that are deduced for a given import path.

This PR was created to accommodate #1149 (gvt importer), following @sdboyer 's advice.
gvt allows the user to specify an alternate url (e.g. fork) for a vendored import, via the Repository field in the manifest. However, all packages that are listed in the manifest have the Repository field even if it points to the original source URL.
gps already has a complex logic of deducing the source URLs given an import, however the actual URLs are not exposed to the callers of SourceManager. The new exported SourceURLsForPath() will allow the importers to understand if the a URL is a not a default one, and only in such a case, pass it as a constraint.

This change required a slight modification to gps's internal maybeSource interface and some refactoring to the various implementations: the getURL() string method (which wasn't called anywhere) was changed to possibleURLs() []*url.URL. In addition a small change was done to the gopkg.in deducer.

to expose the deduced possible source URLs for a given import path.
This information is useful for importing configuration from other tools
that support vendoring forks
@michael-go michael-go changed the title add SourceURLsForPath to SourceManager ineterface add SourceURLsForPath() to SourceManager ineterface Sep 13, 2017
@michael-go
Copy link
Contributor Author

michael-go commented Sep 13, 2017

CodeClimate doesn't like me using context.TODO() 🤓 can someone please help me disable this check like already probably done for all other uses of context.TODO() in the same file (source_manager.go).
Thanks!

@carolynvs
Copy link
Collaborator

Don't worry about the code climate error, we can ignore it when we merge.

Copy link
Member

@sdboyer sdboyer left a comment

Choose a reason for hiding this comment

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

this looks generally good, and is hooking into the right test. basically just some nits on wording in errors and docs!

for _, url := range mb.possibleURLs() {
urls += url.String() + "\n"
}
errs = append(errs, errors.Wrapf(err, "failed to set up %q", urls))
Copy link
Member

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.)

@@ -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
Copy link
Member

Choose a reason for hiding this comment

The 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."

@michael-go
Copy link
Contributor Author

Thanks @sdboyer, fixed the comment & error string

for _, url := range mb.possibleURLs() {
urls += url.String() + "\n"
}
errs = append(errs, errors.Wrapf(err, "failed to set sources from the following URLs:\n%s", urls))
Copy link
Member

Choose a reason for hiding this comment

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

🤦‍♂️

i fatfingered that. i meant "failed to set up sources from the following URLs:\n" - sorry!

@michael-go
Copy link
Contributor Author

Thanks @sdboyer - fixed the typo

and an error msg in `maybeSources.try()`
@michael-go michael-go force-pushed the source-manager-expose-deduced-sources branch from 450d24f to 348b869 Compare September 19, 2017 07:48
@sdboyer sdboyer merged commit 118a565 into golang:master Sep 19, 2017
@darkowlzz darkowlzz changed the title add SourceURLsForPath() to SourceManager ineterface add SourceURLsForPath() to SourceManager interface Oct 7, 2017
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants