Skip to content
This repository has been archived by the owner on Sep 9, 2020. It is now read-only.

gps: remove unused gopkgin code #1447

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 2 additions & 23 deletions gps/deduce.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,11 +12,10 @@ import (
"net/url"
"path"
"regexp"
"strconv"
"strings"
"sync"

radix "github.com/armon/go-radix"
"github.com/armon/go-radix"
"github.com/pkg/errors"
)

Expand All @@ -28,8 +27,6 @@ var (
gopkginSchemes = []string{"https", "http"}
)

const gopkgUnstableSuffix = "-unstable"

func validateVCSScheme(scheme, typ string) bool {
// everything allows plain ssh
if scheme == "ssh" {
Expand Down Expand Up @@ -286,29 +283,11 @@ func (m gopkginDeducer) deduceSource(p string, u *url.URL) (maybeSource, error)
u.Path = path.Join(v[2], v[3])
}

unstable := false
majorStr := v[4]

if strings.HasSuffix(majorStr, gopkgUnstableSuffix) {
unstable = true
majorStr = strings.TrimSuffix(majorStr, gopkgUnstableSuffix)
}
major, err := strconv.ParseUint(majorStr[1:], 10, 64)
if err != nil {
// this should only be reachable if there's an error in the regex
return nil, fmt.Errorf("could not parse %q as a gopkg.in major version", majorStr[1:])
}

mb := make(maybeSources, len(gopkginSchemes))
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are we modifying a github url with gopkginSchemes?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's supposed to be a conservative approach, mirroring gopkg.in's current behavior most closely: the real, running service supports only http and https, not ssh or git.

for k, scheme := range gopkginSchemes {
u2 := *u
u2.Scheme = scheme
mb[k] = maybeGopkginSource{
opath: v[1],
url: &u2,
major: major,
unstable: unstable,
}
mb[k] = maybeGitSource{url: &u2}
}

return mb, nil
Expand Down
26 changes: 12 additions & 14 deletions gps/deduce_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -131,48 +131,48 @@ var pathDeductionFixtures = map[string][]pathDeductionFixture{
in: "gopkg.in/sdboyer/gps.v0",
root: "gopkg.in/sdboyer/gps.v0",
mb: maybeSources{
maybeGopkginSource{opath: "gopkg.in/sdboyer/gps.v0", url: mkurl("https://github.com/sdboyer/gps"), major: 0},
maybeGopkginSource{opath: "gopkg.in/sdboyer/gps.v0", url: mkurl("http://github.com/sdboyer/gps"), major: 0},
maybeGitSource{url: mkurl("https://github.com/sdboyer/gps")},
maybeGitSource{url: mkurl("http://github.com/sdboyer/gps")},
},
},
{
in: "gopkg.in/sdboyer/gps.v0/foo",
root: "gopkg.in/sdboyer/gps.v0",
mb: maybeSources{
maybeGopkginSource{opath: "gopkg.in/sdboyer/gps.v0", url: mkurl("https://github.com/sdboyer/gps"), major: 0},
maybeGopkginSource{opath: "gopkg.in/sdboyer/gps.v0", url: mkurl("http://github.com/sdboyer/gps"), major: 0},
maybeGitSource{url: mkurl("https://github.com/sdboyer/gps")},
maybeGitSource{url: mkurl("http://github.com/sdboyer/gps")},
},
},
{
in: "gopkg.in/sdboyer/gps.v1/foo/bar",
root: "gopkg.in/sdboyer/gps.v1",
mb: maybeSources{
maybeGopkginSource{opath: "gopkg.in/sdboyer/gps.v1", url: mkurl("https://github.com/sdboyer/gps"), major: 1},
maybeGopkginSource{opath: "gopkg.in/sdboyer/gps.v1", url: mkurl("http://github.com/sdboyer/gps"), major: 1},
maybeGitSource{url: mkurl("https://github.com/sdboyer/gps")},
maybeGitSource{url: mkurl("http://github.com/sdboyer/gps")},
},
},
{
in: "gopkg.in/yaml.v1",
root: "gopkg.in/yaml.v1",
mb: maybeSources{
maybeGopkginSource{opath: "gopkg.in/yaml.v1", url: mkurl("https://github.com/go-yaml/yaml"), major: 1},
maybeGopkginSource{opath: "gopkg.in/yaml.v1", url: mkurl("http://github.com/go-yaml/yaml"), major: 1},
maybeGitSource{url: mkurl("https://github.com/go-yaml/yaml")},
maybeGitSource{url: mkurl("http://github.com/go-yaml/yaml")},
},
},
{
in: "gopkg.in/yaml.v1/foo/bar",
root: "gopkg.in/yaml.v1",
mb: maybeSources{
maybeGopkginSource{opath: "gopkg.in/yaml.v1", url: mkurl("https://github.com/go-yaml/yaml"), major: 1},
maybeGopkginSource{opath: "gopkg.in/yaml.v1", url: mkurl("http://github.com/go-yaml/yaml"), major: 1},
maybeGitSource{url: mkurl("https://github.com/go-yaml/yaml")},
maybeGitSource{url: mkurl("http://github.com/go-yaml/yaml")},
},
},
{
in: "gopkg.in/inf.v0",
root: "gopkg.in/inf.v0",
mb: maybeSources{
maybeGopkginSource{opath: "gopkg.in/inf.v0", url: mkurl("https://github.com/go-inf/inf"), major: 0},
maybeGopkginSource{opath: "gopkg.in/inf.v0", url: mkurl("http://github.com/go-inf/inf"), major: 0},
maybeGitSource{url: mkurl("https://github.com/go-inf/inf")},
maybeGitSource{url: mkurl("http://github.com/go-inf/inf")},
},
},
{
Expand Down Expand Up @@ -517,8 +517,6 @@ func TestDeduceFromPath(t *testing.T) {
return fmt.Sprintf("%T: %s", tmb, ufmt(tmb.url))
case maybeHgSource:
return fmt.Sprintf("%T: %s", tmb, ufmt(tmb.url))
case maybeGopkginSource:
return fmt.Sprintf("%T: %s (v%v) %s ", tmb, tmb.opath, tmb.major, ufmt(tmb.url))
default:
t.Errorf("Unknown maybeSource type: %T", mb)
}
Expand Down
46 changes: 24 additions & 22 deletions gps/manager_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,24 +376,26 @@ func (f sourceCreationTestFixture) run(t *testing.T) {
t.Errorf("want %v gateways in the sources map, but got %v", f.srccount, len(sm.srcCoord.srcs))
}

var keys []string
for k := range sm.srcCoord.nameToURL {
keys = append(keys, k)
}
sort.Strings(keys)
if t.Failed() {
var keys []string
for k := range sm.srcCoord.nameToURL {
keys = append(keys, k)
}
sort.Strings(keys)

var buf bytes.Buffer
w := tabwriter.NewWriter(&buf, 0, 4, 2, ' ', 0)
fmt.Fprint(w, "NAME\tMAPPED URL\n")
for _, r := range keys {
fmt.Fprintf(w, "%s\t%s\n", r, sm.srcCoord.nameToURL[r])
}
w.Flush()
t.Log("\n", buf.String())
var buf bytes.Buffer
w := tabwriter.NewWriter(&buf, 0, 4, 2, ' ', 0)
fmt.Fprint(w, "NAME\tMAPPED URL\n")
for _, r := range keys {
fmt.Fprintf(w, "%s\t%s\n", r, sm.srcCoord.nameToURL[r])
}
w.Flush()
t.Log("\n", buf.String())

t.Log("SRC KEYS")
for k := range sm.srcCoord.srcs {
t.Log(k)
t.Log("SRC KEYS")
for k := range sm.srcCoord.srcs {
t.Log(k)
}
}
}

Expand All @@ -407,22 +409,22 @@ func TestSourceCreationCounts(t *testing.T) {
}

fixtures := map[string]sourceCreationTestFixture{
"gopkgin uniqueness": {
"gopkgin merge": {
roots: []ProjectIdentifier{
mkPI("gopkg.in/sdboyer/gpkt.v1"),
mkPI("gopkg.in/sdboyer/gpkt.v2"),
mkPI("gopkg.in/sdboyer/gpkt.v3"),
},
namecount: 6,
srccount: 3,
namecount: 4,
srccount: 1,
},
"gopkgin separation from github": {
"gopkgin maps to github": {
roots: []ProjectIdentifier{
mkPI("gopkg.in/sdboyer/gpkt.v1"),
mkPI("github.com/sdboyer/gpkt"),
},
namecount: 4,
srccount: 2,
namecount: 3,
srccount: 1,
},
"case variance across path and URL-based access": {
roots: []ProjectIdentifier{
Expand Down
61 changes: 0 additions & 61 deletions gps/maybe_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,67 +122,6 @@ func (m maybeGitSource) possibleURLs() []*url.URL {
return []*url.URL{m.url}
}

type maybeGopkginSource struct {
// the original gopkg.in import path. this is used to create the on-disk
// location to avoid duplicate resource management - e.g., if instances of
// a gopkg.in project are accessed via different schemes, or if the
// underlying github repository is accessed directly.
opath string
// the actual upstream URL - always github
url *url.URL
// the major version to apply for filtering
major uint64
// whether or not the source package is "unstable"
unstable bool
}

func (m maybeGopkginSource) try(ctx context.Context, cachedir string, c singleSourceCache, superv *supervisor) (source, sourceState, error) {
// We don't actually need a fully consistent transform into the on-disk path
// - just something that's unique to the particular gopkg.in domain context.
// So, it's OK to just dumb-join the scheme with the path.
aliasURL := m.url.Scheme + "://" + m.opath
path := sourceCachePath(cachedir, aliasURL)
ustr := m.url.String()

r, err := newCtxRepo(vcs.Git, ustr, path)
if err != nil {
return nil, 0, unwrapVcsErr(err)
}

src := &gopkginSource{
gitSource: gitSource{
baseVCSSource: baseVCSSource{
repo: r,
},
},
major: m.major,
unstable: m.unstable,
aliasURL: aliasURL,
}

var vl []PairedVersion
if err := superv.do(ctx, "git:lv:maybe", ctListVersions, func(ctx context.Context) error {
var err error
vl, err = src.listVersions(ctx)
return errors.Wrapf(err, "remote repository at %s does not exist, or is inaccessible", ustr)
}); err != nil {
return nil, 0, err
}

c.setVersionMap(vl)
state := sourceIsSetUp | sourceExistsUpstream | sourceHasLatestVersionList

if r.CheckLocal() {
state |= sourceExistsLocally
}

return src, state, nil
}

func (m maybeGopkginSource) possibleURLs() []*url.URL {
return []*url.URL{m.url}
}

type maybeBzrSource struct {
url *url.URL
}
Expand Down
98 changes: 0 additions & 98 deletions gps/vcs_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,6 @@ import (
"regexp"
"strings"

"github.com/Masterminds/semver"
"github.com/golang/dep/gps/pkgtree"
"github.com/golang/dep/internal/fs"
"github.com/pkg/errors"
Expand Down Expand Up @@ -384,103 +383,6 @@ func (s *gitSource) listVersions(ctx context.Context) (vlist []PairedVersion, er
return
}

// gopkginSource is a specialized git source that performs additional filtering
// according to the input URL.
type gopkginSource struct {
gitSource
major uint64
unstable bool
// The aliased URL we report as being the one we talk to, even though we're
// actually talking directly to GitHub.
aliasURL string
}

func (s *gopkginSource) upstreamURL() string {
return s.aliasURL
}

func (s *gopkginSource) listVersions(ctx context.Context) ([]PairedVersion, error) {
ovlist, err := s.gitSource.listVersions(ctx)
if err != nil {
return nil, err
}

// Apply gopkg.in's filtering rules
vlist := make([]PairedVersion, len(ovlist))
k := 0
var dbranch int // index of branch to be marked default
var bsv semver.Version
var defaultBranch PairedVersion
tryDefaultAsV0 := s.major == 0
for _, v := range ovlist {
// all git versions will always be paired
pv := v.(versionPair)
switch tv := pv.v.(type) {
case semVersion:
tryDefaultAsV0 = false
if tv.sv.Major() == s.major && !s.unstable {
vlist[k] = v
k++
}
case branchVersion:
if tv.isDefault && defaultBranch == nil {
defaultBranch = pv
}

// The semver lib isn't exactly the same as gopkg.in's logic, but
// it's close enough that it's probably fine to use. We can be more
// exact if real problems crop up.
sv, err := semver.NewVersion(tv.name)
if err != nil {
continue
}
tryDefaultAsV0 = false

if sv.Major() != s.major {
// not the same major version as specified in the import path constraint
continue
}

// Gopkg.in has a special "-unstable" suffix which we need to handle
// separately.
if s.unstable != strings.HasSuffix(tv.name, gopkgUnstableSuffix) {
continue
}

// Turn off the default branch marker unconditionally; we can't know
// which one to mark as default until we've seen them all
tv.isDefault = false
// Figure out if this is the current leader for default branch
if bsv == (semver.Version{}) || bsv.LessThan(sv) {
bsv = sv
dbranch = k
}
pv.v = tv
vlist[k] = pv
k++
}
// The switch skips plainVersions because they cannot possibly meet
// gopkg.in's requirements
}

vlist = vlist[:k]
if bsv != (semver.Version{}) {
dbv := vlist[dbranch].(versionPair)
vlist[dbranch] = branchVersion{
name: dbv.v.(branchVersion).name,
isDefault: true,
}.Pair(dbv.r)
}

// Treat the default branch as v0 only when no other semver branches/tags exist
// See http://labix.org/gopkg.in#VersionZero
if tryDefaultAsV0 && defaultBranch != nil {
vlist = append(vlist, defaultBranch)
}

return vlist, nil
}

// bzrSource is a generic bzr repository implementation that should work with
// all standard bazaar remotes.
type bzrSource struct {
Expand Down
Loading