mirror of
				https://git.launchpad.net/ubuntu-dev-tools
				synced 2025-11-04 07:54:03 +00:00 
			
		
		
		
	edit-patch: Tentatively commit support for applying patches with no patchsystem present
This commit is contained in:
		
							parent
							
								
									31c8c6dfcf
								
							
						
					
					
						commit
						5bbdbed962
					
				
							
								
								
									
										85
									
								
								edit-patch
									
									
									
									
									
								
							
							
						
						
									
										85
									
								
								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<<EOF
 | 
			
		||||
## Description: add some description\
 | 
			
		||||
@ -66,7 +68,8 @@ detect_patchsystem() {
 | 
			
		||||
	PATCHSYSTEM="quilt"
 | 
			
		||||
	require_installed quilt "no quilt found, is 'quilt' installed?"
 | 
			
		||||
    else
 | 
			
		||||
	fatal_error "Patch system can not be detected (no quilt, cdbs or dpatch?)"
 | 
			
		||||
    PATCHSYSTEM="none"
 | 
			
		||||
    PREFIX="debian/applied-patches"
 | 
			
		||||
    fi
 | 
			
		||||
}
 | 
			
		||||
 | 
			
		||||
@ -81,7 +84,7 @@ normalize_patch_path() {
 | 
			
		||||
# - cdbs/quilt with .patch
 | 
			
		||||
normalize_patch_extension() {
 | 
			
		||||
    # check if we have a patch already
 | 
			
		||||
    if [ -e debian/patches/$PATCHNAME ]; then
 | 
			
		||||
    if [ -e $PREFIX/$PATCHNAME ]; then
 | 
			
		||||
	echo "Patch $PATCHNAME exists, not normalizing"
 | 
			
		||||
	return
 | 
			
		||||
    fi
 | 
			
		||||
@ -94,6 +97,8 @@ normalize_patch_extension() {
 | 
			
		||||
	PATCHNAME="${PATCHNAME}.patch"
 | 
			
		||||
    elif [ "$PATCHSYSTEM" = "dpatch" ]; then
 | 
			
		||||
	PATCHNAME="${PATCHNAME}.dpatch"
 | 
			
		||||
	elif [ "$PATCHSYSTEM" = "none" ]; then
 | 
			
		||||
	PATCHNAME="${PATCHNAME}.patch"
 | 
			
		||||
    fi
 | 
			
		||||
 | 
			
		||||
    echo "Normalizing patch name to $PATCHNAME"
 | 
			
		||||
@ -107,15 +112,15 @@ edit_patch_cdbs() {
 | 
			
		||||
edit_patch_dpatch() {
 | 
			
		||||
    dpatch-edit-patch $PATCHNAME
 | 
			
		||||
    # add if needed
 | 
			
		||||
    if ! grep -q $1 debian/patches/00list; then
 | 
			
		||||
	echo "$1" >> 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
 | 
			
		||||
 | 
			
		||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user