mirror of
https://git.launchpad.net/ubuntu-dev-tools
synced 2025-05-06 22:41:35 +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:
|
# Authors:
|
||||||
# Daniel Holbach
|
# Daniel Holbach
|
||||||
# Michael Vogt
|
# Michael Vogt
|
||||||
|
# David Futcher
|
||||||
#
|
#
|
||||||
# This program is free software; you can redistribute it and/or modify it under
|
# 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
|
# the terms of the GNU General Public License as published by the Free Software
|
||||||
@ -24,6 +25,7 @@ set -e
|
|||||||
|
|
||||||
PATCHSYSTEM="unknown"
|
PATCHSYSTEM="unknown"
|
||||||
PATCHNAME="no-patch-name"
|
PATCHNAME="no-patch-name"
|
||||||
|
PREFIX="debian/patches"
|
||||||
|
|
||||||
PATCH_DESC=$(cat<<EOF
|
PATCH_DESC=$(cat<<EOF
|
||||||
## Description: add some description\
|
## Description: add some description\
|
||||||
@ -66,7 +68,8 @@ detect_patchsystem() {
|
|||||||
PATCHSYSTEM="quilt"
|
PATCHSYSTEM="quilt"
|
||||||
require_installed quilt "no quilt found, is 'quilt' installed?"
|
require_installed quilt "no quilt found, is 'quilt' installed?"
|
||||||
else
|
else
|
||||||
fatal_error "Patch system can not be detected (no quilt, cdbs or dpatch?)"
|
PATCHSYSTEM="none"
|
||||||
|
PREFIX="debian/applied-patches"
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,7 +84,7 @@ normalize_patch_path() {
|
|||||||
# - cdbs/quilt with .patch
|
# - cdbs/quilt with .patch
|
||||||
normalize_patch_extension() {
|
normalize_patch_extension() {
|
||||||
# check if we have a patch already
|
# check if we have a patch already
|
||||||
if [ -e debian/patches/$PATCHNAME ]; then
|
if [ -e $PREFIX/$PATCHNAME ]; then
|
||||||
echo "Patch $PATCHNAME exists, not normalizing"
|
echo "Patch $PATCHNAME exists, not normalizing"
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
@ -94,6 +97,8 @@ normalize_patch_extension() {
|
|||||||
PATCHNAME="${PATCHNAME}.patch"
|
PATCHNAME="${PATCHNAME}.patch"
|
||||||
elif [ "$PATCHSYSTEM" = "dpatch" ]; then
|
elif [ "$PATCHSYSTEM" = "dpatch" ]; then
|
||||||
PATCHNAME="${PATCHNAME}.dpatch"
|
PATCHNAME="${PATCHNAME}.dpatch"
|
||||||
|
elif [ "$PATCHSYSTEM" = "none" ]; then
|
||||||
|
PATCHNAME="${PATCHNAME}.patch"
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Normalizing patch name to $PATCHNAME"
|
echo "Normalizing patch name to $PATCHNAME"
|
||||||
@ -107,15 +112,15 @@ edit_patch_cdbs() {
|
|||||||
edit_patch_dpatch() {
|
edit_patch_dpatch() {
|
||||||
dpatch-edit-patch $PATCHNAME
|
dpatch-edit-patch $PATCHNAME
|
||||||
# add if needed
|
# add if needed
|
||||||
if ! grep -q $1 debian/patches/00list; then
|
if ! grep -q $1 $PREFIX/00list; then
|
||||||
echo "$1" >> debian/patches/00list
|
echo "$1" >> $PREFIX/00list
|
||||||
fi
|
fi
|
||||||
vcs_add debian/patches/00list debian/patches/$1
|
vcs_add $PREFIX/00list $PREFIX/$1
|
||||||
}
|
}
|
||||||
|
|
||||||
edit_patch_quilt() {
|
edit_patch_quilt() {
|
||||||
export QUILT_PATCHES=debian/patches
|
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,
|
# if its a existing patch and we are at the end of the stack,
|
||||||
# go back at the beginning
|
# go back at the beginning
|
||||||
if ! quilt unapplied; then
|
if ! quilt unapplied; then
|
||||||
@ -133,7 +138,7 @@ edit_patch_quilt() {
|
|||||||
quilt shell
|
quilt shell
|
||||||
quilt refresh
|
quilt refresh
|
||||||
quilt pop -a
|
quilt pop -a
|
||||||
vcs_add debian/patches/$1 debian/patches/series
|
vcs_add $PREFIX/$1 $PREFIX/series
|
||||||
}
|
}
|
||||||
|
|
||||||
vcs_add() {
|
vcs_add() {
|
||||||
@ -156,7 +161,7 @@ vcs_commit() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
add_changelog() {
|
add_changelog() {
|
||||||
S="debian/patches/$1: [DESCRIBE CHANGES HERE]"
|
S="$PREFIX/$1: [DESCRIBE CHANGES HERE]"
|
||||||
if head -n1 debian/changelog|grep UNRELEASED; then
|
if head -n1 debian/changelog|grep UNRELEASED; then
|
||||||
dch --append "$S"
|
dch --append "$S"
|
||||||
else
|
else
|
||||||
@ -168,57 +173,77 @@ add_changelog() {
|
|||||||
|
|
||||||
add_patch_tagging() {
|
add_patch_tagging() {
|
||||||
# check if we have a descripton already
|
# check if we have a descripton already
|
||||||
if grep "## Description:" debian/patches/$1; then
|
if grep "## Description:" $PREFIX/$1; then
|
||||||
return
|
return
|
||||||
fi
|
fi
|
||||||
# if not, add one
|
# if not, add one
|
||||||
RANGE=1,1
|
RANGE=1,1
|
||||||
# make sure we keep the first line (for dpatch)
|
# 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
|
RANGE=2,2
|
||||||
fi
|
fi
|
||||||
sed -i ${RANGE}i"$PATCH_DESC" debian/patches/$1
|
sed -i ${RANGE}i"$PATCH_DESC" $PREFIX/$1
|
||||||
}
|
}
|
||||||
|
|
||||||
detect_patch_location() {
|
detect_patch_location() {
|
||||||
# Checks whether the specified patch exists in debian/patches or on the filesystem
|
# Checks whether the specified patch exists in debian/patches or on the filesystem
|
||||||
FILENAME=${PATCHNAME##*/}
|
FILENAME=${PATCHNAME##*/}
|
||||||
|
|
||||||
if [ -f "debian/patches/$FILENAME" ]; then
|
if [ -f "$PREFIX/$FILENAME" ]; then
|
||||||
PATCHTYPE="debian"
|
PATCHTYPE="debian"
|
||||||
elif [ -f "$PATCHNAME" ]; then
|
elif [ -f "$PATCHNAME" ]; then
|
||||||
PATCHTYPE="file"
|
PATCHTYPE="file"
|
||||||
PATCHORIG="$PATCHNAME"
|
PATCHORIG="$PATCHNAME"
|
||||||
else
|
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
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
prepare_new_patch() {
|
edit_patch_none() {
|
||||||
# Prepares new patches by copying them into debian/patches and adding
|
# Dummy edit-patch function, just display a warning message
|
||||||
# them to the relevant series files. Also adds dpatch headers when required.
|
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
|
if [ "$PATCHTYPE" = "file" ]; then
|
||||||
cp "$PATCHORIG" "debian/patches/$PATCHNAME"
|
[ -f "$PATCHORIG" ] || fatal_error "No patch detected"
|
||||||
|
|
||||||
if [ "$PATCHSYSTEM" = "quilt" ]; then
|
if [ "$PATCHSYSTEM" = "none" ]; then
|
||||||
echo "$PATCHNAME" >> debian/patches/series
|
# If we're supplied a file and there is no patchsys we apply it directly
|
||||||
elif [ "$PATCHSYSTEM" = "dpatch" ]; then
|
# and store it in debian/applied patches
|
||||||
echo "$PATCHNAME" >> debian/patches/00list
|
[ -d $PREFIX ] || mkdir $PREFIX
|
||||||
|
|
||||||
# Add the dpatch header to files that don't already have it
|
patch -p0 < "$PATCHORIG"
|
||||||
if ! grep -q "@DPATCH@" "debian/patches/$PATCHNAME"; then
|
cp "$PATCHORIG" "$PREFIX/$PATCHNAME"
|
||||||
sed -i '1i#! /bin/sh /usr/share/dpatch/dpatch-run\n@DPATCH@' debian/patches/$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
|
fi
|
||||||
|
|
||||||
|
echo "Copying and applying new patch. You can now edit the patch or exit the subshell to save."
|
||||||
fi
|
fi
|
||||||
|
|
||||||
echo "Copying and applying new patch. You can now edit the patch or exit the subshell to save."
|
|
||||||
fi
|
fi
|
||||||
}
|
}
|
||||||
|
|
||||||
# TODO:
|
# TODO:
|
||||||
# - edit-patch --remove implementieren
|
# - edit-patch --remove implementieren
|
||||||
# - dbs patch system
|
# - dbs patch system
|
||||||
# - handle no patch system
|
|
||||||
|
|
||||||
main() {
|
main() {
|
||||||
# parse args
|
# parse args
|
||||||
@ -232,7 +257,7 @@ main() {
|
|||||||
detect_patch_location
|
detect_patch_location
|
||||||
normalize_patch_path
|
normalize_patch_path
|
||||||
normalize_patch_extension
|
normalize_patch_extension
|
||||||
prepare_new_patch
|
handle_file_patch
|
||||||
edit_patch_$PATCHSYSTEM $PATCHNAME
|
edit_patch_$PATCHSYSTEM $PATCHNAME
|
||||||
add_patch_tagging $PATCHNAME
|
add_patch_tagging $PATCHNAME
|
||||||
add_changelog $PATCHNAME
|
add_changelog $PATCHNAME
|
||||||
|
Loading…
x
Reference in New Issue
Block a user