From f287ecedc78c0cc8fb485c5995b8d1cfae9f0fe8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Karel=20Ko=C4=8D=C3=AD?= Date: Wed, 20 Sep 2017 21:19:05 +0200 Subject: Commit current state --- utils/diff | 28 ++++++++++++++++++++++++++++ 1 file changed, 28 insertions(+) create mode 100644 utils/diff (limited to 'utils/diff') 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 +} -- cgit v1.2.3