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

Commit c2ddece

Browse files
committed
Store old lock projects and lookup new look project in that map
1 parent e14bc3d commit c2ddece

File tree

1 file changed

+12
-9
lines changed

1 file changed

+12
-9
lines changed

cmd/dep/root_analyzer.go

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -168,17 +168,20 @@ func (a *rootAnalyzer) DeriveManifestAndLock(dir string, pr gps.ProjectRoot) (gp
168168
func (a *rootAnalyzer) FinalizeRootManifestAndLock(m *dep.Manifest, l *dep.Lock, ol dep.Lock) {
169169
// Iterate through the new projects in solved lock and add them to manifest
170170
// if they are direct deps and log feedback for all the new projects.
171-
sl := gps.SortedLockedProjects(l.Projects())
172-
sol := gps.SortedLockedProjects(ol.Projects())
173-
for i, y := range sl {
171+
//
172+
// IDEA: Make a lookup map of ProjectRoot ->projects in the old lock
173+
// use that data structure to simplify these loops
174+
olLookup := make(map[gps.ProjectRoot]gps.LockedProject)
175+
for _, op := range ol.Projects() {
176+
olLookup[op.Ident().ProjectRoot] = op
177+
}
178+
for _, y := range l.Projects() {
174179
var f *fb.ConstraintFeedback
175180
pr := y.Ident().ProjectRoot
176-
if i < len(sol) {
177-
op := sol[i]
178-
if same := y.Ident().Eq(op.Ident()); same {
179-
if diff := gps.DiffProjects(y, op); diff != nil {
180-
fmt.Printf("Some changes: \nImported: %v\nRevised: %v\nDiff: %v\n", y, op, diff)
181-
}
181+
182+
if op, ok := olLookup[pr]; ok {
183+
if diff := gps.DiffProjects(y, op); diff != nil {
184+
fmt.Printf("Some changes: \nImported: %v\nRevised: %v\nDiff: %v\n", y, op, diff)
182185
}
183186
}
184187
// New constraints: in new lock and dir dep but not in manifest

0 commit comments

Comments
 (0)