aboutsummaryrefslogtreecommitdiff
path: root/utils/diff
diff options
context:
space:
mode:
Diffstat (limited to 'utils/diff')
-rw-r--r--utils/diff28
1 files changed, 28 insertions, 0 deletions
diff --git a/utils/diff b/utils/diff
new file mode 100644
index 0000000..0d093c7
--- /dev/null
+++ b/utils/diff
@@ -0,0 +1,28 @@
+# vim:ft=sh:noexpandtab
+# Clever diff function
+
+# TODO directory diff
+
+# This function does diff and reports changes on debug level
+# First and second arguments have to be paths to compared files and third argument
+# have to be a debug message prepended string.
+# It exits with nonzero exit code if there is no difference.
+do_diff() {
+ if [ ! -f "$1" ]; then
+ echo_error "No reference file to compare to: $1"
+ return 1 # We pretend that there is no change as reference file is missing
+ fi
+ if [ ! -f "$2" ]; then
+ echo_dbg "$3: No target file"
+ return 0
+ fi
+
+ # Do real diff if both files exists
+ local DIFF="$(diff --suppress-common-lines -ay "$1" "$2")"
+ if [ -n "$DIFF" ]; then
+ echo_dbg "$3:
+$DIFF"
+ else
+ return 1
+ fi
+}