From f6ecc196ef0bbc30fdb9ca66083939381c28ea13 Mon Sep 17 00:00:00 2001 From: Zachary Romero Date: Tue, 23 Jan 2018 18:25:01 +0300 Subject: [PATCH] Initial work to get the -old flag working --- cmd/dep/status.go | 94 ++++++++++++++++++++--------------------------- 1 file changed, 39 insertions(+), 55 deletions(-) diff --git a/cmd/dep/status.go b/cmd/dep/status.go index 26d52dd061..42830f283d 100644 --- a/cmd/dep/status.go +++ b/cmd/dep/status.go @@ -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, @@ -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: @@ -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 @@ -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() @@ -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) @@ -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 } } @@ -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 ""