@@ -43,47 +43,49 @@ func (r *Reporter) PushStep(ps cmp.PathStep) {
4343}
4444
4545func (r * Reporter ) Report (rs cmp.Result ) {
46- if ! rs .Equal () {
47- var lines []string
48- remoteValue , localValue := r .path .Last ().Values ()
49-
50- // Diff values
51- if v , ok := r .relationsDiff (remoteValue , localValue ); ok {
52- // Relations diff
53- lines = append (lines , v ... )
54- } else if v , ok := r .stringsDiff (remoteValue , localValue ); ok {
55- // Strings diff
56- lines = append (lines , v ... )
57- } else {
58- // Other types
59- lines = append (lines , valuesDiff (remoteValue , localValue )... )
60- }
46+ if rs .Equal () {
47+ return
48+ }
6149
62- // Format lines
63- var mark string
64- switch {
65- case remoteValue .IsValid () && ! localValue .IsValid ():
66- mark = OnlyInRemoteMark
67- case ! remoteValue .IsValid () && localValue .IsValid ():
68- mark = OnlyInLocalMark
69- default :
70- // Values are present in both: local and remote value
71- // Individual lines are already marked.
72- mark = " "
73- }
74- pathStr := r .pathToString (r .path )
75- if len (pathStr ) > 0 {
76- r .paths = append (r .paths , pathStr )
77- if ! r .isPathHidden () {
78- r .diffs = append (r .diffs , fmt .Sprintf (`%s %s:` , mark , pathStr ))
79- // Ident values inside path
80- mark += ` `
81- }
82- }
83- for _ , line := range lines {
84- r .diffs = append (r .diffs , fmt .Sprintf (`%s %s` , mark , line ))
50+ var lines []string
51+ remoteValue , localValue := r .path .Last ().Values ()
52+
53+ // Diff values
54+ if v , ok := r .relationsDiff (remoteValue , localValue ); ok {
55+ // Relations diff
56+ lines = append (lines , v ... )
57+ } else if v , ok := r .stringsDiff (remoteValue , localValue ); ok {
58+ // Strings diff
59+ lines = append (lines , v ... )
60+ } else {
61+ // Other types
62+ lines = append (lines , valuesDiff (remoteValue , localValue )... )
63+ }
64+
65+ // Format lines
66+ var mark string
67+ switch {
68+ case remoteValue .IsValid () && ! localValue .IsValid ():
69+ mark = OnlyInRemoteMark
70+ case ! remoteValue .IsValid () && localValue .IsValid ():
71+ mark = OnlyInLocalMark
72+ default :
73+ // Values are present in both: local and remote value
74+ // Individual lines are already marked.
75+ mark = " "
76+ }
77+ pathStr := r .pathToString (r .path )
78+ if len (pathStr ) > 0 {
79+ r .paths = append (r .paths , pathStr )
80+ if ! r .isPathHidden () {
81+ r .diffs = append (r .diffs , fmt .Sprintf (`%s %s:` , mark , pathStr ))
82+ // Ident values inside path
83+ mark += ` `
8584 }
8685 }
86+ for _ , line := range lines {
87+ r .diffs = append (r .diffs , fmt .Sprintf (`%s %s` , mark , line ))
88+ }
8789}
8890
8991func (r * Reporter ) PopStep () {
@@ -185,15 +187,22 @@ func (r *Reporter) pathToString(path cmp.Path) string {
185187}
186188
187189func (r * Reporter ) objectPath (value reflect.Value ) string {
188- if value .IsValid () {
189- if v , ok := value .Interface ().(model.RecordPaths ); ok {
190- objectPath := v .Path ()
191- if objectPath != "" {
192- if v , err := filesystem .Rel (r .manifest .Path (), objectPath ); err == nil {
193- return v
194- }
195- }
196- }
190+ if ! value .IsValid () {
191+ return ""
192+ }
193+
194+ v , ok := value .Interface ().(model.RecordPaths )
195+ if ! ok {
196+ return ""
197+ }
198+
199+ objectPath := v .Path ()
200+ if objectPath == "" {
201+ return ""
202+ }
203+
204+ if v , err := filesystem .Rel (r .manifest .Path (), objectPath ); err == nil {
205+ return v
197206 }
198207 return ""
199208}
0 commit comments