aboutsummaryrefslogtreecommitdiff
path: root/scripts/pd-diff
blob: a5d6fa22cc0b2026bb0ce8d1f07eaf27f96820a4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
#!/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