@@ -82,7 +82,7 @@ type outputter interface {
82
82
MissingFooter () error
83
83
}
84
84
85
- // Only a subset of the outputters should be able to output old statuses
85
+ // Only a subset of the outputters should be able to output old statuses.
86
86
type oldOutputter interface {
87
87
OldHeader () error
88
88
OldLine (* OldStatus ) error
@@ -311,7 +311,7 @@ func (cmd *statusCommand) Run(ctx *dep.Ctx, args []string) error {
311
311
312
312
if cmd .old {
313
313
if _ , ok := out .(oldOutputter ); ! ok {
314
- return errors .Errorf ("invalid output command usesed " )
314
+ return errors .Errorf ("invalid output format used " )
315
315
}
316
316
err = cmd .runOld (ctx , out .(oldOutputter ), p , sm )
317
317
ctx .Out .Print (buf .String ())
@@ -451,7 +451,7 @@ func (cmd *statusCommand) runOld(ctx *dep.Ctx, out oldOutputter, p *dep.Project,
451
451
// Locks aren't a part of the input hash check, so we can omit it.
452
452
}
453
453
454
- // Check update for all the projects
454
+ // Check update for all the projects.
455
455
params .ChangeAll = true
456
456
457
457
solver , err := gps .Prepare (params , sm )
@@ -465,40 +465,54 @@ func (cmd *statusCommand) runOld(ctx *dep.Ctx, out oldOutputter, p *dep.Project,
465
465
}
466
466
467
467
var oldStatuses []OldStatus
468
+ lockProjects := p .Lock .Projects ()
468
469
solutionProjects := solution .Projects ()
469
470
470
- for _ , proj := range p .Lock .Projects () {
471
- for i := range solutionProjects {
472
- // Look for the same project in solution and lock
473
- if solutionProjects [i ].Ident ().ProjectRoot != proj .Ident ().ProjectRoot {
474
- continue
475
- }
471
+ sort .Slice (solutionProjects , func (i , j int ) bool {
472
+ return solutionProjects [i ].Ident ().Less (solutionProjects [j ].Ident ())
473
+ })
476
474
477
- // If revisions are not the same then it is old and we should display it
478
- latestRev , _ , _ := gps .VersionComponentStrings (solutionProjects [i ].Version ())
479
- atRev , _ , _ := gps .VersionComponentStrings (proj .Version ())
480
- if atRev == latestRev {
481
- continue
482
- }
475
+ sort .Slice (lockProjects , func (i , j int ) bool {
476
+ return lockProjects [i ].Ident ().Less (lockProjects [j ].Ident ())
477
+ })
483
478
484
- // Generate the old status data and append it
485
- os := OldStatus {
486
- ProjectRoot : proj .Ident ().String (),
487
- Revision : gps .Revision (atRev ),
488
- Latest : gps .Revision (latestRev ),
489
- }
490
- // Getting Constraint
491
- if pp , has := p .Manifest .Ovr [proj .Ident ().ProjectRoot ]; has && pp .Constraint != nil {
492
- // manifest has override for project
493
- os .Constraint = pp .Constraint
494
- } else if pp , has := p .Manifest .Constraints [proj .Ident ().ProjectRoot ]; has && pp .Constraint != nil {
495
- // manifest has normal constraint
496
- os .Constraint = pp .Constraint
497
- } else {
498
- os .Constraint = gps .Any ()
499
- }
500
- oldStatuses = append (oldStatuses , os )
479
+ for i := range solutionProjects {
480
+ lProj := lockProjects [i ]
481
+ sProj := solutionProjects [i ]
482
+
483
+ if lProj .Ident ().ProjectRoot != sProj .Ident ().ProjectRoot {
484
+ // We should always be comparing the same projects and should enter be here.
485
+ return errors .New ("Projects from the solution and lock are not in the same order" )
486
+ }
487
+
488
+ // If revisions are not the same then it is old and we should display it.
489
+ latestRev , _ , _ := gps .VersionComponentStrings (sProj .Version ())
490
+ atRev , _ , _ := gps .VersionComponentStrings (lProj .Version ())
491
+ if atRev == latestRev {
492
+ continue
493
+ }
494
+
495
+ var constraint gps.Constraint
496
+ // Getting Constraint
497
+ if pp , has := p .Manifest .Ovr [lProj .Ident ().ProjectRoot ]; has && pp .Constraint != nil {
498
+ // Manifest has override for project.
499
+ constraint = pp .Constraint
500
+ } else if pp , has := p .Manifest .Constraints [lProj .Ident ().ProjectRoot ]; has && pp .Constraint != nil {
501
+ // Manifest has normal constraint.
502
+ constraint = pp .Constraint
503
+ } else {
504
+ // No constraint exists. No need to worry about displaying it
505
+ continue
506
+ }
507
+
508
+ // Generate the old status data and append it.
509
+ os := OldStatus {
510
+ ProjectRoot : lProj .Ident ().String (),
511
+ Revision : gps .Revision (atRev ),
512
+ Latest : gps .Revision (latestRev ),
513
+ Constraint : constraint ,
501
514
}
515
+ oldStatuses = append (oldStatuses , os )
502
516
}
503
517
504
518
out .OldHeader ()
0 commit comments