Skip to content

Commit

Permalink
Remove a truckload of dead code
Browse files Browse the repository at this point in the history
  • Loading branch information
sdboyer committed Aug 16, 2016
1 parent ec580d9 commit 92406ea
Show file tree
Hide file tree
Showing 2 changed files with 3 additions and 212 deletions.
40 changes: 0 additions & 40 deletions source.go
Original file line number Diff line number Diff line change
Expand Up @@ -167,46 +167,6 @@ func (dc *sourceMetaCache) toUnpaired(v Version) UnpairedVersion {
}
}

func (bs *baseVCSSource) listVersions() (vlist []Version, err error) {
if !bs.cvsync {
// This check only guarantees that the upstream exists, not the cache
bs.ex.s |= existsUpstream
vpairs, exbits, err := bs.crepo.getCurrentVersionPairs()
// But it *may* also check the local existence
bs.ex.s |= exbits
bs.ex.f |= exbits

if err != nil {
// TODO(sdboyer) More-er proper-er error
return nil, err
}

vlist = make([]Version, len(vpairs))
// mark our cache as synced if we got ExistsUpstream back
if exbits&existsUpstream == existsUpstream {
bs.cvsync = true
}

// Process the version data into the cache
// TODO(sdboyer) detect out-of-sync data as we do this?
for k, v := range vpairs {
u, r := v.Unpair(), v.Underlying()
bs.dc.vMap[u] = r
bs.dc.rMap[r] = append(bs.dc.rMap[r], u)
vlist[k] = v
}
} else {
vlist = make([]Version, len(bs.dc.vMap))
k := 0
for v := range bs.dc.vMap {
vlist[k] = v
k++
}
}

return
}

func (bs *baseVCSSource) revisionPresentIn(r Revision) (bool, error) {
// First and fastest path is to check the data cache to see if the rev is
// present. This could give us false positives, but the cases where that can
Expand Down
175 changes: 3 additions & 172 deletions vcs_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ import (

type vcsSource interface {
syncLocal() error
ensureLocal() error
listLocalVersionPairs() ([]PairedVersion, sourceExistence, error)
listUpstreamVersionPairs() ([]PairedVersion, sourceExistence, error)
revisionPresentIn(Revision) (bool, error)
hasRevision(Revision) (bool, error)
checkout(Version) error
ping() bool
ensureCacheExistence() error
exportVersionTo(Version, string) error
}

// gitSource is a generic git repository implementation that should work with
Expand Down Expand Up @@ -379,175 +379,6 @@ type repo struct {
synced bool
}

func (r *repo) getCurrentVersionPairs() (vlist []PairedVersion, exbits sourceExistence, err error) {
r.mut.Lock()
defer r.mut.Unlock()

switch r.r.(type) {
case *vcs.GitRepo:
var out []byte
c := exec.Command("git", "ls-remote", r.r.Remote())
// Ensure no terminal prompting for PWs
c.Env = mergeEnvLists([]string{"GIT_TERMINAL_PROMPT=0"}, os.Environ())
out, err = c.CombinedOutput()

all := bytes.Split(bytes.TrimSpace(out), []byte("\n"))
if err != nil || len(all) == 0 {
// TODO(sdboyer) remove this path? it really just complicates things, for
// probably not much benefit

// ls-remote failed, probably due to bad communication or a faulty
// upstream implementation. So fetch updates, then build the list
// locally
err = r.r.Update()
if err != nil {
// Definitely have a problem, now - bail out
return
}

// Upstream and cache must exist, so add that to exbits
exbits |= existsUpstream | existsInCache
// Also, local is definitely now synced
r.synced = true

out, err = r.r.RunFromDir("git", "show-ref", "--dereference")
if err != nil {
return
}

all = bytes.Split(bytes.TrimSpace(out), []byte("\n"))
}
// Local cache may not actually exist here, but upstream definitely does
exbits |= existsUpstream

tmap := make(map[string]PairedVersion)
for _, pair := range all {
var v PairedVersion
if string(pair[46:51]) == "heads" {
v = NewBranch(string(pair[52:])).Is(Revision(pair[:40])).(PairedVersion)
vlist = append(vlist, v)
} else if string(pair[46:50]) == "tags" {
vstr := string(pair[51:])
if strings.HasSuffix(vstr, "^{}") {
// If the suffix is there, then we *know* this is the rev of
// the underlying commit object that we actually want
vstr = strings.TrimSuffix(vstr, "^{}")
} else if _, exists := tmap[vstr]; exists {
// Already saw the deref'd version of this tag, if one
// exists, so skip this.
continue
// Can only hit this branch if we somehow got the deref'd
// version first. Which should be impossible, but this
// covers us in case of weirdness, anyway.
}
v = NewVersion(vstr).Is(Revision(pair[:40])).(PairedVersion)
tmap[vstr] = v
}
}

// Append all the deref'd (if applicable) tags into the list
for _, v := range tmap {
vlist = append(vlist, v)
}
case *vcs.BzrRepo:
var out []byte
// Update the local first
err = r.r.Update()
if err != nil {
return
}
// Upstream and cache must exist, so add that to exbits
exbits |= existsUpstream | existsInCache
// Also, local is definitely now synced
r.synced = true

// Now, list all the tags
out, err = r.r.RunFromDir("bzr", "tags", "--show-ids", "-v")
if err != nil {
return
}

all := bytes.Split(bytes.TrimSpace(out), []byte("\n"))
for _, line := range all {
idx := bytes.IndexByte(line, 32) // space
v := NewVersion(string(line[:idx])).Is(Revision(bytes.TrimSpace(line[idx:]))).(PairedVersion)
vlist = append(vlist, v)
}

case *vcs.HgRepo:
var out []byte
err = r.r.Update()
if err != nil {
return
}

// Upstream and cache must exist, so add that to exbits
exbits |= existsUpstream | existsInCache
// Also, local is definitely now synced
r.synced = true

out, err = r.r.RunFromDir("hg", "tags", "--debug", "--verbose")
if err != nil {
return
}

all := bytes.Split(bytes.TrimSpace(out), []byte("\n"))
lbyt := []byte("local")
nulrev := []byte("0000000000000000000000000000000000000000")
for _, line := range all {
if bytes.Equal(lbyt, line[len(line)-len(lbyt):]) {
// Skip local tags
continue
}

// tip is magic, don't include it
if bytes.HasPrefix(line, []byte("tip")) {
continue
}

// Split on colon; this gets us the rev and the tag plus local revno
pair := bytes.Split(line, []byte(":"))
if bytes.Equal(nulrev, pair[1]) {
// null rev indicates this tag is marked for deletion
continue
}

idx := bytes.IndexByte(pair[0], 32) // space
v := NewVersion(string(pair[0][:idx])).Is(Revision(pair[1])).(PairedVersion)
vlist = append(vlist, v)
}

out, err = r.r.RunFromDir("hg", "branches", "--debug", "--verbose")
if err != nil {
// better nothing than incomplete
vlist = nil
return
}

all = bytes.Split(bytes.TrimSpace(out), []byte("\n"))
lbyt = []byte("(inactive)")
for _, line := range all {
if bytes.Equal(lbyt, line[len(line)-len(lbyt):]) {
// Skip inactive branches
continue
}

// Split on colon; this gets us the rev and the branch plus local revno
pair := bytes.Split(line, []byte(":"))
idx := bytes.IndexByte(pair[0], 32) // space
v := NewBranch(string(pair[0][:idx])).Is(Revision(pair[1])).(PairedVersion)
vlist = append(vlist, v)
}
case *vcs.SvnRepo:
// TODO(sdboyer) is it ok to return empty vlist and no error?
// TODO(sdboyer) ...gotta do something for svn, right?
default:
panic("unknown repo type")
}

return
}

func (r *repo) exportVersionTo(v Version, to string) error {
r.mut.Lock()
defer r.mut.Unlock()
Expand Down

0 comments on commit 92406ea

Please sign in to comment.