Commit 669f5be2 authored by Russ Cox's avatar Russ Cox

cmd/go: prefer <meta> tags on launchpad.net to the hard-coded logic

Fixes #11436.

Change-Id: I5c4455e9b13b478838f23ac31e6343672dfc60af
Reviewed-on: https://go-review.googlesource.com/12143Reviewed-by: 's avatarMichael Hudson-Doyle <michael.hudson@canonical.com>
Reviewed-by: 's avatarIan Lance Taylor <iant@golang.org>
parent fd9b9c31
...@@ -557,7 +557,7 @@ const ( ...@@ -557,7 +557,7 @@ const (
// repoRootForImportPath analyzes importPath to determine the // repoRootForImportPath analyzes importPath to determine the
// version control system, and code repository to use. // version control system, and code repository to use.
func repoRootForImportPath(importPath string, security securityMode) (*repoRoot, error) { func repoRootForImportPath(importPath string, security securityMode) (*repoRoot, error) {
rr, err := repoRootForImportPathStatic(importPath, "", security) rr, err := repoRootFromVCSPaths(importPath, "", security, vcsPaths)
if err == errUnknownSite { if err == errUnknownSite {
// If there are wildcards, look up the thing before the wildcard, // If there are wildcards, look up the thing before the wildcard,
// hoping it applies to the wildcarded parts too. // hoping it applies to the wildcarded parts too.
...@@ -579,6 +579,13 @@ func repoRootForImportPath(importPath string, security securityMode) (*repoRoot, ...@@ -579,6 +579,13 @@ func repoRootForImportPath(importPath string, security securityMode) (*repoRoot,
err = fmt.Errorf("unrecognized import path %q", importPath) err = fmt.Errorf("unrecognized import path %q", importPath)
} }
} }
if err != nil {
rr1, err1 := repoRootFromVCSPaths(importPath, "", security, vcsPathsAfterDynamic)
if err1 == nil {
rr = rr1
err = nil
}
}
if err == nil && strings.Contains(importPath, "...") && strings.Contains(rr.root, "...") { if err == nil && strings.Contains(importPath, "...") && strings.Contains(rr.root, "...") {
// Do not allow wildcards in the repo root. // Do not allow wildcards in the repo root.
...@@ -590,13 +597,10 @@ func repoRootForImportPath(importPath string, security securityMode) (*repoRoot, ...@@ -590,13 +597,10 @@ func repoRootForImportPath(importPath string, security securityMode) (*repoRoot,
var errUnknownSite = errors.New("dynamic lookup required to find mapping") var errUnknownSite = errors.New("dynamic lookup required to find mapping")
// repoRootForImportPathStatic attempts to map importPath to a // repoRootFromVCSPaths attempts to map importPath to a repoRoot
// repoRoot using the commonly-used VCS hosting sites in vcsPaths // using the mappings defined in vcsPaths.
// (github.com/user/dir), or from a fully-qualified importPath already
// containing its VCS type (foo.com/repo.git/dir)
//
// If scheme is non-empty, that scheme is forced. // If scheme is non-empty, that scheme is forced.
func repoRootForImportPathStatic(importPath, scheme string, security securityMode) (*repoRoot, error) { func repoRootFromVCSPaths(importPath, scheme string, security securityMode, vcsPaths []*vcsPath) (*repoRoot, error) {
// A common error is to use https://packagepath because that's what // A common error is to use https://packagepath because that's what
// hg and git require. Diagnose this helpfully. // hg and git require. Diagnose this helpfully.
if loc := httpPrefixRE.FindStringIndex(importPath); loc != nil { if loc := httpPrefixRE.FindStringIndex(importPath); loc != nil {
...@@ -831,7 +835,10 @@ func expand(match map[string]string, s string) string { ...@@ -831,7 +835,10 @@ func expand(match map[string]string, s string) string {
return s return s
} }
// vcsPaths lists the known vcs paths. // vcsPaths defines the meaning of import paths referring to
// commonly-used VCS hosting sites (github.com/user/dir)
// and import paths referring to a fully-qualified importPath
// containing a VCS type (foo.com/repo.git/dir)
var vcsPaths = []*vcsPath{ var vcsPaths = []*vcsPath{
// Google Code - new syntax // Google Code - new syntax
{ {
...@@ -864,15 +871,6 @@ var vcsPaths = []*vcsPath{ ...@@ -864,15 +871,6 @@ var vcsPaths = []*vcsPath{
check: bitbucketVCS, check: bitbucketVCS,
}, },
// Launchpad
{
prefix: "launchpad.net/",
re: `^(?P<root>launchpad\.net/((?P<project>[A-Za-z0-9_.\-]+)(?P<series>/[A-Za-z0-9_.\-]+)?|~[A-Za-z0-9_.\-]+/(\+junk|[A-Za-z0-9_.\-]+)/[A-Za-z0-9_.\-]+))(/[A-Za-z0-9_.\-]+)*$`,
vcs: "bzr",
repo: "https://{root}",
check: launchpadVCS,
},
// IBM DevOps Services (JazzHub) // IBM DevOps Services (JazzHub)
{ {
prefix: "hub.jazz.net/git", prefix: "hub.jazz.net/git",
...@@ -891,12 +889,28 @@ var vcsPaths = []*vcsPath{ ...@@ -891,12 +889,28 @@ var vcsPaths = []*vcsPath{
}, },
// General syntax for any server. // General syntax for any server.
// Must be last.
{ {
re: `^(?P<root>(?P<repo>([a-z0-9.\-]+\.)+[a-z0-9.\-]+(:[0-9]+)?/[A-Za-z0-9_.\-/]*?)\.(?P<vcs>bzr|git|hg|svn))(/[A-Za-z0-9_.\-]+)*$`, re: `^(?P<root>(?P<repo>([a-z0-9.\-]+\.)+[a-z0-9.\-]+(:[0-9]+)?/[A-Za-z0-9_.\-/]*?)\.(?P<vcs>bzr|git|hg|svn))(/[A-Za-z0-9_.\-]+)*$`,
ping: true, ping: true,
}, },
} }
// vcsPathsAfterDynamic gives additional vcsPaths entries
// to try after the dynamic HTML check.
// This gives those sites a chance to introduce <meta> tags
// as part of a graceful transition away from the hard-coded logic.
var vcsPathsAfterDynamic = []*vcsPath{
// Launchpad. See golang.org/issue/11436.
{
prefix: "launchpad.net/",
re: `^(?P<root>launchpad\.net/((?P<project>[A-Za-z0-9_.\-]+)(?P<series>/[A-Za-z0-9_.\-]+)?|~[A-Za-z0-9_.\-]+/(\+junk|[A-Za-z0-9_.\-]+)/[A-Za-z0-9_.\-]+))(/[A-Za-z0-9_.\-]+)*$`,
vcs: "bzr",
repo: "https://{root}",
check: launchpadVCS,
},
}
func init() { func init() {
// fill in cached regexps. // fill in cached regexps.
// Doing this eagerly discovers invalid regexp syntax // Doing this eagerly discovers invalid regexp syntax
...@@ -904,6 +918,9 @@ func init() { ...@@ -904,6 +918,9 @@ func init() {
for _, srv := range vcsPaths { for _, srv := range vcsPaths {
srv.regexp = regexp.MustCompile(srv.re) srv.regexp = regexp.MustCompile(srv.re)
} }
for _, srv := range vcsPathsAfterDynamic {
srv.regexp = regexp.MustCompile(srv.re)
}
} }
// noVCSSuffix checks that the repository name does not // noVCSSuffix checks that the repository name does not
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment