-
Notifications
You must be signed in to change notification settings - Fork 109
/
apdiff.sh
executable file
·81 lines (73 loc) · 2.15 KB
/
apdiff.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
#!/bin/bash
#
# Since we replaced all 'abp' string with 'aup',
# it causes problems when we diff these two repositories.
#
# This script is used to handle such problem.
#
# @usage: same as `diff`
# @example: $./apdiff.sh -rBb chrome/content/ ../adblockplus/chrome/content/
# @output: same as `diff` but will ignore lines which diff only because abp/aup
################################################################################
diff $* > temp.diff;
curLineNum=1;
while true
do
curLine=$(sed -n "$curLineNum{p;q;}" temp.diff);
if [[ "$curLine" =~ ^\< ]]; then
FoundNextDiff=false;
((nextDiffNum = $curLineNum + 1));
while true
do
nextDiff=$(sed -n "$nextDiffNum{p;q;}" temp.diff);
if [[ "$nextDiff" =~ ^\> ]]; then
FoundNextDiff=true;
nextDiff=${nextDiff/#>/<};
nextDiff=${nextDiff//abp/aup};
nextDiff=${nextDiff//ABP/AUP};
nextDiff=${nextDiff//adblockplus/autoproxy};
nextDiff=${nextDiff//AdblockPlus/AutoProxy};
nextDiff=${nextDiff//Adblock Plus/AutoProxy};
nextDiff=${nextDiff//Adblock/AutoProxy};
nextDiff=${nextDiff//adblock/AutoProxy};
if [ "$nextDiff" == "$curLine" ]; then
sed -i "$nextDiffNum d" temp.diff;
sed -i "$curLineNum d" temp.diff;
((curLineNum--));
break;
fi
elif $FoundNextDiff; then
break;
elif [ "$nextDiff" == "" ]; then
break;
fi
((nextDiffNum++));
done
elif [ "$curLine" == "" ]; then # EOF
break;
fi
((curLineNum++));
done
# remove lines like this:
# "191c191" followed by "---"
#
# Note:
# `sed` access the newest temp.diff from disk every time,
# 'while read' uses old unmodified temp.diff forever, they are independent.
#
curLineNum=1;
while read curLine
do
if [[ "$curLine" =~ ^[1-9] ]]; then
((nextLineNum = $curLineNum + 1));
nextLine=$(sed -n "$nextLineNum{p;q;}" temp.diff);
if [[ "$nextLine" =~ ^---$ ]]; then
sed -i "$nextLineNum d" temp.diff;
sed -i "$curLineNum d" temp.diff;
((curLineNum -= 2));
fi
fi
((curLineNum++));
done < temp.diff
# highlight in vim looks better than `echo`
vim temp.diff;