[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Auto-generating ChangeLogs, take two



Hi,

following some recent discussions with Guillem, I rewrote the script
that I proposed to update the ChangeLog files.

It's similar in spirit but it only extracts the block that conform to the
GNU Changelog style (starting with "* " and ending with an empty line).
It will also look for pseudo fields "Contributions-from" or
"Based-on-a-patch-by" to add supplementary "authors" in the generated
Changelog entry.

It will dispatch the entries in the various ChangeLog depending on
the set of files modified by the corresponding commit.

The script is not very efficient but it doesn't matter much as it's only
run once before a new release and the number of commits will never be
huge.

Comments are welcome, if everything is fine, I'd like to merge soon
because it will facilitate the maintenance (and later merge) of multiple
branches.

Cheers,
-- 
Raphaël Hertzog

Le best-seller français mis à jour pour Debian Etch :
http://www.ouaza.com/livre/admin-debian/
>From ce9e2bd677f74f28d7ee92c33e264bdbc867ebc3 Mon Sep 17 00:00:00 2001
From: Raphael Hertzog <hertzog@debian.org>
Date: Mon, 30 Jun 2008 21:00:45 +0200
Subject: [PATCH] New infrastructure to auto-update ChangeLogs based on git log

* maint-tools/update-changelogs: new script that generates ChangeLog
entries for all commits merged since the last run. It will dispatch the
entries in the various ChangeLogs based on the set of modified files.
* README.translators: update recommendations for translators.
* ChangeLog: add the initial marker of last revision described in the
ChangeLog
* Makefile.am: add the new script to EXTRA_FILES.

Contributions-from: Guillem Jover <guillem@debian.org>
---
 ChangeLog                     |    1 +
 Makefile.am                   |    3 +-
 README.translators            |   54 ++++++++----------------
 maint-tools/update-changelogs |   92 +++++++++++++++++++++++++++++++++++++++++
 4 files changed, 113 insertions(+), 37 deletions(-)
 create mode 100755 maint-tools/update-changelogs

diff --git a/ChangeLog b/ChangeLog
index 15f57b7..0810f9c 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -14634,3 +14634,4 @@ Thu Aug 25 11:46:27 1994  Ian Murdock  (imurdock@debra.debian.org)
 
 ChangeLog begins Thu Aug 25 11:46:27 1994 for dpkg 0.93.5.
 
+last: 3e5aa7b25b21c6fd845d70073770d7c10f9af071
diff --git a/Makefile.am b/Makefile.am
index 77988c7..80a8971 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -53,7 +53,8 @@ EXTRA_DIST = \
 	debian/usertags \
 	debian/rules \
 	debian/shlibs.default \
-	debian/shlibs.override
+	debian/shlibs.override \
+	maint-tools/update-changelogs
 
 # If we create the dist tarball from the git repository, make sure
 # that we're not forgetting some files...
diff --git a/README.translators b/README.translators
index 8a11e99..c967e5a 100644
--- a/README.translators
+++ b/README.translators
@@ -1,35 +1,8 @@
 Translators, when adding/updating your translation files, please follow
 the following rules:
 
-* Update debian/changelog and one of po/ChangeLog, dselect/po/ChangeLog,
-  scripts/ChangeLog or man/ChangeLog:
-
-  - Beware the you should NOT update the main ChangeLog file
-    for translation updates. Use the ChangeLog in the relevant
-    subdirectory instead.
-
-  - The format of entries in the subdirectories' ChangeLog is strict:
-
-==========================================================
-2006-02-11  Christian Perrier  <bubulle@debian.org>
-
-	* fr.po: Updated to 1011t.
-==========================================================
-
-    Note the date format AND the DOUBLE SPACE between the date and the
-    translator's email address.
-
-    Note also the TAB character before the entry. NOT multiple spaces.
-
-    Also note that the update should mention the file statistics as
-    XXXtYYYfZZZu.
-
-    "XXXt" means "XXX translated strings".
-    "YYYf" means "YYY fuzzy strings strings".
-    "ZZZu" means "ZZZ untranslated strings".
-    YYY or ZZZ may be omitted if they are null.
-
-    This file contents MUST be encoded in UTF-8.
+* Update debian/changelog but do not touch to any other ChangeLog file,
+  they are auto-generated based on the git commit messages.
 
 * Format of entries in debian/changelog:
 
@@ -64,18 +37,27 @@ dpkg (1.13.15) unstable; urgency=low
 
 * Format of commit message
 
-  The formats above only apply to ChangeLog files and debian/changelog.
-  They do not apply to the commit message. Following recommendations
-  of http://wiki.debian.org/Teams/Dpkg/GitUsage you should start the
-  commit message with a summary line, followed by an empty line and a
-  a detailed/long description. For example:
+  Since ChangeLog files are auto-generated, it's important to properly
+  format the commit message.  Following recommendations of
+  http://wiki.debian.org/Teams/Dpkg/GitUsage you should start the commit
+  message with a summary line, followed by an empty line and a
+  detailed/long description. For example:
 
 ==========================================================
-Updated german translation of manual pages
+Updated german translation
 
-	* man/po/fr.po: Updated to 1354t.
+* man/po/de.po: Updated to 1354t.
+* po/de.po: Updated to 1335t0f48u.
 ==========================================================
 
+  Note that the detailed description should mention the file statistics
+  as XXXtYYYfZZZu.
+
+  "XXXt" means "XXX translated strings".
+  "YYYf" means "YYY fuzzy strings strings".
+  "ZZZu" means "ZZZ untranslated strings".
+  YYY or ZZZ may be omitted if they are null.
+
 * Use of po/LINGUAS, dselect/po/LINGUAS or scripts/po/LINGUAS:
 
   When ADDING a new translation, don't forget adding the language to
diff --git a/maint-tools/update-changelogs b/maint-tools/update-changelogs
new file mode 100755
index 0000000..b2545d2
--- /dev/null
+++ b/maint-tools/update-changelogs
@@ -0,0 +1,92 @@
+#!/bin/sh
+
+extract_gnu_changelog_entry() {
+    awk 'BEGIN { IN = 0 }
+	{
+	    if(IN == 0) {
+		if(/^[[:blank:]]*\* /) { IN=1; STRIP = index($0, "*"); print "\t" substr($0, STRIP); }
+	    } else {
+		if(/^$/) { IN=0 }
+		print "\t" substr($0, STRIP);
+	    }
+	}
+	END { if (IN == 1) { print "\t\n" } }
+	'
+}
+
+extract_contributors() {
+    awk -F ": " '/^(Based-on-a-patch-by|Contributions-from): / { sub(" *<", "  <", $2); print $2 }'
+}
+
+display_entry() {
+    local commit date author summary body entry contributor IFS
+    commit="$1"
+    date=$(git log -n 1 --pretty='format:%ci' $commit | awk '{print $1}')
+    author=$(git log -n 1 --pretty='format:%an  <%ae>' $commit)
+    summary=$(git log -n 1 --pretty='format:%s' $commit)
+    body=$(git log -n 1 --pretty='format:%b%n' $commit)
+    entry=$(echo "$body" | extract_gnu_changelog_entry)
+    [ -n "$entry" ] || return
+    echo -n "$date  $author"
+    IFS="
+"
+    for contributor in $(echo "$body" | extract_contributors); do
+	echo ","
+	echo -n "            $contributor"
+    done
+    echo ""
+    echo ""
+    echo "$entry"
+}
+
+get_filelist() {
+    git whatchanged -n 1 $1 | awk '
+	/^:/ { if ($6 !~ /(^debian\/|ChangeLog$)/) { print $6 } }
+	'
+}
+
+select_changelogs() {
+    while read line; do
+	case "$line" in
+	    po/*)
+		echo "po/ChangeLog"
+		;;
+	    dselect/po/*)
+		echo "dselect/po/ChangeLog"
+		;;
+	    man/po/*)
+		echo "man/po/ChangeLog"
+		;;
+	    scripts/po/*)
+		echo "scripts/po/ChangeLog"
+		;;
+	    *)
+		echo "ChangeLog"
+		;;
+	esac
+    done | sort -u
+}
+
+oldtip=$(awk '/^last: / { print $2 }' ChangeLog)
+newtip=$(git log -n 1 --pretty="format:%H")
+
+for rev in $(git rev-list $oldtip..); do
+    entry=$(display_entry $rev)
+    [ -n "$entry" ] || continue
+    filelist=$(get_filelist $rev)
+    changelogs=$(echo "$filelist" | select_changelogs)
+
+    for ch in $changelogs; do
+	echo "$entry" >>$ch.new
+    done
+done
+
+for ch in ChangeLog po/ChangeLog scripts/po/ChangeLog man/po/ChangeLog; do
+    if [ -e $ch.new ]; then
+	sed -i -e "s/^	$//" $ch.new
+	cat $ch >>$ch.new
+	mv $ch.new $ch
+    fi
+done
+sed -i -e "s/^last: .*/last: $newtip/" ChangeLog
+
-- 
1.5.6


Reply to: