[debrepatch] 01/01: repatch: add flags for tweaking things and the ability to execute a post-patch command

Ximin Luo infinity0 at debian.org
Mon Sep 26 15:51:49 UTC 2016


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

infinity0 pushed a commit to branch master
in repository debrepatch.

commit 70bf0c967eaadd330186f49e1e8bba9e855d2320
Author: Ximin Luo <infinity0 at debian.org>
Date:   Mon Sep 26 17:51:29 2016 +0200

    repatch: add flags for tweaking things and the ability to execute a post-patch command
---
 debpatch |  11 ++++++-
 repatch  | 102 ++++++++++++++++++++++++++++++++++++++++++++++++---------------
 2 files changed, 88 insertions(+), 25 deletions(-)

diff --git a/debpatch b/debpatch
index 162d4a4..d4933ed 100755
--- a/debpatch
+++ b/debpatch
@@ -135,9 +135,13 @@ def main(args):
     parser.add_argument('-c', '--changelog', default='debian/changelog',
         help='Path to debian/changelog; default: %(default)s')
     parser.add_argument('-C', '--directory',
-        help="apply patches from this directory; should be the top-level source dir")
+        help="Apply patches from this directory; should be the top-level source dir")
     parser.add_argument('-i', '--interactive', action="store_true",
         help="Run the python REPL after processing.")
+    parser.add_argument('--source-version', action="store_true",
+        help="Don't apply the patch; instead print out the version of the Debian "
+        "package that it is supposed to be applied to, or nothing if this can't be "
+        "read from the debian/changelog hunk.")
     parser.add_argument('patch_file')
     args = parser.parse_args(args)
 
@@ -179,6 +183,11 @@ def main(args):
         patch.remove(changelog[0])
         old_version, target = read_dch_patch(changelog[0])
 
+    if args.source_version:
+        if old_version:
+            print(old_version)
+        return
+
     # TODO: if we patched any patch in d/patches, then we should refresh *that*
     # patch here. this is hard, but it would help us to avoid refreshing *all*
     # patches in ./repatch, hopefully ending up with a smaller debdiff.
diff --git a/repatch b/repatch
index 23c1db1..1af9381 100755
--- a/repatch
+++ b/repatch
@@ -6,39 +6,85 @@
 # watch out! if xargs gives non-0 exit code, it means there was a failure
 #
 scriptdir="$(readlink -f "$(dirname "$0")")"
-patchdir="${patchdir:-$scriptdir/patches}"
+debpatch="$scriptdir/debpatch"
 set -e
 
-test -n "$1" || exit
+USAGE="Usage: $0 [-hyuf] [-d patchdir] SOURCE_PACKAGE [post_patch_command [args ...]]"
+force_yes=false
+auto_update=false
+force_postpatch=false
+patchdir="./patches"
+builddir="./build"
+while getopts 'hd:yuf' o; do
+    case $o in
+    y )     force_yes=true;;
+    d )     patchdir="$OPTARG";;
+    u )     auto_update=true;;
+    f )     force_postpatch=true;;
+    h )     cat <<EOF
+$USAGE
 
-# options: -y # answer "yes" to all questions, e.g. when naive source-build fails
-# TODO:
-# options: -n # re-use existing dsc, don't rm
-# options: -u # upload to $HOST
-# options: -b # build using reprotest
-# options: -f # build even if no version change (diff source version = current version)
+Use debpatch(1) to apply a debdiff to the latest version of a given source
+package. If successful and the package is at a different version than what is
+mentioned in d/changelog from the debdiff, then run a command from inside the
+unpacked and patched package source directory.
 
+  -h            This help text.
+  -d            Directory to find patches in; default ./patches
+  -b            Directory to build new packages in; default ./build
+  -y            Answer "yes" to all questions, e.g. automatically trying to
+                refresh d/patches when a naive source-build fails.
+  -u            Run "apt-get update" first; requires sudo.
+  -f            Run post_patch_command even if there was no version change,
+                i.e. the current version is the same as what is mentioned in
+                debian/changelog in the patch file.
+EOF
+            exit 2
+            ;;
+    esac
+done
+shift $(expr $OPTIND - 1)
+
+log() {
+    # TODO: add some colours based on $1
+    echo >&2 "$0: $2"
+}
 maybe_ask() { read -p "$1 (press enter to continue) " x >&2; }
-if [ "$1" = "-y" ]; then
-    maybe_ask() { echo >&2 "$1"; }
-    shift
+if $force_yes; then
+    maybe_ask() { log I "$1"; }
 fi
 export QUILT_PATCHES=debian/patches
 
+test -n "$1" || { log E "$USAGE"; exit 2; }
 srcpkg="$1"
+shift
 
-mkdir -p "$scriptdir/build" && cd "$scriptdir/build"
-rm -rf "./$srcpkg" # TODO: disable this if -n
+if [ "$(ls -1 "$patchdir/$srcpkg"_*.patch | wc -l)" -gt 1 ]; then
+    log W "not sure how to apply more than 1 patch: "
+    ls -1 "$patchdir/$srcpkg"_*.patch
+    exit 1
+fi
+patchfile="$(readlink -f "$patchdir/$srcpkg"_*.patch)"
+patchdir="$(readlink -f "$patchdir")" # we cd later, so need this
+test -f "$patchfile"
+
+mkdir -p "$builddir" && cd "$builddir"
+rm -rf "./$srcpkg"
 mkdir -p "$srcpkg" && cd "$srcpkg"
 
+if $auto_update; then
+    sudo apt-get update
+fi
+
+# TODO: yeah this is hacky but is easier than trying to select the
+# right version out of `apt-cache showsrc`. Ideally we'd expose the
+# logic of "static pkgSrcRecords::Parser *FindSrc" in apt-private/private-source.cc
+oldver="$(LC_ALL="en_US.utf8" apt-get source -s "$srcpkg" | sed -n -e "s/.*version '\(.*\)' .*/\1/p")"
+srcdir="$srcpkg-$(echo "$oldver" | sed -e 's/\(.*\)-.*/\1/')"
 apt-get source "$srcpkg"
-olddsc="$(ls -1 *.dsc)"
-cd "$srcpkg"-*
-for i in "$patchdir/$srcpkg"_*.patch; do
-    # TODO: this would *probably* not work very well if we actually have
-    # multiple patchs for any source package. Try it and see! :p
-    "$scriptdir/debpatch" -v "$i"
-done
+olddsc="$(ls -1 *.dsc)" # TODO: probably more correct to use $oldver
+cd "$srcdir"
+"$debpatch" -v "$patchfile"
 
 build_dsc() {
     # we give "-nc" because:
@@ -66,12 +112,20 @@ version="$(dpkg-parsechangelog -c1 -SVersion | sed -e 's/^[0-9]*://')"
 newdsc="${srcpkg}_${version}.dsc"
 cd ..
 
-echo >&2 "$srcpkg patched successfully"
+log I "$srcpkg patched successfully"
 ls -l "$olddsc" "$newdsc"
 
 debdiff "$olddsc" "$newdsc" > "$patchdir/$srcpkg.patch.new" || true
-echo >&2 "updated patch written to $patchdir/$srcpkg.patch.new"
+log I "updated patch written to $patchdir/$srcpkg.patch.new"
 if $refreshed_patches; then
-    echo >&2 "however, we had to refresh d/patches in order to build $newdsc;"
-    echo >&2 "you should review the updated patch for unnecessary cruft before re-submitting it."
+    log W "however, we had to refresh d/patches in order to build $newdsc;"
+    log W "you should review the updated patch for unnecessary cruft before re-submitting it."
+fi
+
+if [ -z "$*" ]; then exit 0; fi
+
+if [ "$("$debpatch" --source-version "$patchfile")" != "$oldver" ] || $force_postpatch; then
+    cd "$srcdir"
+    log I "running post-patch command:" "$@"
+    exec "$@"
 fi

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



More information about the Reproducible-commits mailing list