-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathannexdiff.sh
executable file
·119 lines (97 loc) · 3.01 KB
/
annexdiff.sh
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
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/bin/bash
diffmode="$1"
if [ "$diffmode" != "onlynames" ] && [ "$diffmode" != "full" ] \
&& [ "$diffmode" != "header" ] && [ "$diffmode" != "difffile" ]; then
echo "ERROR: first argument must be either onlynames, full, header or difffile"
exit 1
fi
relfilepath="$2"
reffile1="$3"
reffile2="$4"
if [ -d "$reffile1" ]; then
exit
fi
if [ -d "$reffile2" ]; then
exit
fi
filepath="$GIT_WORK_TREE/$relfilepath"
dirpath="$(dirname $filepath)"
if [ "$reffile1" != "/dev/null" ]; then
rawpath1=$(cat $reffile1)
truefile1="$dirpath/$rawpath1"
fi
if [ "$reffile2" != "/dev/null" ]; then
rawpath2=$(cat $reffile2)
truefile2="$dirpath/$rawpath2"
fi
if [ "$diffmode" = "onlynames" ]; then
# for some reason: git diff --name-only ...
# is MUCH faster than this approach
if [ "$reffile1" = "/dev/null" ]; then
echo "only in #2: $relfilepath"
elif [ "$reffile2" = "/dev/null" ]; then
echo "only in #1: $relfilepath"
else
if [ "$truefile1" != "$truefile2" ]; then
echo "different in #1 and #2: $relfilepath"
fi
fi
exit
fi
if [ "$reffile1" != "/dev/null" ]; then
cmpfile1="$(mktemp)"
if [ "$diffmode" = "header" ]; then
head -n20 "$truefile1" | cut -c-75 -- > "$cmpfile1"
else
cut -c-75 "$truefile1" > "$cmpfile1"
fi
dos2unix --quiet "$cmpfile1"
fi
if [ "$reffile2" != "/dev/null" ]; then
cmpfile2=$(mktemp)
if [ "$diffmode" = "header" ]; then
head -n20 "$truefile2" | cut -c-75 -- > "$cmpfile2"
else
cut -c-75 "$truefile2" > "$cmpfile2"
fi
dos2unix --quiet "$cmpfile2"
fi
if [ "$diffmode" = "full" ]; then
vimdiff "$cmpfile1" "$cmpfile2"
elif [ "$diffmode" = "header" ]; then
echo '################################################################################################################################################################'
echo '################################################################################################################################################################'
echo
echo "FILE: $relfilepath"
echo
if [ "$reffile1" = "/dev/null" ]; then
echo "only in #2"
elif [ "$reffile2" = "/dev/null" ]; then
echo "only in #1"
else
diff -y "$cmpfile1" "$cmpfile2"
fi
echo
elif [ "$diffmode" = "difffile" ]; then
if [ ! -d "diffdir" ]; then
echo 'ERROR: diffdir does not exist'
exit
fi
if [ "$reffile1" = "/dev/null" ]; then
echo "only in #2"
elif [ "$reffile2" = "/dev/null" ]; then
echo "only in #1"
else
echo "working on $relfilepath"
difffile="diffdir/$relfilepath.diff.html"
locdiffdir="diffdir/$(dirname $relfilepath)"
mkdir -p "$locdiffdir"
dtwdiff "$cmpfile1" "$cmpfile2" | ansi2html --white | sed 's/<head>/<head><meta charset="UTF-8" \/>/' > "$difffile"
fi
fi
if [ "$reffile1" != "/dev/null" ]; then
rm "$cmpfile1"
fi
if [ "$reffile2" != "/dev/null" ]; then
rm "$cmpfile2"
fi