dyff icon indicating copy to clipboard operation
dyff copied to clipboard

Packaging dyff in debian

Open pavianogiacomo opened this issue 5 months ago • 6 comments

Hi, i'm trying to package dyff for debian trixie but it seems that there is a broken dependency. I have this error:

src/github.com/homeport/dyff/pkg/dyff/core.go:1060:59: not enough arguments in call to hashstructure.Hash
	have (interface{}, nil)
	want (interface{}, hashstructure.Format, *hashstructure.HashOptions)
src/github.com/homeport/dyff/pkg/dyff/core.go:1063:46: not enough arguments in call to hashstructure.Hash
	have (string, nil)
	want (interface{}, hashstructure.Format, *hashstructure.HashOptions)

This is because in Debian there's only version 2.0.2 of hashstructure, which now requires more function arguments.

Could you please consider updating to the newer library version? Also, the hashstructure maintainer mentions that version 1 (which you are using) may generate clashing hashes, and it isn't 100% safe to use.

I hope that the issue is clear. If is not please ask me.

pavianogiacomo avatar Jul 20 '25 11:07 pavianogiacomo

This was already reported in #131 but fixed with a3b388bf966ba5fef13b22e7bfd61ab90e6be387 but I don't fully get why GO111MODULE=on affects this and the git commit message does not explain anything why this was chosen as the solution.

ottok avatar Jul 31 '25 20:07 ottok

The above commit was actually removed when upgrading to Go v1.17 in cf2bc0f5c9c2aa0b9cd4faf3d0141c7e925561d7. The package still depends on github.com/mitchellh/hashstructure v1.1.0 from 2020. It should be updated to use the latest 2.0.2 from 2021 (see https://github.com/mitchellh/hashstructure/tags).

ottok avatar Jul 31 '25 21:07 ottok

One option would also to replace mitchellh/hashstructure with some newer fork listed at https://github.com/mitchellh/hashstructure/network. However the most developed fork https://github.com/shorsher/hashstructure has no updated in the README, accepts no issues and has zero PRs so it does not look like @shorsher wants his fork to be the official successor multiple people should use.

ottok avatar Jul 31 '25 21:07 ottok

On Thu Jul 31, 2025 at 11:12 PM CEST, Otto Kekäläinen wrote:

One option would also to replace mitchellh/hashstructure with some newer fork listed at https://github.com/mitchellh/hashstructure/network.

There's https://github.com/gohugoio/hashstructure, probably used by Hugo. Seen this in https://gist.github.com/mitchellh/90029601268e59a29e64e55bab1c5bdc

Tachi107 avatar Jul 31 '25 21:07 Tachi107

This was already reported in #131 but fixed with a3b388bf966ba5fef13b22e7bfd61ab90e6be387 but I don't fully get why GO111MODULE=on affects this and the git commit message does not explain anything why this was chosen as the solution.

By the way, me and Giacomo already fixed this issue with the following patch:

diff --git a/pkg/dyff/core.go b/pkg/dyff/core.go
index 55d10b4..d89bbcd 100644
--- a/pkg/dyff/core.go
+++ b/pkg/dyff/core.go
@@ -30,7 +30,7 @@ import (
        "github.com/gonvenience/text"
        "github.com/gonvenience/ytbx"

-       "github.com/mitchellh/hashstructure"
+       "github.com/mitchellh/hashstructure/v2"
        yamlv3 "gopkg.in/yaml.v3"
 )

@@ -1057,10 +1057,10 @@ func (compare *compare) calcNodeHash(node *yamlv3.Node) (hash uint64) {

        switch node.Kind {
        case yamlv3.MappingNode, yamlv3.SequenceNode:
-               hash, err = hashstructure.Hash(compare.basicType(node), nil)
+               hash, err = hashstructure.Hash(compare.basicType(node), hashstructure.FormatV1, nil)

        case yamlv3.ScalarNode:
-               hash, err = hashstructure.Hash(node.Value, nil)
+               hash, err = hashstructure.Hash(node.Value, hashstructure.FormatV1, nil)

        case yamlv3.AliasNode:
                hash = compare.calcNodeHash(followAlias(node))

It's really an easy fix, and tests pass. dyff should probably switch to hashstructure.FormatV2 though, as V1 is documented to have some issues.

Tachi107 avatar Jul 31 '25 21:07 Tachi107

Great! Looking forward to see that as an upstream submission at https://github.com/homeport/dyff/pulls

ottok avatar Jul 31 '25 21:07 ottok