|
|
@@ -59,6 +59,7 @@ var gogetTemplate = template.Must(template.New("").Parse(` |
|
|
|
<html> |
|
|
|
<head> |
|
|
|
<meta name="go-import" content="{{.GopkgRoot}} git https://{{.GopkgRoot}}"> |
|
|
|
{{$root := .GitHubRoot}}{{$tree := .GitHubTree}}<meta name="go-source" content="{{.GopkgRoot}} _ https://{{$root}}/tree/{{$tree}}{/dir} https://{{$root}}/blob/{{$tree}}{/dir}/{file}#L{line}"> |
|
|
|
</head> |
|
|
|
<body> |
|
|
|
go get {{.GopkgPath}} |
|
|
@@ -73,7 +74,26 @@ type Repo struct { |
|
|
|
SubPath string |
|
|
|
OldFormat bool // The old /v2/pkg format. |
|
|
|
MajorVersion Version |
|
|
|
AllVersions VersionList |
|
|
|
|
|
|
|
// FullVersion is the best version in AllVersions that matches MajorVersion. |
|
|
|
// It defaults to InvalidVersion if there are no matches. |
|
|
|
FullVersion Version |
|
|
|
|
|
|
|
// AllVersions holds all versions currently available in the repository, |
|
|
|
// either coming from branch names or from tag names. Version zero (v0) |
|
|
|
// is only present in the list if it really exists in the repository. |
|
|
|
AllVersions VersionList |
|
|
|
} |
|
|
|
|
|
|
|
// SetVersions records in the relevant fields the details about which |
|
|
|
// package versions are available in the repository. |
|
|
|
func (repo *Repo) SetVersions(all []Version) { |
|
|
|
repo.AllVersions = all |
|
|
|
for _, v := range repo.AllVersions { |
|
|
|
if v.Major == repo.MajorVersion.Major && v.Unstable == repo.MajorVersion.Unstable && repo.FullVersion.Less(v) { |
|
|
|
repo.FullVersion = v |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// GitHubRoot returns the repository root at GitHub, without a schema. |
|
|
@@ -85,6 +105,14 @@ func (repo *Repo) GitHubRoot() string { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
// GitHubTree returns the repository tree name at GitHub for the selected version. |
|
|
|
func (repo *Repo) GitHubTree() string { |
|
|
|
if repo.FullVersion == InvalidVersion { |
|
|
|
return "master" |
|
|
|
} |
|
|
|
return repo.FullVersion.String() |
|
|
|
} |
|
|
|
|
|
|
|
// GopkgRoot returns the package root at gopkg.in, without a schema. |
|
|
|
func (repo *Repo) GopkgRoot() string { |
|
|
|
return repo.GopkgVersionRoot(repo.MajorVersion) |
|
|
@@ -153,10 +181,11 @@ func handler(resp http.ResponseWriter, req *http.Request) { |
|
|
|
} |
|
|
|
|
|
|
|
repo := &Repo{ |
|
|
|
User: m[1], |
|
|
|
Name: m[2], |
|
|
|
SubPath: m[5], |
|
|
|
OldFormat: oldFormat, |
|
|
|
User: m[1], |
|
|
|
Name: m[2], |
|
|
|
SubPath: m[5], |
|
|
|
OldFormat: oldFormat, |
|
|
|
FullVersion: InvalidVersion, |
|
|
|
} |
|
|
|
|
|
|
|
var ok bool |
|
|
@@ -167,9 +196,11 @@ func handler(resp http.ResponseWriter, req *http.Request) { |
|
|
|
} |
|
|
|
|
|
|
|
var changed []byte |
|
|
|
var versions VersionList |
|
|
|
original, err := fetchRefs(repo) |
|
|
|
if err == nil { |
|
|
|
changed, repo.AllVersions, err = changeRefs(original, repo.MajorVersion) |
|
|
|
changed, versions, err = changeRefs(original, repo.MajorVersion) |
|
|
|
repo.SetVersions(versions) |
|
|
|
} |
|
|
|
|
|
|
|
switch err { |
|
|
@@ -338,7 +369,7 @@ func changeRefs(data []byte, major Version) (changed []byte, versions VersionLis |
|
|
|
} |
|
|
|
|
|
|
|
var buf bytes.Buffer |
|
|
|
buf.Grow(len(data)+256) |
|
|
|
buf.Grow(len(data) + 256) |
|
|
|
|
|
|
|
// Copy the header as-is. |
|
|
|
buf.Write(data[:hlinei]) |
|
|
@@ -346,7 +377,7 @@ func changeRefs(data []byte, major Version) (changed []byte, versions VersionLis |
|
|
|
// Extract the original capabilities. |
|
|
|
caps := "" |
|
|
|
if i := strings.Index(sdata[hlinei:hlinej], "\x00"); i > 0 { |
|
|
|
caps = strings.Replace(sdata[hlinei+i+1:hlinej-1], "symref=", "oldref=", -1) |
|
|
|
caps = strings.Replace(sdata[hlinei+i+1:hlinej-1], "symref=", "oldref=", -1) |
|
|
|
} |
|
|
|
|
|
|
|
// Insert the HEAD reference line with the right hash and a proper symref capability. |
|
|
|