@@ -557,7 +557,7 @@ const (
557
557
// repoRootForImportPath analyzes importPath to determine the
558
558
// version control system, and code repository to use.
559
559
func repoRootForImportPath (importPath string , security securityMode ) (* repoRoot , error ) {
560
- rr , err := repoRootForImportPathStatic (importPath , "" , security )
560
+ rr , err := repoRootFromVCSPaths (importPath , "" , security , vcsPaths )
561
561
if err == errUnknownSite {
562
562
// If there are wildcards, look up the thing before the wildcard,
563
563
// hoping it applies to the wildcarded parts too.
@@ -579,6 +579,13 @@ func repoRootForImportPath(importPath string, security securityMode) (*repoRoot,
579
579
err = fmt .Errorf ("unrecognized import path %q" , importPath )
580
580
}
581
581
}
582
+ if err != nil {
583
+ rr1 , err1 := repoRootFromVCSPaths (importPath , "" , security , vcsPathsAfterDynamic )
584
+ if err1 == nil {
585
+ rr = rr1
586
+ err = nil
587
+ }
588
+ }
582
589
583
590
if err == nil && strings .Contains (importPath , "..." ) && strings .Contains (rr .root , "..." ) {
584
591
// Do not allow wildcards in the repo root.
@@ -590,13 +597,10 @@ func repoRootForImportPath(importPath string, security securityMode) (*repoRoot,
590
597
591
598
var errUnknownSite = errors .New ("dynamic lookup required to find mapping" )
592
599
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.
598
602
// 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 ) {
600
604
// A common error is to use https://packagepath because that's what
601
605
// hg and git require. Diagnose this helpfully.
602
606
if loc := httpPrefixRE .FindStringIndex (importPath ); loc != nil {
@@ -831,7 +835,10 @@ func expand(match map[string]string, s string) string {
831
835
return s
832
836
}
833
837
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)
835
842
var vcsPaths = []* vcsPath {
836
843
// Google Code - new syntax
837
844
{
@@ -864,15 +871,6 @@ var vcsPaths = []*vcsPath{
864
871
check : bitbucketVCS ,
865
872
},
866
873
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
-
876
874
// IBM DevOps Services (JazzHub)
877
875
{
878
876
prefix : "hub.jazz.net/git" ,
@@ -891,19 +889,38 @@ var vcsPaths = []*vcsPath{
891
889
},
892
890
893
891
// General syntax for any server.
892
+ // Must be last.
894
893
{
895
894
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_.\-]+)*$` ,
896
895
ping : true ,
897
896
},
898
897
}
899
898
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
+
900
914
func init () {
901
915
// fill in cached regexps.
902
916
// Doing this eagerly discovers invalid regexp syntax
903
917
// without having to run a command that needs that regexp.
904
918
for _ , srv := range vcsPaths {
905
919
srv .regexp = regexp .MustCompile (srv .re )
906
920
}
921
+ for _ , srv := range vcsPathsAfterDynamic {
922
+ srv .regexp = regexp .MustCompile (srv .re )
923
+ }
907
924
}
908
925
909
926
// noVCSSuffix checks that the repository name does not
0 commit comments