@@ -6,6 +6,7 @@ package dep
6
6
7
7
import (
8
8
"bytes"
9
+ "encoding/hex"
9
10
"encoding/json"
10
11
"fmt"
11
12
"io/ioutil"
@@ -65,6 +66,10 @@ func (diff *LockDiff) Format() (string, error) {
65
66
66
67
var buf bytes.Buffer
67
68
69
+ if diff .HashDiff != nil {
70
+ buf .WriteString (fmt .Sprintf ("Memo: %s\n " , diff .HashDiff ))
71
+ }
72
+
68
73
if len (diff .Add ) > 0 {
69
74
buf .WriteString ("Add: " )
70
75
@@ -121,23 +126,27 @@ type StringDiff struct {
121
126
Current string
122
127
}
123
128
124
- func (diff StringDiff ) MarshalJSON () ([]byte , error ) {
125
- var value string
126
-
129
+ func (diff StringDiff ) String () string {
127
130
if diff .Previous == "" && diff .Current != "" {
128
- value = fmt .Sprintf ("+ %s" , diff .Current )
129
- } else if diff .Previous != "" && diff .Current == "" {
130
- value = fmt .Sprintf ("- %s" , diff .Previous )
131
- } else if diff .Previous != diff .Current {
132
- value = fmt .Sprintf ("%s -> %s" , diff .Previous , diff .Current )
133
- } else {
134
- value = diff .Current
131
+ return fmt .Sprintf ("+ %s" , diff .Current )
132
+ }
133
+
134
+ if diff .Previous != "" && diff .Current == "" {
135
+ return fmt .Sprintf ("- %s" , diff .Previous )
135
136
}
136
137
138
+ if diff .Previous != diff .Current {
139
+ return fmt .Sprintf ("%s -> %s" , diff .Previous , diff .Current )
140
+ }
141
+
142
+ return diff .Current
143
+ }
144
+
145
+ func (diff StringDiff ) MarshalJSON () ([]byte , error ) {
137
146
var buf bytes.Buffer
138
147
enc := json .NewEncoder (& buf )
139
148
enc .SetEscapeHTML (false )
140
- err := enc .Encode (value )
149
+ err := enc .Encode (diff . String () )
141
150
142
151
return buf .Bytes (), err
143
152
}
@@ -416,10 +425,10 @@ func diffLocks(l1 gps.Lock, l2 gps.Lock) *LockDiff {
416
425
417
426
diff := LockDiff {}
418
427
419
- h1 := l1 .InputHash ()
420
- h2 := l2 .InputHash ()
421
- if ! bytes . Equal ( h1 , h2 ) {
422
- diff .HashDiff = & StringDiff {Previous : string ( h1 ) , Current : string ( h2 ) }
428
+ h1 := hex . EncodeToString ( l1 .InputHash () )
429
+ h2 := hex . EncodeToString ( l2 .InputHash () )
430
+ if h1 != h2 {
431
+ diff .HashDiff = & StringDiff {Previous : h1 , Current : h2 }
423
432
}
424
433
425
434
var i2next int
0 commit comments