2
2
// Use of this source code is governed by a BSD-style
3
3
// license that can be found in the LICENSE file.
4
4
5
- package gps
5
+ package verify
6
6
7
7
import (
8
8
"fmt"
9
9
"sort"
10
10
"strings"
11
+
12
+ "github.com/golang/dep/gps"
11
13
)
12
14
13
15
// StringDiff represents a modified string value.
@@ -40,6 +42,21 @@ func (diff *StringDiff) String() string {
40
42
return diff .Current
41
43
}
42
44
45
+ // sortLockedProjects returns a sorted copy of lps, or itself if already sorted.
46
+ func sortLockedProjects (lps []gps.LockedProject ) []gps.LockedProject {
47
+ if len (lps ) <= 1 || sort .SliceIsSorted (lps , func (i , j int ) bool {
48
+ return lps [i ].Ident ().Less (lps [j ].Ident ())
49
+ }) {
50
+ return lps
51
+ }
52
+ cp := make ([]gps.LockedProject , len (lps ))
53
+ copy (cp , lps )
54
+ sort .Slice (cp , func (i , j int ) bool {
55
+ return cp [i ].Ident ().Less (cp [j ].Ident ())
56
+ })
57
+ return cp
58
+ }
59
+
43
60
// LockDiff is the set of differences between an existing lock file and an updated lock file.
44
61
// Fields are only populated when there is a difference, otherwise they are empty.
45
62
type LockDiff struct {
@@ -51,7 +68,7 @@ type LockDiff struct {
51
68
// LockedProjectDiff contains the before and after snapshot of a project reference.
52
69
// Fields are only populated when there is a difference, otherwise they are empty.
53
70
type LockedProjectDiff struct {
54
- Name ProjectRoot
71
+ Name gps. ProjectRoot
55
72
Source * StringDiff
56
73
Version * StringDiff
57
74
Branch * StringDiff
@@ -61,13 +78,13 @@ type LockedProjectDiff struct {
61
78
62
79
// DiffLocks compares two locks and identifies the differences between them.
63
80
// Returns nil if there are no differences.
64
- func DiffLocks (l1 Lock , l2 Lock ) * LockDiff {
81
+ func DiffLocks (l1 , l2 gps. Lock ) * LockDiff {
65
82
// Default nil locks to empty locks, so that we can still generate a diff
66
83
if l1 == nil {
67
- l1 = & SimpleLock {}
84
+ l1 = & gps. SimpleLock {}
68
85
}
69
86
if l2 == nil {
70
- l2 = & SimpleLock {}
87
+ l2 = & gps. SimpleLock {}
71
88
}
72
89
73
90
p1 , p2 := l1 .Projects (), l2 .Projects ()
@@ -129,7 +146,7 @@ func DiffLocks(l1 Lock, l2 Lock) *LockDiff {
129
146
// DiffFor checks to see if there was a diff for the provided ProjectRoot. The
130
147
// first return value is a 0 if there was no diff, 1 if it was added, 2 if it
131
148
// was removed, and 3 if it was modified.
132
- func (ld * LockDiff ) DiffFor (pr ProjectRoot ) (uint8 , LockedProjectDiff ) {
149
+ func (ld * LockDiff ) DiffFor (pr gps. ProjectRoot ) (uint8 , LockedProjectDiff ) {
133
150
for _ , lpd := range ld .Add {
134
151
if lpd .Name == pr {
135
152
return 1 , lpd
@@ -151,9 +168,9 @@ func (ld *LockDiff) DiffFor(pr ProjectRoot) (uint8, LockedProjectDiff) {
151
168
return 0 , LockedProjectDiff {}
152
169
}
153
170
154
- func buildLockedProjectDiff (lp LockedProject ) LockedProjectDiff {
171
+ func buildLockedProjectDiff (lp gps. LockedProject ) LockedProjectDiff {
155
172
s2 := lp .Ident ().Source
156
- r2 , b2 , v2 := VersionComponentStrings (lp .Version ())
173
+ r2 , b2 , v2 := gps . VersionComponentStrings (lp .Version ())
157
174
158
175
var rev , version , branch , source * StringDiff
159
176
if s2 != "" {
@@ -185,7 +202,7 @@ func buildLockedProjectDiff(lp LockedProject) LockedProjectDiff {
185
202
186
203
// DiffProjects compares two projects and identifies the differences between them.
187
204
// Returns nil if there are no differences.
188
- func DiffProjects (lp1 LockedProject , lp2 LockedProject ) * LockedProjectDiff {
205
+ func DiffProjects (lp1 , lp2 gps. LockedProject ) * LockedProjectDiff {
189
206
diff := LockedProjectDiff {Name : lp1 .Ident ().ProjectRoot }
190
207
191
208
s1 := lp1 .Ident ().Source
@@ -194,8 +211,8 @@ func DiffProjects(lp1 LockedProject, lp2 LockedProject) *LockedProjectDiff {
194
211
diff .Source = & StringDiff {Previous : s1 , Current : s2 }
195
212
}
196
213
197
- r1 , b1 , v1 := VersionComponentStrings (lp1 .Version ())
198
- r2 , b2 , v2 := VersionComponentStrings (lp2 .Version ())
214
+ r1 , b1 , v1 := gps . VersionComponentStrings (lp1 .Version ())
215
+ r2 , b2 , v2 := gps . VersionComponentStrings (lp2 .Version ())
199
216
if r1 != r2 {
200
217
diff .Revision = & StringDiff {Previous : r1 , Current : r2 }
201
218
}
0 commit comments