@@ -176,24 +176,28 @@ type Conflict struct {
176
176
// Changes involved (which share the same path).
177
177
func MergeDiffs (a , b []* Change ) ([]* Change , []Conflict ) {
178
178
paths := make (map [string ]* Change )
179
- for _ , c := range a {
179
+ for _ , c := range b {
180
180
paths [c .Path ] = c
181
181
}
182
182
183
183
var changes []* Change
184
184
var conflicts []Conflict
185
185
186
- for _ , changeB := range b {
187
- if changeA , ok := paths [changeB .Path ]; ok {
186
+ // NOTE: we avoid iterating over maps here to ensure iteration order is determistic. We
187
+ // include changes from a first, then b.
188
+ for _ , changeA := range a {
189
+ if changeB , ok := paths [changeA .Path ]; ok {
188
190
conflicts = append (conflicts , Conflict {changeA , changeB })
189
191
} else {
190
- changes = append (changes , changeB )
192
+ changes = append (changes , changeA )
191
193
}
192
- delete (paths , changeB .Path )
194
+ delete (paths , changeA .Path )
193
195
}
194
196
195
- for _ , c := range paths {
196
- changes = append (changes , c )
197
+ for _ , c := range b {
198
+ if _ , ok := paths [c .Path ]; ok {
199
+ changes = append (changes , c )
200
+ }
197
201
}
198
202
199
203
return changes , conflicts
0 commit comments