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

Commit

Permalink
Initial work to get the -old flag working
Browse files Browse the repository at this point in the history
  • Loading branch information
zkry committed Jan 23, 2018
1 parent 4a245cc commit f6ecc19
Showing 1 changed file with 39 additions and 55 deletions.
94 changes: 39 additions & 55 deletions cmd/dep/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -243,8 +243,6 @@ func (cmd *statusCommand) Run(ctx *dep.Ctx, args []string) error {
switch {
case cmd.missing:
return errors.Errorf("not implemented")
case cmd.old:
cmd.runOld(ctx, args, p, sm)
case cmd.json:
out = &jsonOutput{
w: &buf,
Expand Down Expand Up @@ -275,7 +273,7 @@ func (cmd *statusCommand) Run(ctx *dep.Ctx, args []string) error {
return errors.Errorf("no Gopkg.lock found. Run `dep ensure` to generate lock file")
}

hasMissingPkgs, errCount, err := runStatusAll(ctx, out, p, sm)
hasMissingPkgs, errCount, err := runStatusAll(ctx, out, p, sm, cmd)
if err != nil {
switch err {
case errFailedUpdate:
Expand Down Expand Up @@ -351,56 +349,6 @@ type OldStatus struct {
Latest gps.Version
}

func (cmd *statusCommand) runOld(ctx *dep.Ctx, args []string, p *dep.Project, sm gps.SourceManager) error {
// While the network churns on ListVersions() requests, statically analyze
// code from the current project.
ptree, err := p.ParseRootPackageTree()
if err != nil {
return err
}

// Set up a solver in order to check the InputHash.
params := gps.SolveParameters{
ProjectAnalyzer: dep.Analyzer{},
RootDir: p.AbsRoot,
RootPackageTree: ptree,
Manifest: p.Manifest,
// Locks aren't a part of the input hash check, so we can omit it.
}

// Check update for all the projects
params.ChangeAll = true

solver, err := gps.Prepare(params, sm)
if err != nil {
return errors.Wrap(err, "fastpath solver prepare")
}

solution, err := solver.Solve(context.TODO())
if err != nil {
return errors.Wrap(err, "runOld")
}

var oldLockProjects []gps.LockedProject
lockProjects := p.Lock.Projects()
solutionProjects := solution.Projects()

for i := range solutionProjects {
spr, _, _ := gps.VersionComponentStrings(solutionProjects[i].Version())
lpr, _, _ := gps.VersionComponentStrings(lockProjects[i].Version())

if spr != lpr {
oldLockProjects = append(oldLockProjects, lockProjects[i])
}
}

for _, oldLockProject := range oldLockProjects {
ctx.Out.Println(oldLockProject)
}

return nil
}

type rawStatus struct {
ProjectRoot string
Constraint string
Expand Down Expand Up @@ -484,7 +432,7 @@ type MissingStatus struct {
MissingPackages []string
}

func runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Project, sm gps.SourceManager) (hasMissingPkgs bool, errCount int, err error) {
func runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Project, sm gps.SourceManager, cmd *statusCommand) (hasMissingPkgs bool, errCount int, err error) {
// While the network churns on ListVersions() requests, statically analyze
// code from the current project.
ptree, err := p.ParseRootPackageTree()
Expand Down Expand Up @@ -517,6 +465,17 @@ func runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Project, sm gps.SourceMana
return false, 0, errors.Wrapf(err, "could not set up solver for input hashing")
}

// We only care about solution in the -old flag case
var solution gps.Solution
if cmd.old {
params.ChangeAll = true
var err error
solution, err = s.Solve(context.TODO())
if err != nil {
return false, 0, err
}
}

// Errors while collecting constraints should not fail the whole status run.
// It should count the error and tell the user about incomplete results.
cm, ccerrs := collectConstraints(ctx, p, sm)
Expand Down Expand Up @@ -701,7 +660,18 @@ func runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Project, sm gps.SourceMana

// Use the collected BasicStatus in outputter.
for _, proj := range slp {
if err := out.BasicLine(bsMap[string(proj.Ident().ProjectRoot)]); err != nil {
pr := proj.Ident().ProjectRoot

// If -old flag, only display the lines where the solver mismatches
if cmd.old {
if matches, err := projUpToDate(proj, solution); matches {
continue
} else if err != nil {
return false, 0, err
}
}

if err := out.BasicLine(bsMap[string(pr)]); err != nil {
return false, 0, err
}
}
Expand Down Expand Up @@ -782,6 +752,20 @@ outer:
return hasMissingPkgs, 0, errInputDigestMismatch
}

// projUpToDate returns true if the project p, is at the same revision as what the solution indicates
func projUpToDate(p gps.LockedProject, s gps.Solution) (bool, error) {
solutionProjects := s.Projects()
for i := range solutionProjects {
if solutionProjects[i].Ident().ProjectRoot == p.Ident().ProjectRoot {
spr, _, _ := gps.VersionComponentStrings(solutionProjects[i].Version())
lpr, _, _ := gps.VersionComponentStrings(p.Version())
return spr == lpr, nil
}
}
// If we're here, the solution was missing a project. Should never get here but just incase
return false, errors.New("solution missing project information for " + string(p.Ident().ProjectRoot))
}

func formatVersion(v gps.Version) string {
if v == nil {
return ""
Expand Down

0 comments on commit f6ecc19

Please sign in to comment.