#!/bin/sh # difference between two Pd patches # the problem here is, that there exists a many-to-1 relation between # Pd-file and patch # e.g. objects might have a different creation order without affecting # the functionality of a patch # otoh, creation order might have implications as well # nevertheless, creation order has an impact on the Pd-file, since connections # between objects are made using indices; therefore a change in the creation order # of the objects will be reflected on several places within the Pd-file! # furthermore, in most cases the position of an object within the patch does not # have any significance # the noteable built-in exceptions are [inlet] and [outlet] # these weirdnesses make it hard to effectively find out whether a patch description # differs substantially from another one # in practice, traditional diff will only tell you that _something_ has changed, # but it is hard to interprete its output in a meaningful way # even harder it is to build a merger of Pd-files (for concurrent development) ## originally draft for this differ (as i deduce it from hcs's code) # # 2 pass evaluation: # - find diffs in the object-list without position information # - count connections in each patch and compare them # TODO # - more algorithms for diffing features # - modularity (allow user to chose diff-algorithms) # - better tempfile algorithm (ideally there wouldn't be any tempfiles at all) # - cleanup at the end (no tempfiles should be left behind) # - ensure that this script is portable # (probably switch from "shell" (bash) to another language, like tcl DATE=$(date '+%Y-%m-%d_%H.%M.%S') TMPDIR=/tmp/pd-diff #------------------------------------------------------------------------------ # FUNCTIONS generate_tmp_filename () { echo ${TMPDIR}/$(echo $1 | sed -e 's|/|_|g')-${DATE} } prep_for_diff () { TMPFILE=$(generate_tmp_filename "$1") # everything but the first line # no "connect" lines # remove position information cat "$1" | \ sed '2,$!d' | \ grep -v '#X connect ' | \ sed 's/\(#[XN] [a-z]+\) [0-9]+ [0-9]+/\1/' \ > ${TMPFILE} } #------------------------------------------------------------------------------ # THE PROGRAM if [ $# -ne 2 ]; then echo "ERROR: Invalid number of arguments ($#)" echo "Usage: $0 FILE1 FILE2" else if [ ! -d ${TMPDIR} ]; then mkdir ${TMPDIR} fi TMP1=$(generate_tmp_filename "$1") TMP2=$(generate_tmp_filename "$2") prep_for_diff "$1" prep_for_diff "$2" # diff of everything except "#X connect"'s diff -uw "${TMP1}" "${TMP2}" file1count=$(grep -v '#X connect ' "$1" | wc -l) file2count=$(grep -v '#X connect ' "$2" | wc -l) if [ $file1count -ne $file2count ]; then echo "---------------------------------------------------------" echo Connections differ: ${file1count} vs. ${file2count} fi fi