-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAutoVer
More file actions
executable file
·241 lines (209 loc) · 5.73 KB
/
AutoVer
File metadata and controls
executable file
·241 lines (209 loc) · 5.73 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
#!/bin/bash
if [ "$#" -ne 1 ]
then
echo
echo "Usage: AutoVer -y"
echo " AutoVer -no_update"
echo
exit
fi
if [ "$1" == "-y" ]
then
update=1
elif [ "$1" == "-no_update" ]
then
update=0
else
echo "ERROR: invalid input flag"
echo " run without arguments to see options"
exit
fi
if [ ! -d .AutoVer ]
then
echo "ERROR: AutoVer has not been initialized"
echo " or you aren't in the project top level directory"
exit
fi
AutoVerMajor=$( head -1 .AutoVer/version )
AutoVerMinor=$( head -2 .AutoVer/version | tail -1 )
AutoVerPatch=$( head -3 .AutoVer/version | tail -1 )
IncrementMajor=0
IncrementMinor=0
IncrementPatch=0
version_control=$( cat .AutoVer/version_control )
increment_version() {
if [ "$IncrementMajor" -gt "0" ]
then
NewMajor=$(( AutoVerMajor + 1 ))
NewMinor=0
NewPatch=0
elif [ "$IncrementMinor" -gt "0" ]
then
NewMajor=$AutoVerMajor
NewMinor=$(( AutoVerMinor + 1 ))
NewPatch=0
else
NewMajor=$AutoVerMajor
NewMinor=$AutoVerMinor
NewPatch=$(( AutoVerPatch + 1 ))
fi
echo "Old version ${AutoVerMajor}.${AutoVerMinor}.${AutoVerPatch}"
echo "New version ${NewMajor}.${NewMinor}.${NewPatch}"
if [ "$update" -eq "1" ]
then
echo $NewMajor >.AutoVer/version
echo $NewMinor >>.AutoVer/version
echo $NewPatch >>.AutoVer/version
AutoVerHeader $NewMajor $NewMinor $NewPatch
# copy new headers to previous_headers
# this works, but seems to mess up version control systems
#rm -r .AutoVer/previous_headers
#mv .AutoVer/new_headers .AutoVer/previous_headers
# we have a new_header_list and old_header_list
# we need to break it into three new_not_old old_not_new both
new_not_old=""
old_not_new=""
both=""
for new_header in $new_header_list
do
found=0
for old_header in $old_header_list
do
# use if instead of group to avoid substring matches
if [ "${new_header}.norm" == "$old_header" ]
then
found=1
fi
done
if [ "$found" -eq "1" ]
then
both="$both ${new_header}.norm"
else
new_not_old="$new_not_old ${new_header}.norm"
fi
done
for old_header in $old_header_list
do
found=0
for new_header in $new_header_list
do
# use if instead of group to avoid substring matches
if [ "${new_header}.norm" == "$old_header" ]
then
found=1
fi
done
if [ "$found" -eq "0" ]
then
old_not_new="$old_not_new $old_header"
fi
done
# old not new, needs to be removed from version control
for header_file in $old_not_new
do
if [ "$version_control" == "mercurial" ]
then
hg remove .AutoVer/previous_headers/$header_file
elif [ "$version_control" == "git" ]
then
git rm -r .AutoVer/previous_headers/$header_file
else
rm -r .AutoVer/previous_headers/$header_file
fi
done
# new not old, copy and add
for header_file in $new_not_old
do
if [ -d .AutoVer/new_headers/$header_file ]
then
mkdir .AutoVer/previous_headers/$header_file
else
cp .AutoVer/new_headers/$header_file .AutoVer/previous_headers/$header_file
fi
if [ "$version_control" == "mercurial" ]
then
hg add .AutoVer/previous_headers/$header_file
elif [ "$version_control" == "git" ]
then
git add .AutoVer/previous_headers/$header_file
fi
done
for header_file in $both
do
if [ ! -d .AutoVer/new_headers/$header_file ]
then
cp .AutoVer/new_headers/$header_file .AutoVer/previous_headers/$header_file
fi
done
fi
# updated or not, remove the data
if [ -d .AutoVer/new_headers ]
then
rm -r .AutoVer/new_headers
fi
}
# make sure new_headers are empty
if [ -d .AutoVer/new_headers ]
then
rm -r .AutoVer/new_headers
fi
mkdir .AutoVer/new_headers
#echo "Indexing header files"
new_header_list=$( find . -type f \( -name "*.[hH]" -o -name "*.[hH][pP][pP]" -o -name "*.[hH][hH]" -o -name "*.[hH][xX][xX]" \) | grep -v AutoVer.h | cut -c 3- )
for file_name in $new_header_list
do
# make directories to put files in
num_slashes=$(grep -o '/' <<< "$file_name" | wc -l)
#echo "$file_name $num_slashes"
if [ "$num_slashes" -gt "0" ]
then
directory="${file_name%/*}"
#echo "$file_name $directory"
if [ ! -d ".AutoVer/new_headers/${directory}" ]
then
mkdir -p ".AutoVer/new_headers/${directory}"
fi
fi
# normalize the header
#echo "calling AutoVerNormalize $file_name \".AutoVer/new_headers/${file_name}.norm\" "
AutoVerNormalize $file_name ".AutoVer/new_headers/${file_name}.norm"
done
old_header_list=$( find .AutoVer/previous_headers -type f -name "*.norm" | grep -v AutoVer.h | cut -c 27- )
num_new_headers=$( echo $new_header_list | wc -w )
num_old_headers=$( echo $old_header_list | wc -w )
#echo "num_new_headers $num_new_headers"
#echo "num_old_headers $num_old_headers"
if [ "$num_new_headers" -lt "$num_old_headers" ]
then
echo "Header files have been removed"
IncrementMajor=1
increment_version
exit
fi
# Compare files
for file_name in $new_header_list
do
if [ ! -f .AutoVer/previous_headers/${file_name}.norm ]
then
echo "header file $file_name has been added"
IncrementMinor=$(( IncrementMinor + 1 ))
else
compare_flag=$( AutoVerCompare .AutoVer/previous_headers/${file_name}.norm .AutoVer/new_headers/${file_name}.norm )
if [ "$compare_flag" == "MAJOR" ]
then
echo "Major update for file $file_name"
IncrementMajor=$(( IncrementMajor + 1 ))
fi
if [ "$compare_flag" == "MINOR" ]
then
echo "Minor update for file $file_name"
IncrementMinor=$(( IncrementMinor + 1 ))
fi
if [ "$compare_flag" == "PATCH" ]
then
IncrementPatch=$(( IncrementPatch + 1 ))
fi
fi
done
increment_version
exit