view contrib/buildrpm @ 9378:1a7bcf58ba56

dirstate.write: don't ignore stat data if mtime is in the future (issue1790) This change narrows the race guard that was introduced by af3f26b6bba4 ("dirstate: ignore stat data for files that were updated too recently") to not discard the _map entry's stat data if the mtime is in the future. Without this change, status locks files having odd mtimes in the future into the 'unset' state, causing needless file compares later (admittedly harmless), but also inflicting highly irritating sticky effects on tools/plugins that directly read .hg/dirstate (e.g. TortoiseHg).
author Adrian Buehlmann <adrian@cadifra.com>
date Fri, 21 Aug 2009 14:17:23 +0200
parents bb255fe7c27e
children ce145bf2ca5e
line wrap: on
line source

#!/bin/sh
#
# Build a Mercurial RPM in place.
#
# Bryan O'Sullivan <bos@serpentine.com>
#
# Tested on
# - Fedora 10
# - Fedora 11
# - Centos 5.3 (with Fedora EPEL repo for asciidoc)

HG="`dirname $0`/../hg"
PYTHONPATH="`dirname $0`/../mercurial/pure"
export PYTHONPATH

root="`$HG root 2>/dev/null`"
specfile=contrib/mercurial.spec

if [ -z "$root" ]; then
    echo 'You are not inside a Mercurial repository!' 1>&2
    exit 1
fi

rpmdir=/tmp/"`basename $root | sed 's/ /_/'`"-rpm # FIXME: Insecure /tmp handling

cd "$root"
rm -rf $rpmdir
mkdir -p $rpmdir/RPMS
$HG clone "$root" $rpmdir/BUILD

if [ ! -f $specfile ]; then
    echo "Cannot find $specfile!" 1>&2
    exit 1
fi

tmpspec=/tmp/`basename "$specfile"`.$$ # FIXME: Insecure /tmp handling
# Use the most recent tag as the version.
version=`$HG tags | python -c 'import sys; print [l for l in sys.stdin.readlines() if l[0].isdigit()][0].split()[0]'`
# Compute the release number as the difference in revision numbers
# between the tip and the most recent tag.
release=`$HG tags | python -c 'import sys; l = sys.stdin.readlines(); print int(l[0].split()[1].split(":")[0]) - int([x for x in l if x[0].isdigit()][0].split()[1].split(":")[0])'`
tip=`$HG -q tip`

# Beat up the spec file
sed -e 's,^Source:.*,Source: /dev/null,' \
    -e "s,^Version:.*,Version: $version," \
    -e "s,^Release:.*,Release: $release," \
    -e "s,^%prep.*,Changeset: $tip\n\0," \
    -e 's,^%setup.*,,' \
    $specfile > $tmpspec

cat <<EOF >> $tmpspec
%changelog
* `LANG=en_US date +'%a %b %d %Y'` `$HG showconfig ui.username` $version-$release
- Automatically built via $0

EOF
$HG log \
     --template '* {date|rfc822date} {author}\n- {desc|firstline}\n\n' \
     .hgtags \
  | sed -e 's/^\(\* [MTWFS][a-z][a-z]\), \([0-3][0-9]\) \([A-Z][a-z][a-z]\) /\1 \3 \2 /' \
        -e '/^\* [MTWFS][a-z][a-z] /{s/ [012][0-9]:[0-9][0-9]:[0-9][0-9] [+-][0-9]\{4\}//}' \
   >> $tmpspec

rpmbuild --define "_topdir $rpmdir" -bb $tmpspec
if [ $? = 0 ]; then
    rm -rf $tmpspec $rpmdir/BUILD
    mv $rpmdir/RPMS/*/* $rpmdir && rm -r $rpmdir/RPMS
    echo
    echo "Packages are in $rpmdir:"
    ls -l $rpmdir/*.rpm
fi