+ mktemp --tmpdir -t builder.$PACKAGE_NAME.XXXXXX || ${TMPDIR:-/tmp}/builder.$RANDOM.$$
+}
+
+tempdir() {
+ mktemp --tmpdir -d builder.$PACKAGE_NAME.XXXXXX
+}
+
+# inserts git log instead of %changelog
+# outputs name of modified file created by tempfile
+insert_gitlog() {
+ local SPECFILE=$1 specdir=$(tempdir) gitlog=$(tempfile) speclog=$(tempfile)
+
+ # allow this being customized
+ local log_entries=$(rpm -E '%{?_buildchangelogtruncate}')
+
+ # rpm5.org/rpm.org do not parse any other date format than 'Wed Jan 1 1997'
+ # otherwise i'd use --date=iso here
+ # http://rpm5.org/cvs/fileview?f=rpm/build/parseChangelog.c&v=2.44.2.1
+ # http://rpm.org/gitweb?p=rpm.git;a=blob;f=build/parseChangelog.c;h=56ba69daa41d65ec9fd18c9f371b8ff14118cdca;hb=a113baa510a004476edc44b5ebaaf559238a18b6#l33
+ # NOTE: changelog date is always in UTC for rpmbuild
+ # * 1265749244 +0000 Random Hacker <nikt@pld-linux.org> 9370900
+ git rev-list --date-order -${log_entries:-20} HEAD 2>/dev/null | while read sha1; do
+ local logfmt='%B%n'
+ git notes list $sha1 > /dev/null 2>&1 && logfmt='%N'
+ git log -n 1 $sha1 --format=format:"* %ad %an <%ae> %h%n- ${logfmt}%n" --date=raw | sed -re 's/^- +- */- /'| sed '/^$/q'
+ done > $gitlog
+
+ # add link to full git logs
+ local giturl="http://git.pld-linux.org/?p=packages/$PACKAGE_NAME.git;a=log"
+ if [ -n "$CVSTAG" ]; then
+ giturl="$giturl;h=$CVSTAG"
+ fi
+ local gitauthor="PLD Linux Team <feedback@pld-linux.org>"
+ LC_ALL=C gawk -vgiturl="$giturl" -vgitauthor="$gitauthor" -vpackage=$PACKAGE_NAME 'BEGIN{
+ printf("* %s %s\n- For complete changelog see: %s\n", strftime("%a %b %d %Y"), gitauthor, giturl);
+ print;
+ exit
+ }' > $speclog
+
+ LC_ALL=C gawk '/^\* /{printf("* %s %s\n", strftime("%a %b %d %Y", $2), substr($0, length($1)+length($2)+length($3)+4)); next}{print}' $gitlog >> $speclog
+ sed '/^%changelog/,$d' $SPECFILE | sed -e "\${
+ a%changelog
+ r $speclog
+ }
+ " > $specdir/$SPECFILE
+ rm -f $gitlog $speclog
+ echo $specdir
+}
+
+# @param string logfile
+# @param varargs... commands to execute
+teeboth() {
+ local rc
+ # use teeboth from toys/cleanbuild, if available and enabled
+ if [ "$USE_TEEBOTH" = "yes" ] && [ -x $APPDIR/teeboth ]; then
+ $APPDIR/teeboth "$@"
+ rc=$?
+ else
+ local efile rc logfile=$1; shift
+ if [ "$logfile" ]; then
+ efile=$(tempfile)
+ { "$@" 2>&1; echo $? > $efile; } | tee -a $logfile
+ rc=$(< $efile)
+ rm -f $efile
+ else
+ "$@"
+ rc=$?
+ fi
+ fi
+ return $rc