From 669f5be2ac6f761f8c917baa2ba899ed7f64bc14 Mon Sep 17 00:00:00 2001 From: Russ Cox Date: Tue, 14 Jul 2015 02:04:21 -0400 Subject: [PATCH] cmd/go: prefer tags on launchpad.net to the hard-coded logic Fixes #11436. Change-Id: I5c4455e9b13b478838f23ac31e6343672dfc60af Reviewed-on: https://go-review.googlesource.com/12143 Reviewed-by: Michael Hudson-Doyle Reviewed-by: Ian Lance Taylor --- src/cmd/go/vcs.go | 51 +++++++++++++++++++++++++++++++---------------- 1 file changed, 34 insertions(+), 17 deletions(-) diff --git a/src/cmd/go/vcs.go b/src/cmd/go/vcs.go index 8871f77371..2ee1057a58 100644 --- a/src/cmd/go/vcs.go +++ b/src/cmd/go/vcs.go @@ -557,7 +557,7 @@ const ( // repoRootForImportPath analyzes importPath to determine the // version control system, and code repository to use. func repoRootForImportPath(importPath string, security securityMode) (*repoRoot, error) { - rr, err := repoRootForImportPathStatic(importPath, "", security) + rr, err := repoRootFromVCSPaths(importPath, "", security, vcsPaths) if err == errUnknownSite { // If there are wildcards, look up the thing before the wildcard, // hoping it applies to the wildcarded parts too. @@ -579,6 +579,13 @@ func repoRootForImportPath(importPath string, security securityMode) (*repoRoot, 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, "...") { // Do not allow wildcards in the repo root. @@ -590,13 +597,10 @@ func repoRootForImportPath(importPath string, security securityMode) (*repoRoot, var errUnknownSite = errors.New("dynamic lookup required to find mapping") -// repoRootForImportPathStatic attempts to map importPath to a -// repoRoot using the commonly-used VCS hosting sites in vcsPaths -// (github.com/user/dir), or from a fully-qualified importPath already -// containing its VCS type (foo.com/repo.git/dir) -// +// repoRootFromVCSPaths attempts to map importPath to a repoRoot +// using the mappings defined in vcsPaths. // 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 // hg and git require. Diagnose this helpfully. if loc := httpPrefixRE.FindStringIndex(importPath); loc != nil { @@ -831,7 +835,10 @@ func expand(match map[string]string, s string) string { 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{ // Google Code - new syntax { @@ -864,15 +871,6 @@ var vcsPaths = []*vcsPath{ check: bitbucketVCS, }, - // Launchpad - { - prefix: "launchpad.net/", - re: `^(?Plaunchpad\.net/((?P[A-Za-z0-9_.\-]+)(?P/[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) { prefix: "hub.jazz.net/git", @@ -891,12 +889,28 @@ var vcsPaths = []*vcsPath{ }, // General syntax for any server. + // Must be last. { re: `^(?P(?P([a-z0-9.\-]+\.)+[a-z0-9.\-]+(:[0-9]+)?/[A-Za-z0-9_.\-/]*?)\.(?Pbzr|git|hg|svn))(/[A-Za-z0-9_.\-]+)*$`, ping: true, }, } +// vcsPathsAfterDynamic gives additional vcsPaths entries +// to try after the dynamic HTML check. +// This gives those sites a chance to introduce 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: `^(?Plaunchpad\.net/((?P[A-Za-z0-9_.\-]+)(?P/[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() { // fill in cached regexps. // Doing this eagerly discovers invalid regexp syntax @@ -904,6 +918,9 @@ func init() { for _, srv := range vcsPaths { srv.regexp = regexp.MustCompile(srv.re) } + for _, srv := range vcsPathsAfterDynamic { + srv.regexp = regexp.MustCompile(srv.re) + } } // noVCSSuffix checks that the repository name does not -- 2.48.1