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 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294
|
#!/bin/bash
if test $# -ne 3; then
cat >> /dev/stderr <<EOF
Usage:
$0 <summarydir> <rutdir> <earliest_commit>
Iterate through [<earliest_commit>..HEAD] identifying the next next commit
to test.
On STDOUT, print the hash of the next commit to test. The first of
the following is chosen:
- <earliest_commit>, presumably it was specified for a reason
- HEAD
- a tag
- a branch/merge point
- when HEAD is "uninteresting", the most recent "interesting" commit
- some other "interesting" commit selected by splitting the longest
run of untested commits
On STDERR, in addition to random debug lines, list the status of all
commits using the format:
{TESTED,UNTESTED}: <resultdir> <hash> <interesting> <index> <run-length> <bias>
(see git-interesting.sh for <interesting>'s value)
(see earliest-commit.sh for <earliest_commit>'s value)
EOF
exit 1
fi
bindir=$(realpath $(dirname $0))
summarydir=$(realpath $1) ; shift
rutdir=$(realpath $1) ; shift
earliest_commit=$(git -C ${rutdir} rev-parse ${1}^{})
echo summarydir ${summarydir} 1>&2
echo rutdir ${rutdir} 1>&2
echo earliest_commit ${earliest_commit} 1>&2
branch=$(${bindir}/gime-git-branch.sh ${rutdir})
remote=$(git -C ${rutdir} config --get branch.${branch}.remote)
echo branch=${branch} remote=${remote} 1>&2
# non-zero index indicates earliest commit is untested
earliest_index=0
# non-zero index indicates head is untested
head_commit=
head_index=0
# tag and branch/merge point; non-zero index indicates one was found
tag=
tag_commit=
tag_index=0
point=
point_commit=
point_index=0
# The longest untested run of commits.
#
# The RUN_BIAS (a count of TAG, MERGE and BRANCH commits) is used to
# perfer earlier shorter runs.
#
# non-zero index indicates an untested commit
declare -a run_commits run_indexes
run_commit=
run_index=0
run_length=0
run_bias=0
# Go through all the mainline commits (--first-parent excludes
# branches) in new-to-old order (--topo-order).
#
# revlist excludes earliest commit so add it
index=0
for commit in $(git -C ${rutdir} rev-list \
--topo-order \
--first-parent \
${earliest_commit}..${remote} ;
echo ${earliest_commit}) ; do
index=$(expr ${index} + 1)
# See of the commit has a test result directory?
#
# Git's abbreviated hash length keeps growing.
resultdir=
for h in ${commit} \
$(expr ${commit} : '\(..............\).*') \
$(expr ${commit} : '\(.............\).*') \
$(expr ${commit} : '\(............\).*') \
$(expr ${commit} : '\(...........\).*') \
$(expr ${commit} : '\(..........\).*') \
$(expr ${commit} : '\(.........\).*') \
$(expr ${commit} : '\(........\).*') \
$(expr ${commit} : '\(.......\).*') \
; do
# either branch-count-g<hash> or tag-count-g<hash>-branch
for d in ${summarydir}/*-g${h} ${summarydir}/*-g${h}-* ; do
if test -d "${d}" ; then
resultdir=$d
break
fi
done
if test -n "${resultdir}" ; then
break
fi
done
# Always test HEAD (even when it isn't interesting).
#
# Hopefully this is less confusing then having tester.sh ignore new
# commits. These results will get pruned early.
#
# Use index=1 as a flag to indicate that the test wasn't tested.
if test -z "${head_commit}" ; then
head_commit=${commit}
test ${index} -eq 1 # always true
if test -z "${resultdir}" ; then
# flag that this hasn't been tested
head_index=${index}
fi
echo head ${head_commit} at ${head_index} 1>&2
# Don't bail early as some scripts rely on this script
# printing an analysis of all the commits.
fi
# deal with earliest_commit
if test "${commit}" == "${earliest_commit}" ; then
if test -z "${resultdir}" ; then
earliest_index=${index}
fi
fi
# Find out how interesting the commit is, and why. list the
# results on stderr.
#
# Among other things, this output can be used to select a random
# set of results to delete. For instance, by selecting a random
# subset of the less interesting results (interesting results have
# a colon). See README.txt.
if interesting=$(${bindir}/git-interesting.sh ${rutdir} ${commit}) ; then
uninteresting=false
else
uninteresting=true
fi
if test -n "${resultdir}"; then
TESTED=TESTED
else
TESTED=UNTESTED
fi
echo ${TESTED}: ${resultdir} ${commit} ${interesting} ${index} ${#run_commits[@]} ${run_bias} 1>&2
# Skip uninteresting commits - don't include them in untested
# runs.
if ${uninteresting} ; then
continue
fi
# Update the longest run if, after using the RUN_BIAS to bias
# things towards earlier runs, it is longer. While repeatedly
# updating isn't the most efficient it avoids the need to do
# updates in the various code paths below.
if test ${#run_commits[@]} -gt $(expr ${run_length} + ${run_bias}) ; then
run_length=${#run_commits[@]}
i=$((run_length / 2))
run_index=${run_indexes[$i]}
run_commit=${run_commits[$i]}
echo RUN ${run_commit} at ${run_index} length ${run_length} commits "${run_commits[@]}" indexes "${run_indexes[@]}" 1>&2
fi
# Increment the point count (branch, merge, tag) when needed.
#
# Do this before discarding tested commits so that tested TAG,
# BRANCH, and MERGE commits are included in the count.
#
# The RUN_BIAS is used to bias the untested run length so that
# earlier shorter runs are preferred.
case "${interesting}" in
*:* )
run_bias=$(expr ${run_bias} + 1)
echo bias: ${run_bias} ${commit} ${interesting} at ${index} 1>&2
;;
esac
# already tested? stop the current run and start again
if test -n "${resultdir}"; then
unset run_commits ; declare -a run_commits
continue
fi
# Finally, save the first really interesting TAG or BRANCH/MERGE
# commit.
case "${interesting}" in
tag:*)
if test -z "${tag}" ; then
tag=$(expr "${interesting}" : '.*: *\(.*\)')
tag_commit=${commit}
tag_index=${index}
fi
# kill current run
unset run_commits ; declare -a run_commits
continue
;;
branch:* | merge:* )
if test -z "${point}" ; then
point=$(expr "${interesting}" : '\(.*\):')
point_commit=${commit}
point_index=${index}
fi
# kill current run
unset run_commits ; declare -a run_commits
continue
;;
esac
# append commit to the end of run_commits[] and run_indexes[]
# arrays, growing them by one.
i=${#run_commits[@]}
run_indexes[$i]=${index}
run_commits[$i]=${commit}
done
# Dump the results
# ${point^^} converts ${point} to upper case
echo EARLIEST ${earliest_commit} at ${earliest_index} 1>&2
echo HEAD ${head_commit} at ${head_index} 1>&2
echo ${point^^}POINT ${point_commit} at ${point_index} 1>&2
echo TAG ${tag} ${tag_commit} at ${tag_index} 1>&2
echo RUN ${run_commit} at ${run_index} length ${run_length} 1>&2
# Now which came first?
print_selected() {
echo selecting $1 at $2 1>&2
# dump to the console
git -C ${rutdir} --no-pager show --no-patch $2 1>&2
echo $2
exit 0
}
# earliest
if test "${earliest_index}" -gt 0 ; then
print_selected earliest "${earliest_commit}"
fi
# head
if test ${head_index} -gt 0 ; then
print_selected "head" ${head_commit}
fi
# any tag
if test "${tag_index}" -gt 0 ; then
print_selected tag:${tag} "${tag_commit}"
fi
# any branch/merge is untested?
if test "${point_index}" -gt 0 ; then
print_selected ${point} "${point_commit}"
fi
if test ${run_index} -gt 0 ; then
print_selected "longest-run" ${run_commit}
fi
exit 1
|