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

Commit f6ecc19

Browse files
committed
Initial work to get the -old flag working
1 parent 4a245cc commit f6ecc19

File tree

1 file changed

+39
-55
lines changed

1 file changed

+39
-55
lines changed

cmd/dep/status.go

+39-55
Original file line numberDiff line numberDiff line change
@@ -243,8 +243,6 @@ func (cmd *statusCommand) Run(ctx *dep.Ctx, args []string) error {
243243
switch {
244244
case cmd.missing:
245245
return errors.Errorf("not implemented")
246-
case cmd.old:
247-
cmd.runOld(ctx, args, p, sm)
248246
case cmd.json:
249247
out = &jsonOutput{
250248
w: &buf,
@@ -275,7 +273,7 @@ func (cmd *statusCommand) Run(ctx *dep.Ctx, args []string) error {
275273
return errors.Errorf("no Gopkg.lock found. Run `dep ensure` to generate lock file")
276274
}
277275

278-
hasMissingPkgs, errCount, err := runStatusAll(ctx, out, p, sm)
276+
hasMissingPkgs, errCount, err := runStatusAll(ctx, out, p, sm, cmd)
279277
if err != nil {
280278
switch err {
281279
case errFailedUpdate:
@@ -351,56 +349,6 @@ type OldStatus struct {
351349
Latest gps.Version
352350
}
353351

354-
func (cmd *statusCommand) runOld(ctx *dep.Ctx, args []string, p *dep.Project, sm gps.SourceManager) error {
355-
// While the network churns on ListVersions() requests, statically analyze
356-
// code from the current project.
357-
ptree, err := p.ParseRootPackageTree()
358-
if err != nil {
359-
return err
360-
}
361-
362-
// Set up a solver in order to check the InputHash.
363-
params := gps.SolveParameters{
364-
ProjectAnalyzer: dep.Analyzer{},
365-
RootDir: p.AbsRoot,
366-
RootPackageTree: ptree,
367-
Manifest: p.Manifest,
368-
// Locks aren't a part of the input hash check, so we can omit it.
369-
}
370-
371-
// Check update for all the projects
372-
params.ChangeAll = true
373-
374-
solver, err := gps.Prepare(params, sm)
375-
if err != nil {
376-
return errors.Wrap(err, "fastpath solver prepare")
377-
}
378-
379-
solution, err := solver.Solve(context.TODO())
380-
if err != nil {
381-
return errors.Wrap(err, "runOld")
382-
}
383-
384-
var oldLockProjects []gps.LockedProject
385-
lockProjects := p.Lock.Projects()
386-
solutionProjects := solution.Projects()
387-
388-
for i := range solutionProjects {
389-
spr, _, _ := gps.VersionComponentStrings(solutionProjects[i].Version())
390-
lpr, _, _ := gps.VersionComponentStrings(lockProjects[i].Version())
391-
392-
if spr != lpr {
393-
oldLockProjects = append(oldLockProjects, lockProjects[i])
394-
}
395-
}
396-
397-
for _, oldLockProject := range oldLockProjects {
398-
ctx.Out.Println(oldLockProject)
399-
}
400-
401-
return nil
402-
}
403-
404352
type rawStatus struct {
405353
ProjectRoot string
406354
Constraint string
@@ -484,7 +432,7 @@ type MissingStatus struct {
484432
MissingPackages []string
485433
}
486434

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

468+
// We only care about solution in the -old flag case
469+
var solution gps.Solution
470+
if cmd.old {
471+
params.ChangeAll = true
472+
var err error
473+
solution, err = s.Solve(context.TODO())
474+
if err != nil {
475+
return false, 0, err
476+
}
477+
}
478+
520479
// Errors while collecting constraints should not fail the whole status run.
521480
// It should count the error and tell the user about incomplete results.
522481
cm, ccerrs := collectConstraints(ctx, p, sm)
@@ -701,7 +660,18 @@ func runStatusAll(ctx *dep.Ctx, out outputter, p *dep.Project, sm gps.SourceMana
701660

702661
// Use the collected BasicStatus in outputter.
703662
for _, proj := range slp {
704-
if err := out.BasicLine(bsMap[string(proj.Ident().ProjectRoot)]); err != nil {
663+
pr := proj.Ident().ProjectRoot
664+
665+
// If -old flag, only display the lines where the solver mismatches
666+
if cmd.old {
667+
if matches, err := projUpToDate(proj, solution); matches {
668+
continue
669+
} else if err != nil {
670+
return false, 0, err
671+
}
672+
}
673+
674+
if err := out.BasicLine(bsMap[string(pr)]); err != nil {
705675
return false, 0, err
706676
}
707677
}
@@ -782,6 +752,20 @@ outer:
782752
return hasMissingPkgs, 0, errInputDigestMismatch
783753
}
784754

755+
// projUpToDate returns true if the project p, is at the same revision as what the solution indicates
756+
func projUpToDate(p gps.LockedProject, s gps.Solution) (bool, error) {
757+
solutionProjects := s.Projects()
758+
for i := range solutionProjects {
759+
if solutionProjects[i].Ident().ProjectRoot == p.Ident().ProjectRoot {
760+
spr, _, _ := gps.VersionComponentStrings(solutionProjects[i].Version())
761+
lpr, _, _ := gps.VersionComponentStrings(p.Version())
762+
return spr == lpr, nil
763+
}
764+
}
765+
// If we're here, the solution was missing a project. Should never get here but just incase
766+
return false, errors.New("solution missing project information for " + string(p.Ident().ProjectRoot))
767+
}
768+
785769
func formatVersion(v gps.Version) string {
786770
if v == nil {
787771
return ""

0 commit comments

Comments
 (0)