-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdiff.go
More file actions
58 lines (52 loc) · 1.1 KB
/
diff.go
File metadata and controls
58 lines (52 loc) · 1.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
package wineregdiff
type RegistryDiff struct {
Registry1Only Registry
Registry2Only Registry
RegistryChanged map[Key]ValueDiff
}
func NewRegistryDiff() RegistryDiff {
return RegistryDiff{
Registry1Only: Registry{},
Registry2Only: Registry{},
RegistryChanged: map[Key]ValueDiff{},
}
}
type ValueDiff struct {
Value1 Value
Value2 Value
}
func (d ValueDiff) HasDiff() bool {
return len(d.Value1) > 0 || len(d.Value2) > 0
}
func NewValueDiff() ValueDiff {
return ValueDiff{
Value1: Value{},
Value2: Value{},
}
}
func Diff(reg1, reg2 Registry) (RegistryDiff, error) {
cmp := &DefaultValueComparator{
DataComparator: &DefaultDataComparator{},
}
diff := NewRegistryDiff()
for key, value1 := range reg1 {
value2, ok := reg2[key]
if !ok {
diff.Registry1Only[key] = value1
continue
}
valueDiff, err := cmp.CompareValue(key, value1, value2)
if err != nil {
return diff, err
}
if valueDiff.HasDiff() {
diff.RegistryChanged[key] = valueDiff
}
}
for key, value2 := range reg2 {
if _, ok := reg1[key]; !ok {
diff.Registry2Only[key] = value2
}
}
return diff, nil
}