[linux] 03/05: stable-update: Rewrite stable-update.sh in Python

debian-kernel at lists.debian.org debian-kernel at lists.debian.org
Sun May 8 01:46:21 UTC 2016


This is an automated email from the git hooks/post-receive script.

benh pushed a commit to branch jessie
in repository linux.

commit 858ac7d9fce471adff600a65dba3b44da07b217a
Author: Ben Hutchings <ben at decadent.org.uk>
Date:   Sat May 7 21:31:44 2016 +0100

    stable-update: Rewrite stable-update.sh in Python
    
    This fixes some of the problems dch was causing:
    - Putting the stable log in the wrong place
    - Updating the date unnecessarily
    
    Change stable-update.sh to be a wrapper for stable-update.
    
    Delete ckt-stable-update.sh; if we need it again in future, it can be
    implemented more cleanly as part of the new script.
    
    (cherry picked from commit 12fe9efbc6955472f1fca74dbe7848f18e4e4572)
    
    Conflicts:
    	debian/README.source
    	debian/bin/stable-update.sh
    	debian/changelog
    
    Drop changes to debian/README.source.
    
    Change interpreter to Python 2, as the debian_linux Python package here
    is not ready for Python 3.
---
 debian/bin/ckt-stable-update.sh |  76 ------------------------
 debian/bin/stable-update        | 128 ++++++++++++++++++++++++++++++++++++++++
 debian/bin/stable-update.sh     |  80 +------------------------
 debian/changelog                |   1 +
 4 files changed, 131 insertions(+), 154 deletions(-)

diff --git a/debian/bin/ckt-stable-update.sh b/debian/bin/ckt-stable-update.sh
deleted file mode 100755
index 729e18b..0000000
--- a/debian/bin/ckt-stable-update.sh
+++ /dev/null
@@ -1,76 +0,0 @@
-#!/bin/bash -eu
-
-if [ $# -ne 2 ]; then
-    echo >&2 "Usage: $0 REPO VERSION"
-    echo >&2 "REPO is the git repository to generate a changelog from"
-    echo >&2 "VERSION is the stable version (without leading v)"
-    exit 2
-fi
-
-# Get base version, i.e. the stable release that a branch started from
-base_version() {
-    local ver
-    ver="${1%-rc*}"
-    case "$ver" in
-	*-ckt*)
-	    ver="${ver%-*}"
-	    ;;
-    esac
-    echo "$ver"
-}
-
-add_update() {
-    local base update
-    base="$(base_version "$1")"
-    update="${1#$base-ckt}"
-    if [ "$update" = "$1" ]; then
-	update=0
-    fi
-    update="$((update + $2))"
-    if [ $update = 0 ]; then
-	echo "$base"
-    else
-	echo "$base-ckt$update"
-    fi
-}
-
-# Get next stable update version
-next_update() {
-    add_update "$1" 1
-}
-
-export GIT_DIR="$1/.git"
-
-new_ver="$2"
-cur_pkg_ver="$(dpkg-parsechangelog | sed -n 's/^Version: //p')"
-cur_ver="${cur_pkg_ver%-*}"
-
-if [ "$(base_version "$new_ver")" != "$(base_version "$cur_ver")" ]; then
-    echo >&2 "$new_ver is not on the same stable series as $cur_ver"
-    exit 2
-fi
-
-case "$cur_pkg_ver" in
-    *~exp*)
-	new_pkg_ver="$new_ver-1~exp1"
-	;;
-    *)
-	new_pkg_ver="$new_ver-1"
-	;;
-esac
-
-# dch insists on word-wrapping everything, so just add the first line initially
-dch -v "$new_pkg_ver" --preserve --multimaint-merge -D UNRELEASED \
-    --release-heuristic=changelog 'New upstream stable update:'
-
-# Then append the shortlogs with sed
-sed -i '1,/^ --/ { /New upstream stable update:/ { a\
-'"$(
-while [ "v$cur_ver" != "v$new_ver" ]; do
-    next_ver="$(next_update "$cur_ver")"
-    echo "    http://kernel.ubuntu.com/stable/ChangeLog-$next_ver\\"
-    git log --reverse --pretty='    - %s\' "v$cur_ver..v$next_ver^"
-    cur_ver="$next_ver"
-done)"'
-
-} }' debian/changelog
diff --git a/debian/bin/stable-update b/debian/bin/stable-update
new file mode 100755
index 0000000..eddb907
--- /dev/null
+++ b/debian/bin/stable-update
@@ -0,0 +1,128 @@
+#!/usr/bin/python
+
+from __future__ import print_function
+
+import sys
+sys.path.append(sys.path[0] + "/../lib/python")
+
+import os, re, subprocess
+
+from debian_linux.debian import Changelog, VersionLinux
+
+def base_version(ver):
+    # Assume base version is at least 3.0, thus only 2 components wanted
+    match = re.match(r'^(\d+\.\d+)', ver)
+    assert match
+    return match.group(1)
+
+def add_update(ver, inc):
+    base = base_version(ver)
+    if base == ver:
+        update = 0
+    else:
+        update = int(ver[len(base)+1:])
+    update += inc
+    if update == 0:
+        return base
+    else:
+        return '{}.{}'.format(base, update)
+
+def next_update(ver):
+    return add_update(ver, 1)
+
+def print_stable_log(log, cur_ver, new_ver):
+    major_ver = re.sub(r'^(\d+)\..*', r'\1', cur_ver)
+    while cur_ver != new_ver:
+        next_ver = next_update(cur_ver)
+        print('    https://www.kernel.org/pub/linux/kernel/v{}.x/ChangeLog-{}'
+              .format(major_ver, next_ver),
+              file=log)
+        log.flush() # serialise our output with git's
+        subprocess.check_call(['git', 'log', '--reverse',
+                               '--pretty=    - %s',
+                               'v{}..v{}^'.format(cur_ver, next_ver)],
+                              stdout=log)
+        cur_ver = next_ver
+
+def main(repo, new_ver):
+    os.environ['GIT_DIR'] = repo + '/.git'
+
+    changelog = Changelog(version=VersionLinux)
+    cur_pkg_ver = changelog[0].version
+    cur_ver = cur_pkg_ver.linux_upstream_full
+
+    if base_version(new_ver) != base_version(cur_ver):
+        print('{} is not on the same stable series as {}'
+              .format(new_ver, cur_ver),
+              file=sys.stderr)
+        sys.exit(2)
+
+    new_pkg_ver = new_ver + '-1'
+    if cur_pkg_ver.linux_revision_experimental:
+        new_pkg_ver += '~exp1'
+
+    # Three possible cases:
+    # 1. The current version has been released so we need to add a new
+    #    version to the changelog.
+    # 2. The current version has not been released so we're changing its
+    #    version string.
+    #    (a) There are no stable updates included in the current version,
+    #        so we need to insert an introductory line, the URL(s) and
+    #        git log(s) and a blank line at the top.
+    #    (b) One or more stable updates are already included in the current
+    #        version, so we need to insert the URL(s) and git log(s) after
+    #        them.
+
+    changelog_intro = 'New upstream stable update:'
+
+    # Case 1
+    if changelog[0].distribution != 'UNRELEASED':
+        subprocess.check_call(['dch', '-v', new_pkg_ver, '-D', 'UNRELEASED',
+                               changelog_intro])
+
+    with open('debian/changelog', 'r') as old_log:
+        with open('debian/changelog.new', 'w') as new_log:
+            line_no = 0
+            inserted = False
+            intro_line = '  * {}\n'.format(changelog_intro)
+
+            for line in old_log:
+                line_no += 1
+
+                # Case 2
+                if changelog[0].distribution == 'UNRELEASED' and line_no == 1:
+                    print('{} ({}) UNRELEASED; urgency={}'
+                          .format(changelog[0].source, new_pkg_ver,
+                                  changelog[0].urgency),
+                          file=new_log)
+                    continue
+
+                if not inserted:
+                    # Case 2(a)
+                    if line_no == 3 and line != intro_line:
+                        new_log.write(intro_line)
+                        print_stable_log(new_log, cur_ver, new_ver)
+                        new_log.write('\n')
+                        inserted = True
+                    # Case 1 or 2(b)
+                    elif line_no > 3 and line == '\n':
+                        print_stable_log(new_log, cur_ver, new_ver)
+                        inserted = True
+
+                # Check that we inserted before hitting the end of the
+                # first version entry
+                assert not (line.startswith(' -- ') and not inserted)
+
+                new_log.write(line)
+
+    os.rename('debian/changelog.new', 'debian/changelog')
+
+if __name__ == '__main__':
+    if len(sys.argv) != 3:
+        print('''\
+Usage: {} REPO VERSION"
+REPO is the git repository to generate a changelog from
+VERSION is the stable version (without leading v)'''.format(sys.argv[0]),
+              file=sys.stderr)
+        sys.exit(2)
+    main(*sys.argv[1:])
diff --git a/debian/bin/stable-update.sh b/debian/bin/stable-update.sh
index c6fb397..bd86860 100755
--- a/debian/bin/stable-update.sh
+++ b/debian/bin/stable-update.sh
@@ -1,78 +1,2 @@
-#!/bin/bash -eu
-
-if [ $# -ne 2 ]; then
-    echo >&2 "Usage: $0 REPO VERSION"
-    echo >&2 "REPO is the git repository to generate a changelog from"
-    echo >&2 "VERSION is the stable version (without leading v)"
-    exit 2
-fi
-
-# Get base version, i.e. the Linus stable release that a version is based on
-base_version() {
-    local ver
-    ver="${1%-rc*}"
-    case "$ver" in
-	2.6.*.* | [3-9].*.* | ??.*.*)
-	    ver="${ver%.*}"
-	    ;;
-    esac
-    echo "$ver"
-}
-
-add_update() {
-    local base update
-    base="$(base_version "$1")"
-    update="${1#$base.}"
-    if [ "$update" = "$1" ]; then
-	update=0
-    fi
-    update="$((update + $2))"
-    if [ $update = 0 ]; then
-	echo "$base"
-    else
-	echo "$base.$update"
-    fi
-}
-
-# Get next stable update version
-next_update() {
-    add_update "$1" 1
-}
-
-export GIT_DIR="$1/.git"
-
-new_ver="$2"
-cur_pkg_ver="$(dpkg-parsechangelog | sed -n 's/^Version: //p')"
-cur_ver="${cur_pkg_ver%-*}"
-
-if [ "$(base_version "$new_ver")" != "$(base_version "$cur_ver")" ]; then
-    echo >&2 "$new_ver is not on the same stable series as $cur_ver"
-    exit 2
-fi
-
-case "$cur_pkg_ver" in
-    *~exp*)
-	new_pkg_ver="$new_ver-1~exp1"
-	;;
-    *)
-	new_pkg_ver="$new_ver-1"
-	;;
-esac
-
-# dch insists on word-wrapping everything, so just add the URLs initially
-dch -v "$new_pkg_ver" --preserve --multimaint-merge -D UNRELEASED \
-    --release-heuristic=changelog "$(
-    echo "New upstream stable update: "
-    while [ "v$cur_ver" != "v$new_ver" ]; do
-        cur_ver="$(next_update "$cur_ver")"
-        echo "https://www.kernel.org/pub/linux/kernel/v3.x/ChangeLog-$cur_ver"
-    done)"
-
-# Then insert the shortlogs with sed
-while [ "v$cur_ver" != "v$new_ver" ]; do
-    next_ver="$(next_update "$cur_ver")"
-    sed -i '/ChangeLog-'"${next_ver//./\\.}"'/a\
-'"$(git log --reverse --pretty='    - %s\' "v$cur_ver..v$next_ver^")"'
-' debian/changelog
-    cur_ver="$next_ver"
-done
+#!/bin/sh -e
+exec "$(dirname "$0")/stable-update" "$@"
diff --git a/debian/changelog b/debian/changelog
index 1b743ac..8ca525d 100644
--- a/debian/changelog
+++ b/debian/changelog
@@ -151,6 +151,7 @@ linux (3.16.7-ckt27-1) UNRELEASED; urgency=medium
   * Revert "libata: Align ata_device's id on a cacheline" to avoid ABI change
   * Revert "net/ipv6: add sysctl option accept_ra_min_hop_limit" to avoid ABI
     change
+  * stable-update: Rewrite stable-update.sh in Python
 
  -- Ben Hutchings <ben at decadent.org.uk>  Sat, 30 Apr 2016 22:07:22 +0200
 

-- 
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/kernel/linux.git



More information about the Kernel-svn-changes mailing list