1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100
|
#!/bin/sh -e
# create or edit a cdbs simple-patchsys.mk patch
#
# (C) 2005 Martin Pitt <mpitt@debian.org>
#
# This script is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License version 2 as
# published by the Free Software Foundation.
# Stolen from quilt
patch_header()
{
awk '
$1 == "***" || $1 == "---" \
{ exit }
/^Index:[ \t]|^diff[ \t]|^==*$|^RCS file: |^retrieving revision [0-9]+(\.[0-9]+)*$/ \
{ eat = eat $0 "\n"
next }
{ print eat $0
eat = "" }
'
}
dh_testdir
if [ -z "$1" ] || [ "$1" = "--help" ]; then
echo "Usage: $0 <patch name>"
exit 0
fi
SRCDIR=$(pwd)
PATCHNAME=${1%.patch}.patch
TMP=$(mktemp -t -d cdbs-new-patch.XXXXXX)
TMP2=$(mktemp -t cdbs-old-patch-header.XXXXXX)
trap "rm -rf $TMP $TMP2" 0 1 2 3 9 11 13 15
ORIGDIR=$(basename $(pwd))
NEWDIR=$ORIGDIR.new
mkdir -p debian/patches
# create clean source package in temporary dir
cp -a . $TMP/$ORIGDIR
cd $TMP/$ORIGDIR
debclean
# create an empty patch if necessary so that the following loop stops at the
# lexicographic patch position
[ -e "debian/patches/$PATCHNAME" ] || touch "debian/patches/$PATCHNAME"
# remove all patches later than the one to edit
for p in $(find debian/patches -type f -name "*.patch" | LC_COLLATE=C sort -r); do
rm -f "$p"
pname=$(basename "$p")
[ "$pname" != "$PATCHNAME" ] || break
done
debian/rules apply-patches
# create new source dir
cp -a . $TMP/$NEWDIR
cd $TMP/$NEWDIR
# if we edit a patch, apply the already existing one to the new directory
if [ -e "$SRCDIR/debian/patches/$PATCHNAME" ]; then
echo -n "Applying already existing patch to edit directory at level"
for level in 0 1 2; do
echo -n " $level"
if patch --dry-run -E -p$level < "$SRCDIR/debian/patches/$PATCHNAME" > /dev/null 2>&1; then
if patch --no-backup-if-mismatch -V never -p$level < "$SRCDIR/debian/patches/$PATCHNAME" > /dev/null 2>&1; then
echo " success"
success=1
break;
fi
fi
done
[ "$success" ] || {
echo " failure"
exit 1
}
fi
echo "
You are now in a subshell in a cleaned copy of your source package.
Please make the changes necessary for the patch $PATCHNAME
in this directory and exit with status 0 to create/update the patch.
Exiting with a non-zero value will cancel the patch modification."
SH=$(getent passwd $USER | cut -f 7 -d:)
[ "$SH" ] || SH=/bin/sh
if $SH; then
if [ -f $SRCDIR/debian/patches/$PATCHNAME ]; then
cat $SRCDIR/debian/patches/$PATCHNAME | patch_header > $TMP2
cat $TMP2 > $SRCDIR/debian/patches/$PATCHNAME
fi
cd $TMP
diff -Nur $ORIGDIR $NEWDIR >> $SRCDIR/debian/patches/$PATCHNAME
fi
|