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

Commit 008ff04

Browse files
committed
Include memo in lock diff
1 parent e565a9f commit 008ff04

File tree

2 files changed

+25
-15
lines changed

2 files changed

+25
-15
lines changed

testdata/txn_writer/expected_diff_output.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
Memo: 595716d270828e763c811ef79c9c41f85b1d1bfbdfe85280036405c03772206c -> 2252a285ab27944a4d7adcba8dbd03980f59ba652f12db39fa93b927c345593e
12
Add: [
23
{
34
"name": "github.com/stuff/realthing",

txn_writer.go

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ package dep
66

77
import (
88
"bytes"
9+
"encoding/hex"
910
"encoding/json"
1011
"fmt"
1112
"io/ioutil"
@@ -65,6 +66,10 @@ func (diff *LockDiff) Format() (string, error) {
6566

6667
var buf bytes.Buffer
6768

69+
if diff.HashDiff != nil {
70+
buf.WriteString(fmt.Sprintf("Memo: %s\n", diff.HashDiff))
71+
}
72+
6873
if len(diff.Add) > 0 {
6974
buf.WriteString("Add: ")
7075

@@ -121,23 +126,27 @@ type StringDiff struct {
121126
Current string
122127
}
123128

124-
func (diff StringDiff) MarshalJSON() ([]byte, error) {
125-
var value string
126-
129+
func (diff StringDiff) String() string {
127130
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)
135136
}
136137

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) {
137146
var buf bytes.Buffer
138147
enc := json.NewEncoder(&buf)
139148
enc.SetEscapeHTML(false)
140-
err := enc.Encode(value)
149+
err := enc.Encode(diff.String())
141150

142151
return buf.Bytes(), err
143152
}
@@ -416,10 +425,10 @@ func diffLocks(l1 gps.Lock, l2 gps.Lock) *LockDiff {
416425

417426
diff := LockDiff{}
418427

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}
423432
}
424433

425434
var i2next int

0 commit comments

Comments
 (0)