Skip to content

Commit 669f5be

Browse files
committed
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/12143 Reviewed-by: Michael Hudson-Doyle <[email protected]> Reviewed-by: Ian Lance Taylor <[email protected]>
1 parent fd9b9c3 commit 669f5be

File tree

1 file changed

+34
-17
lines changed

1 file changed

+34
-17
lines changed

src/cmd/go/vcs.go

Lines changed: 34 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -557,7 +557,7 @@ const (
557557
// repoRootForImportPath analyzes importPath to determine the
558558
// version control system, and code repository to use.
559559
func repoRootForImportPath(importPath string, security securityMode) (*repoRoot, error) {
560-
rr, err := repoRootForImportPathStatic(importPath, "", security)
560+
rr, err := repoRootFromVCSPaths(importPath, "", security, vcsPaths)
561561
if err == errUnknownSite {
562562
// If there are wildcards, look up the thing before the wildcard,
563563
// hoping it applies to the wildcarded parts too.
@@ -579,6 +579,13 @@ func repoRootForImportPath(importPath string, security securityMode) (*repoRoot,
579579
err = fmt.Errorf("unrecognized import path %q", importPath)
580580
}
581581
}
582+
if err != nil {
583+
rr1, err1 := repoRootFromVCSPaths(importPath, "", security, vcsPathsAfterDynamic)
584+
if err1 == nil {
585+
rr = rr1
586+
err = nil
587+
}
588+
}
582589

583590
if err == nil && strings.Contains(importPath, "...") && strings.Contains(rr.root, "...") {
584591
// Do not allow wildcards in the repo root.
@@ -590,13 +597,10 @@ func repoRootForImportPath(importPath string, security securityMode) (*repoRoot,
590597

591598
var errUnknownSite = errors.New("dynamic lookup required to find mapping")
592599

593-
// repoRootForImportPathStatic attempts to map importPath to a
594-
// repoRoot using the commonly-used VCS hosting sites in vcsPaths
595-
// (github.com/user/dir), or from a fully-qualified importPath already
596-
// containing its VCS type (foo.com/repo.git/dir)
597-
//
600+
// repoRootFromVCSPaths attempts to map importPath to a repoRoot
601+
// using the mappings defined in vcsPaths.
598602
// If scheme is non-empty, that scheme is forced.
599-
func repoRootForImportPathStatic(importPath, scheme string, security securityMode) (*repoRoot, error) {
603+
func repoRootFromVCSPaths(importPath, scheme string, security securityMode, vcsPaths []*vcsPath) (*repoRoot, error) {
600604
// A common error is to use https://packagepath because that's what
601605
// hg and git require. Diagnose this helpfully.
602606
if loc := httpPrefixRE.FindStringIndex(importPath); loc != nil {
@@ -831,7 +835,10 @@ func expand(match map[string]string, s string) string {
831835
return s
832836
}
833837

834-
// vcsPaths lists the known vcs paths.
838+
// vcsPaths defines the meaning of import paths referring to
839+
// commonly-used VCS hosting sites (github.com/user/dir)
840+
// and import paths referring to a fully-qualified importPath
841+
// containing a VCS type (foo.com/repo.git/dir)
835842
var vcsPaths = []*vcsPath{
836843
// Google Code - new syntax
837844
{
@@ -864,15 +871,6 @@ var vcsPaths = []*vcsPath{
864871
check: bitbucketVCS,
865872
},
866873

867-
// Launchpad
868-
{
869-
prefix: "launchpad.net/",
870-
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_.\-]+)*$`,
871-
vcs: "bzr",
872-
repo: "https://{root}",
873-
check: launchpadVCS,
874-
},
875-
876874
// IBM DevOps Services (JazzHub)
877875
{
878876
prefix: "hub.jazz.net/git",
@@ -891,19 +889,38 @@ var vcsPaths = []*vcsPath{
891889
},
892890

893891
// General syntax for any server.
892+
// Must be last.
894893
{
895894
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_.\-]+)*$`,
896895
ping: true,
897896
},
898897
}
899898

899+
// vcsPathsAfterDynamic gives additional vcsPaths entries
900+
// to try after the dynamic HTML check.
901+
// This gives those sites a chance to introduce <meta> tags
902+
// as part of a graceful transition away from the hard-coded logic.
903+
var vcsPathsAfterDynamic = []*vcsPath{
904+
// Launchpad. See golang.org/issue/11436.
905+
{
906+
prefix: "launchpad.net/",
907+
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_.\-]+)*$`,
908+
vcs: "bzr",
909+
repo: "https://{root}",
910+
check: launchpadVCS,
911+
},
912+
}
913+
900914
func init() {
901915
// fill in cached regexps.
902916
// Doing this eagerly discovers invalid regexp syntax
903917
// without having to run a command that needs that regexp.
904918
for _, srv := range vcsPaths {
905919
srv.regexp = regexp.MustCompile(srv.re)
906920
}
921+
for _, srv := range vcsPathsAfterDynamic {
922+
srv.regexp = regexp.MustCompile(srv.re)
923+
}
907924
}
908925

909926
// noVCSSuffix checks that the repository name does not

0 commit comments

Comments
 (0)