Skip to contentSkip to conversation

tests/shell: Treat json-nft dumps as binary in git

PATCH In review Phil Sutter 4 participants 5 messages Nov 23, 2023 – Nov 24, 2023 netfilter

lore
Share & tools
lore

Phil Sutter

author reviewer
#0 lore raw

PATCH 1/1 tests/shell: Treat json-nft dumps as binary in git

The stored JSON dumps containing a single line of a thusand characters in average mess up diffs in history and patches if they change. Mitigate this by treating them as binary files.

In order to get useable diffs back, one may undo/override the attribute within $GIT_DIR/info/attributes, preferrably by defining a custom diff driver converting the single-line dumps into something digestable by diff:

| # cat >>$GIT_DIR/info/attributes <<EOF
| tests/shell/testcases/**/dumps/*.json-nft diff=json-nft
| EOF
| # cat >>$GIT_DIR/config <<EOF
| [diff "json-nft"]
|         binary = true
|         textconv = tests/shell/helpers/json-pretty.sh
| EOF

Stating the obvious: The textconv tool is for display purposes only, patches will still contain binary diffs for the files.

---
 .gitattributes                     | 1 +
 tests/shell/helpers/json-pretty.sh | 4 ++++
 2 files changed, 5 insertions(+)
 create mode 100644 .gitattributes
.gitattributes new file +1 -0
new file mode 100644
index 0000000000000..17d78d0554929
@@ -0,0 +1 @@
+tests/shell/testcases/**/dumps/*.json-nft binary
tests/shell/helpers/json-pretty.sh +4 -0
index 0d6972b81e2f0..d773da2be29de 100755
@@ -1,5 +1,9 @@
 #!/bin/bash -e
 
+# support being called with input
+# in a file specified on command line
+[ -f "$1" ] && exec $0 <"$1"
+
 # WARNING: the output is not guaranteed to be stable.
 
 if command -v jq &>/dev/null ; then
Signature · 1 line
2.41.0
maintainer
#1 lore raw
Quoted 8 lines · Phil Sutter

The stored JSON dumps containing a single line of a thusand characters in average mess up diffs in history and patches if they change. Mitigate this by treating them as binary files.

In order to get useable diffs back, one may undo/override the attribute within $GIT_DIR/info/attributes, preferrably by defining a custom diff driver converting the single-line dumps into something digestable by diff:

I'd say we convert the single-line dumps to jq format one-by-one if they need updating.

New dumps are no longer accepted in single-line format.

#2 lore raw
Quoted 5 lines · Florian Westphal
Quoted 4 lines · Phil Sutter

The stored JSON dumps containing a single line of a thusand characters in average mess up diffs in history and patches if they change. Mitigate this by treating them as binary files.

Quoted 7 lines
Quoted 4 lines

In order to get useable diffs back, one may undo/override the attribute within $GIT_DIR/info/attributes, preferrably by defining a custom diff driver converting the single-line dumps into something digestable by diff:

I'd say we convert the single-line dumps to jq format one-by-one if they need updating.

I am also fine with .json-nft dumps in pretty format too, which is friendlier to git diff.

author reviewer
#3 lore raw
Quoted 6 lines · Pablo Neira Ayuso
Quoted 5 lines · Florian Westphal
Quoted 4 lines · Phil Sutter

The stored JSON dumps containing a single line of a thusand characters in average mess up diffs in history and patches if they change. Mitigate this by treating them as binary files.

Quoted 7 lines
Quoted 7 lines
Quoted 4 lines

In order to get useable diffs back, one may undo/override the attribute within $GIT_DIR/info/attributes, preferrably by defining a custom diff driver converting the single-line dumps into something digestable by diff:

I'd say we convert the single-line dumps to jq format one-by-one if they need updating.

This might work without a transitioning mechanism if jq output piped through jq does not change. The testsuite could just pipe the dump through jq before comparing regardless of whether it's pretty-printed already or not.

Quoted 2 lines

I am also fine with .json-nft dumps in pretty format too, which is friendlier to git diff.

Discuss that with Thomas, please. I tried and failed, alleviating the effects is my last resort.

Cheers, Phil

#4 lore raw
Quoted 25 lines · Phil Sutter
Quoted 16 lines · Pablo Neira Ayuso
Quoted 15 lines · Florian Westphal
Quoted 13 lines · Phil Sutter

The stored JSON dumps containing a single line of a thusand characters
in average mess up diffs in history and patches if they change. Mitigate
this by treating them as binary files.

In order to get useable diffs back, one may undo/override the attribute
within $GIT_DIR/info/attributes, preferrably by defining a custom diff
driver converting the single-line dumps into something digestable by
diff:

Quoted 2 lines
Quoted 2 lines

I'd say we convert the single-line dumps to jq format one-by-one if they need updating.

This might work without a transitioning mechanism if jq output piped through jq does not change. The testsuite could just pipe the dump through jq before comparing regardless of whether it's pretty-printed already or not.

Quoted 8 lines
Quoted 2 lines

I am also fine with .json-nft dumps in pretty format too, which is friendlier to git diff.

Discuss that with Thomas, please. I tried and failed, alleviating the effects is my last resort.

Cheers, Phil

Hi,

let me send a patch, that hopefully makes you all happy. (or at least, something to discuss further).

Hold on.

Thomas