Skip to content

Commit

Permalink
Protobuf uses a field "pragma.DoNotCompare" to prevent comparison.
Browse files Browse the repository at this point in the history
Check for the type name to skip comparison, but make sure that both
values are the same. Checking on the string value to avoid a dependency
on the protobuf package.
  • Loading branch information
samuel committed Nov 10, 2023
1 parent b2b7865 commit eba21af
Showing 1 changed file with 13 additions and 0 deletions.
13 changes: 13 additions & 0 deletions diff.go
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,19 @@ func (w diffPrinter) diff(av, bv reflect.Value) {
w.printf("%q != %q", a, b)
}
case reflect.Struct:
for i := 0; i < av.NumField(); i++ {
af := av.Field(i)
bf := bv.Field(i)
avDNC := af.Type().String() == "pragma.DoNotCompare"
bvDNC := bf.Type().String() == "pragma.DoNotCompare"
if avDNC && bvDNC {
return
}
if avDNC != bvDNC {
w.printf("cannot compare types %s and %s", av.Type(), bv.Type())
return
}
}
for i := 0; i < av.NumField(); i++ {
w.relabel(at.Field(i).Name).diff(av.Field(i), bv.Field(i))
}
Expand Down

0 comments on commit eba21af

Please sign in to comment.