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

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



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.

Signed-off-by: Phil Sutter <phil@xxxxxx>
---
 .gitattributes                     | 1 +
 tests/shell/helpers/json-pretty.sh | 4 ++++
 2 files changed, 5 insertions(+)
 create mode 100644 .gitattributes

diff --git a/.gitattributes b/.gitattributes
new file mode 100644
index 0000000000000..17d78d0554929
--- /dev/null
+++ b/.gitattributes
@@ -0,0 +1 @@
+tests/shell/testcases/**/dumps/*.json-nft binary
diff --git a/tests/shell/helpers/json-pretty.sh b/tests/shell/helpers/json-pretty.sh
index 0d6972b81e2f0..d773da2be29de 100755
--- a/tests/shell/helpers/json-pretty.sh
+++ b/tests/shell/helpers/json-pretty.sh
@@ -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
-- 
2.41.0





[Index of Archives]     [Netfitler Users]     [Berkeley Packet Filter]     [LARTC]     [Bugtraq]     [Yosemite Forum]

  Powered by Linux