[PATCH 6 of 6] buildrpm: enhance changelog of the RPM file

Gilles Moris gilles.moris at free.fr
Fri Nov 6 03:07:22 CST 2009


 contrib/buildrpm |  54 +++++++++++++++++++++++++++++++++++++++++++-----------
 1 files changed, 43 insertions(+), 11 deletions(-)


# HG changeset patch
# User Gilles Moris <gilles.moris at free.fr>
# Date 1257498368 -3600
# Node ID 70e88f859e4658d1bd3bc32036b0f0d62a74b842
# Parent  9f8a0a4d55253842dfa0b4bb6bf4fe94c0871aa9
buildrpm: enhance changelog of the RPM file

Now the changelog is different depending if the parent is tagged:
- for tags, keep the previous content, i.e. changelog of the tags.
- for nightly build, changelog of the changesets since the latest tag

As RPM is expecting strictly descending dates, I have used a python
script to reorder the mercurial changelog.

diff --git a/contrib/buildrpm b/contrib/buildrpm
--- a/contrib/buildrpm
+++ b/contrib/buildrpm
@@ -55,18 +55,50 @@
     -e "s,^Release:.*,Release: $release," \
     $specfile > $rpmspec
 
-cat <<EOF >> $rpmspec
-%changelog
-* `LANG=en_US date +'%a %b %d %Y'` `$HG showconfig ui.username` $version-$release
-- Automatically built via $0
+echo >> $rpmspec
+echo "%changelog" >> $rpmspec
 
-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\}//}' \
-   >> $rpmspec
+if echo $version | grep '+' > /dev/null 2>&1; then
+    latesttag="`echo $version | sed -e 's/+.*//'`"
+    $HG log -r .:"$latesttag" -fM \
+        --template '{date|hgdate}\t{author}\t{desc|firstline}\n' | python -c '
+import sys, time
+
+def datestr(date, format):
+    return time.strftime(format, time.gmtime(float(date[0]) - date[1]))
+
+changelog = []
+for l in sys.stdin.readlines():
+    tok = l.split("\t")
+    hgdate = tuple(int(v) for v in tok[0].split())
+    changelog.append((datestr(hgdate, "%F"), tok[1], hgdate, tok[2]))
+prevtitle = ""
+for l in sorted(changelog, reverse=True):
+    title = "* %s %s" % (datestr(l[2], "%a %b %d %Y"), l[1])
+    if prevtitle != title:
+        prevtitle = title
+        print
+        print title
+    print "- %s" % l[3].strip()
+' >> $rpmspec
+
+else
+
+    $HG log \
+         --template '{date|hgdate}\t{author}\t{desc|firstline}\n' \
+         .hgtags | python -c '
+import sys, time
+
+def datestr(date, format):
+    return time.strftime(format, time.gmtime(float(date[0]) - date[1]))
+
+for l in sys.stdin.readlines():
+    tok = l.split("\t")
+    hgdate = tuple(int(v) for v in tok[0].split())
+    print "* %s %s\n- %s" % (datestr(hgdate, "%a %b %d %Y"), tok[1], tok[2])
+' >> $rpmspec
+
+fi
 
 rpmbuild --define "_topdir $rpmdir" -ba $rpmspec --clean
 if [ $? = 0 ]; then


More information about the Mercurial-devel mailing list