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

Commit

Permalink
Initial work for status old
Browse files Browse the repository at this point in the history
  • Loading branch information
zkry committed Feb 6, 2018
1 parent 52307d4 commit 0db8cb2
Showing 1 changed file with 49 additions and 5 deletions.
54 changes: 49 additions & 5 deletions cmd/dep/status.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ package main

import (
"bytes"
"context"
"encoding/json"
"flag"
"fmt"
Expand Down Expand Up @@ -242,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:
return errors.Errorf("not implemented")
case cmd.json:
out = &jsonOutput{
w: &buf,
Expand Down Expand Up @@ -274,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 @@ -341,6 +340,15 @@ func (cmd *statusCommand) validateFlags() error {
return nil
}

// OldStatus contains information about all the out of date packages in a project.
type OldStatus struct {
ProjectRoot string
Constraint gps.Constraint
Version gps.UnpairedVersion
Revision gps.Revision
Latest gps.Version
}

type rawStatus struct {
ProjectRoot string
Constraint string
Expand Down Expand Up @@ -424,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 @@ -457,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 @@ -641,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 @@ -722,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 0db8cb2

Please sign in to comment.