From 5bbdbed9626ebd13fa965b88dbe361f784c87c76 Mon Sep 17 00:00:00 2001 From: David Futcher Date: Thu, 10 Jun 2010 15:12:25 +0100 Subject: [PATCH] edit-patch: Tentatively commit support for applying patches with no patchsystem present --- edit-patch | 85 +++++++++++++++++++++++++++++++++++------------------- 1 file changed, 55 insertions(+), 30 deletions(-) diff --git a/edit-patch b/edit-patch index da2f3ca..75532ae 100755 --- a/edit-patch +++ b/edit-patch @@ -4,7 +4,8 @@ # # Authors: # Daniel Holbach -# Michael Vogt +# Michael Vogt +# David Futcher # # This program is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free Software @@ -24,6 +25,7 @@ set -e PATCHSYSTEM="unknown" PATCHNAME="no-patch-name" +PREFIX="debian/patches" PATCH_DESC=$(cat<> debian/patches/00list + if ! grep -q $1 $PREFIX/00list; then + echo "$1" >> $PREFIX/00list fi - vcs_add debian/patches/00list debian/patches/$1 + vcs_add $PREFIX/00list $PREFIX/$1 } edit_patch_quilt() { export QUILT_PATCHES=debian/patches - if [ -e debian/patches/$1 ]; then + if [ -e $PREFIX/$1 ]; then # if its a existing patch and we are at the end of the stack, # go back at the beginning if ! quilt unapplied; then @@ -133,7 +138,7 @@ edit_patch_quilt() { quilt shell quilt refresh quilt pop -a - vcs_add debian/patches/$1 debian/patches/series + vcs_add $PREFIX/$1 $PREFIX/series } vcs_add() { @@ -156,7 +161,7 @@ vcs_commit() { } add_changelog() { - S="debian/patches/$1: [DESCRIBE CHANGES HERE]" + S="$PREFIX/$1: [DESCRIBE CHANGES HERE]" if head -n1 debian/changelog|grep UNRELEASED; then dch --append "$S" else @@ -168,57 +173,77 @@ add_changelog() { add_patch_tagging() { # check if we have a descripton already - if grep "## Description:" debian/patches/$1; then + if grep "## Description:" $PREFIX/$1; then return fi # if not, add one RANGE=1,1 # make sure we keep the first line (for dpatch) - if head -n1 debian/patches/$1|grep -q '^#'; then + if head -n1 $PREFIX/$1|grep -q '^#'; then RANGE=2,2 fi - sed -i ${RANGE}i"$PATCH_DESC" debian/patches/$1 + sed -i ${RANGE}i"$PATCH_DESC" $PREFIX/$1 } detect_patch_location() { # Checks whether the specified patch exists in debian/patches or on the filesystem FILENAME=${PATCHNAME##*/} - if [ -f "debian/patches/$FILENAME" ]; then + if [ -f "$PREFIX/$FILENAME" ]; then PATCHTYPE="debian" elif [ -f "$PATCHNAME" ]; then PATCHTYPE="file" PATCHORIG="$PATCHNAME" else - PATCHTYPE="new" + if [ "$PATCHSYSTEM" = "none" ]; then + fatal_error "No patchsystem detected, cannot create new patch (no dpatch/quilt/cdbs?)" + else + PATCHTYPE="new" + fi fi } -prepare_new_patch() { - # Prepares new patches by copying them into debian/patches and adding - # them to the relevant series files. Also adds dpatch headers when required. +edit_patch_none() { + # Dummy edit-patch function, just display a warning message + echo "No patchsystem could be found so the patch was applied inline and a copy \ +stored in debian/patches-applied. Please remember to mention this in your changelog." +} + +handle_file_patch() { if [ "$PATCHTYPE" = "file" ]; then - cp "$PATCHORIG" "debian/patches/$PATCHNAME" - - if [ "$PATCHSYSTEM" = "quilt" ]; then - echo "$PATCHNAME" >> debian/patches/series - elif [ "$PATCHSYSTEM" = "dpatch" ]; then - echo "$PATCHNAME" >> debian/patches/00list + [ -f "$PATCHORIG" ] || fatal_error "No patch detected" + + if [ "$PATCHSYSTEM" = "none" ]; then + # If we're supplied a file and there is no patchsys we apply it directly + # and store it in debian/applied patches + [ -d $PREFIX ] || mkdir $PREFIX - # Add the dpatch header to files that don't already have it - if ! grep -q "@DPATCH@" "debian/patches/$PATCHNAME"; then - sed -i '1i#! /bin/sh /usr/share/dpatch/dpatch-run\n@DPATCH@' debian/patches/$PATCHNAME + patch -p0 < "$PATCHORIG" + cp "$PATCHORIG" "$PREFIX/$PATCHNAME" + else + # Patch type is file but there is a patchsys present, so we add it + # correctly + cp "$PATCHORIG" "$PREFIX/$PATCHNAME" + + if [ "$PATCHSYSTEM" = "quilt" ]; then + echo "$PATCHNAME" >> $PREFIX/series + elif [ "$PATCHSYSTEM" = "dpatch" ]; then + echo "$PATCHNAME" >> $PREFIX/00list + + # Add the dpatch header to files that don't already have it + if ! grep -q "@DPATCH@" "$PREFIX/$PATCHNAME"; then + sed -i '1i#! /bin/sh /usr/share/dpatch/dpatch-run\n@DPATCH@' $PREFIX/$PATCHNAME + fi fi + + echo "Copying and applying new patch. You can now edit the patch or exit the subshell to save." fi - - echo "Copying and applying new patch. You can now edit the patch or exit the subshell to save." fi } # TODO: # - edit-patch --remove implementieren # - dbs patch system -# - handle no patch system main() { # parse args @@ -232,7 +257,7 @@ main() { detect_patch_location normalize_patch_path normalize_patch_extension - prepare_new_patch + handle_file_patch edit_patch_$PATCHSYSTEM $PATCHNAME add_patch_tagging $PATCHNAME add_changelog $PATCHNAME